Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

Questions tagged [yasnippet]

YASnippet is a template system for Emacs. It allows you to type an abbreviation and automatically expand it into function templates. Bundled language templates includes: C, C++, C#, Perl, Python, Ruby, SQL, LaTeX, HTML, CSS and more.

Filter by
Sorted by
Tagged with
0 votes
0 answers
15 views

How to expand yas-snippets in eshell (under Doom)

(This may have nothing to do with Doom-emacs, but because I use it, I should mention it) The famous "for-loop" expansion (https://xenodium.com/yasnippet-in-emacs-eshell/) does not work for ...
jeffkowalski's user avatar
0 votes
0 answers
8 views

Error yas--advance-end-maybe-previous-fields with autoactivating yasnippets in latex environments in org mode

I get the error yas--advance-end-maybe-previous-fields: Assertion failed: (memq field (yas--snippet-fields snippet)) in org mode when I use snippets that: do not contain $1 in the snippet use auto ...
userrandrand's user avatar
1 vote
0 answers
23 views

Arbitrary number of fields in yasnippet

Is it possible in a yasnippet snippet to create an arbitrary number of fields following a template, stopping only once the user indicates they are done entering fields? Example One use case is to ...
holocronweaver's user avatar
1 vote
1 answer
41 views

emacs as CLI to transform strings

Is it possible to use emacs as just an CLI tool to transform some strings? What I want is to use yasnippet to generate file by template. I use emacs, but my team doesn't and it would be nice to have ...
Andrey's user avatar
  • 13
0 votes
0 answers
42 views

Inserting newline in snippet start with YASnippet

I have the snippet # -*- mode: snippet -*- # name: LaTeX display math block # key: dm # -- \[\begin{align*} $1 \end{align*}\] $0 which works fine except for the fact that the newline at the start is ...
daedsidog's user avatar
  • 157
0 votes
0 answers
33 views

Yas-snippets not showing dropdown suggestions for python(only)

As the title says Yas snippets don't show a suggestion dropbox when in python mode.I can still tab complete the snippets(just no suggestions). It works as expected in other modes(tried in latex,org ...
je2144's user avatar
  • 1
0 votes
0 answers
77 views

how to create variable-length fields yasnippet snippet

I'm trying to create a snippet that generate a python docstring. I have a function that parses the current python function for arguments. now I want to use this function in the snippet to generate the ...
ntriisii's user avatar
0 votes
0 answers
11 views

Accessing yassnippet from other editors (namely jupyter lab)

I spend most of my time working in emacs, but some of the time I use jupyter lab (I've played with an emacs extension to talk to jupyter from emacs but have been bitten by bugs - and I also do pairing)...
Att Righ's user avatar
  • 775
0 votes
1 answer
67 views

Can I find snippets using yasnippet for the mode of an org-babel block (e.g. python / bash)?

I like snippets. I use yassnippet a lot. I also use babel in org mode. I would quite like to be able to use my snippets in org babel blocks, but they don't work because I am in the wrong mode. Is ...
Att Righ's user avatar
  • 775
0 votes
1 answer
44 views

How to reset yasnippet default snippet file

for some reason the content of my default +new-snippet+ file has changed from # -*- mode: snippet -*- # name: # key: # -- to # -*- mode: snippet -*- # name: # key: # -- The ...
aQuarkyName's user avatar
0 votes
1 answer
80 views

Make Yasnippet insert characters before the key

I want to create a snippet, which does the following: When I write . foo it creates A.B while the cursor is in front of B. I only found ways to insert text after the key and to delete text before, but ...
Sinthoras's user avatar
0 votes
1 answer
60 views

Coding system issues broke my emacs

I was messing with trying to get emojis to display and I broke my emacs by messing with the coding system settings somehow. After my desktop file failed to load, I uninstalled unicode-fonts and ...
firstname gklsodascb's user avatar
0 votes
1 answer
129 views

Why does this yas-snippet (with yas-selected-text) not moving the cursor as intended?

I have following yas-snippet for inserting latex equation parenthesis in selected region. # -*- mode: snippet -*- # name: parenthesis_region_() # binding: M-r ( ) # -- \left( `yas-selected-text` \...
Garid's user avatar
  • 641
0 votes
2 answers
53 views

How to insert kbd macros in Yas-snippets?

I'm trying to learn how to: Define a kbd-macro, (here I'm using kbd-macros, because I'm bad at elisp currently). Letting that to be executed when yas-snippet to expand. (here I'm struggling with) My ...
Garid's user avatar
  • 641
0 votes
1 answer
30 views

Cannot expand yasnippets in .el files

I want to use yasnippet in three modes. I have this in my init.el: ;;; Yasnippet (use-package yasnippet :commands yas-minor-mode :config (yas-reload-all) :hook ((org-mode text-mode emacs-lisp-...
Edman's user avatar
  • 1,219
0 votes
0 answers
66 views

Is there any way I can have snippets (like yasnippet) but for a particular file?

Sometimes files have quite specific snippets that might be useful? Is there any easy way to have per file snippets? Approach I've got some code that get hold of the snippet text for a desired snippet. ...
Att Righ's user avatar
  • 775
2 votes
1 answer
351 views

How to expand yas-snippet, when trigger-key is part of a word?

I have following yas-snippet (for python-mode): # -*- mode: snippet -*- # name: .s-np_array_shape # key: .s # -- .shape And now, .s Tab gives .shape as expected. What I want: This doesn't expand if ...
Garid's user avatar
  • 641
2 votes
1 answer
58 views

Any yasnippet to evaluate infix math expression?

I would like to have a yasnippet to evaluate infix math expression on the current line. E.g., If the line is 1 + 2 = and I trigger yasnippet at the end of line, it will append the result at the end: ...
AhLeung's user avatar
  • 1,083
0 votes
1 answer
133 views

Company doesn't load with Yasnippet

Facing strange problem with auto-completion company-mode. I use the packages Company mode and Yasnippet. When I'm typing in a buffer, I get autocompletion suggestions from Company with Yasnipper. But ...
Likhon BaRoy's user avatar
0 votes
0 answers
37 views

How do I create a project tree from yasnippet

I have built a project prototype as a module in a directory tree in the following example: module main.ext module_feature item.ext another_item.ext I would like to insert the module ...
alexander's user avatar
  • 133
0 votes
1 answer
53 views

How can I control the order of entries in the YASnippet menu?

I use YASnippets for everything and often use them through YASnippet menu. For any given major-mode, I use the .yas-parents file and put the directory/names in the order that I want them. But they ...
Mohsen Banan's user avatar
0 votes
2 answers
370 views

Is there a default folder for yas-snippets?

Does anyone know where yas-lookup-snippet gets its snippets from? I recently did a few changes with my snippets and now face that every time I want to open a new file I get the message: yas-lookup-...
Qohelet's user avatar
  • 185
0 votes
1 answer
107 views

Call an interactive elisp-function inside an YaSnippet

When trying to evaluate an interactive elisp-function which needs an argument in a yasnippet, it gives the error wrong number of arguments. I assume, the reason is, that the function is interactive ...
Sinthoras's user avatar
0 votes
1 answer
61 views

Help with yasnippets installation

Recently, I asked about inserting a snippet with auto-insert-alist. That works but now I thought about using Snippets for blockquote, for inserting images, etc. I’ve been trying to install Yasnippets ...
zeynel's user avatar
  • 371
2 votes
1 answer
62 views

How do I move the cursor back after completing yas-choose-value?

I have a snippet set like so: import React from 'react' const ${1:$$(file-name-base)} = ( ${2:$$(yas-choose-value '("\{ \}" "props"))} ) => { return ( $0 ) } export ...
mustaqim's user avatar
1 vote
1 answer
163 views

How to use a Template for creating YaSnippet snippets

I want to have a way, to efficiently create new YaSnippet-snippets. YaSnippet has the functionality, that via pressing C-c C-n one can create a new snippet. However, the empty new snippet is very ...
Sinthoras's user avatar
0 votes
2 answers
114 views

Does enabling by default a custom input method have any side effect on the default method?

I added these to my init.el: (use-package org :ensure nil :hook (org-mode . (lambda () (org-indent-mode) (variable-pitch-mode -1) (...
Zoli's user avatar
  • 441
0 votes
0 answers
162 views

When using company and lsp, why does the placeholder text sometimes not get replaced?

In a buffer in c-mode with the following content (with point after retu), pressing enter completes to return expression;. int main(int argc, char** argv) { retu } Point is now at the beginning of ...
ruds's user avatar
  • 143
0 votes
1 answer
80 views

Why does yasnippet insert a newline before the cursor?

This is my snippet, in org-mode: # key: quote # name: quote block # -- #+begin_quote `%`$0 #+end_quote Result: #+begin_quote | <- cursor #+end_quote Desired: #+begin_quote | <- cursor #+...
Josh Friedlander's user avatar
1 vote
0 answers
116 views

Insert single date stamp with Yasnippet and date prompt or org-read-date

For kontext: The emacs package "Yasnippet" let's you replace a keyword (like "/newagenda") with a predefined text. It lets you also modify some variable fields quickly after the ...
breathe_in_breathe_out's user avatar
0 votes
1 answer
50 views

History of yasnippet fields

Is it possible to have a history for the value of a yasnippet field? When I expand a second time a snippet like \begin{${1:environment}} I would like to get as suggestion the value I've used for $1 in ...
jo-so's user avatar
  • 51
2 votes
1 answer
96 views

Binding several keys to one yasnippet

Suppose we have a snippet for sql mode: # -*- mode: snippet -*- # name: select * # key: sel # -- SELECT ${1:*} FROM $2; Sometimes I forget to switch the keyboard layout and type Russian "ыуд&...
user4035's user avatar
  • 1,069
0 votes
1 answer
102 views

How can I load some snippets depending on the extension of current file?

When I work on web files I usually use web-mode for javascript, php and css files, the problem I have is that yasnippet uses the current mode to find what snippets to load for that buffer ( as stated ...
Fabman's user avatar
  • 578
0 votes
0 answers
151 views

yasnippet: execute function before inserting snippet

I'm using yasnippet to insert text into RMarkdown (.Rmd) files. For example, I can insert a code block which will produce a web map with something like this: Snippet: # -*- mode: snippet -*- # name: ...
haff's user avatar
  • 218
2 votes
1 answer
341 views

Calling elisp functions from inside yasnippet

I created a yasnippet that calls a function: # -*- mode: snippet -*- # name: print # key: pr # -- `(cperl-print)` The function code: (defun cperl-print () (interactive) (let* ((current (point)) ...
user4035's user avatar
  • 1,069
0 votes
1 answer
183 views

How to use yasnippets from js- and css- modes in html-mode?

I have latest YASnippet package installed on GNU Emacs 27.2 via MELPA. Snippets work, for example in *.js files, let expands to snippet after hitting TAB. However, when I edit HTML file (in html-mode),...
Vlad Havriuk's user avatar
2 votes
2 answers
1k views

How to enable yasnippets for all modes?

Company doesn't show snippets in some modes e.g. python or sh. Yet yas/describe-tables displays all snippets. In other modes e.g. org,emacs-lisp, snippets are shown as expected. Looking at company-...
jjk's user avatar
  • 744
0 votes
1 answer
143 views

Yasnippet-snippets indention not correct for Python functions

Yasnippet-snippets contains a snippet for Python mode to create a function with a docstring. The indention is not correct when I use it, I think it maybe has to do with some Spacemacs settings, but I ...
Cor's user avatar
  • 1
0 votes
0 answers
50 views

How to apply `yasnippets` only for keywords at the beginning of the line? [duplicate]

I am using Python but some pre-defineted snippets. I was wondering is it possible to apply them if the keyword is the first word. if and [TAB] converted into if cond:. I want this behaviour if the ...
alper's user avatar
  • 1,380
2 votes
2 answers
1k views

How to remove or overwrite a `yasnippets`?

I am using Python but some pre-defineted snippets are acting not as I wanted, hence I want to remove some, if possible. In most cases, I am using TAB for indent alignment, hence yasnippets apply ...
alper's user avatar
  • 1,380
1 vote
1 answer
321 views

How to turn on "helm-mode" for a specific function?

The context I've defined a big set of yasnippet snippets and sometimes I forget the shortcut for those snippets. I've found out recently that the function yas-insert-snippet can be used to insert a ...
rdrg109's user avatar
  • 418
1 vote
1 answer
189 views

Is it possible to add descriptions for the yas-choose-value choices?

I got a simple snippet for the opening a file in PHP: fopen('${1:./filename.txt}', '${2:$$(yas-choose-value '("r" "w" "a" "x" "r+" "w+" &...
Fabman's user avatar
  • 578
0 votes
0 answers
280 views

Conflict with TAB keybinding for Yasnippet and Orgmode heading

I tried to use Yasnippet to create a template for org-drill "flashcard" # -*- mode: snippet -*- # name: Orgdrill twosided card # key: drill2 # -- * ${1:Write title here} ...
user1683620's user avatar
0 votes
0 answers
167 views

How do I create a snippet that optiionally expands multiple lines using YASnippet(or some other tool)?

I know how to create basic snippets using YASnippet. For example, consider the following snippet: # -*- mode: snippet -*- # name: js-function # key: jsfunc # -- /** @function * @name ${1:fn-name} * @...
Ev3ryDay1sL3gDay's user avatar
0 votes
1 answer
90 views

yas-new-snippet always duplicates the selected input. What might be causing it?

I've experienced this issue for some time. It's not a blocker but it is a bit annoying. Steps to reproduce: Select a region that you want to extract into YASnippet snippet("foo bar"). Eval ...
Nikita Fedyashev's user avatar
3 votes
1 answer
403 views

Call Python from YaSnippet and insert result

I'm trying to build a comparable functionality as described here: https://castel.dev/post/lecture-notes-1/#sympy-and-mathematica Basically, he's using something comparable to yasnippet to send a ...
beyeran's user avatar
  • 231
1 vote
1 answer
662 views

Company-yasnippet doesn't see yasnippet template in lisp

Config: (use-package yasnippet :ensure t :hook (prog-mode . yas-minor-mode) ) (use-package yasnippet-snippets :ensure t :after yas) (use-package common-lisp-snippets :ensure t :after ...
C-Entropy's user avatar
  • 143
1 vote
1 answer
89 views

How to pass the current scopes function symbol as an argument to an elisp function

I am trying to create an org-capture template which works with yankpad and yasnippets to such that if I am working with some c code like this: example.c static int somefunc(int a) { if (a ==5) { ...
Reginald Marr's user avatar
1 vote
1 answer
731 views

Make :tangle don't add a newline at the end of the file

The context I'm storing all my custom defined yasnippet snippets in an Org file (see below) $ cat ~/.emacs.d/snippets/snippets.org #+PROPERTY: header-args:yasnippet :mkdirp yes #+begin_src yasnippet :...
doltes's user avatar
  • 587
1 vote
0 answers
37 views

Don't understand the key binding for `auto-yasnippet`

I am looking to use auto-yasnippet but I don't understand the key bindings they are suggesting such as H-w and H-y. I haven't seen any key binding that starts with H so I am not sure what that is. I ...
user29896's user avatar

1
2 3 4 5