Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
1answer
45 views

Best pratice advices for abbrev vs. completion vs. snippets

I am not sure if this is really a proper question but I am interested in having some opinions about the most efficient usage of Emacs' abbreviations features (abbrev/dabbrev) in combination with auto-...
0
votes
1answer
27 views

yasnippet: jump at the beginning of inserted snippet

Is it possible to define that after inserting a snippet, the cursor will jump at the beginning of what has been inserted? It will make it even more fun.
1
vote
1answer
43 views

Can you setup a snippet with two choices, where the second choice depends on the first choice?

I am trying to setup a snippet to add a src-block header to an emacs org-mode src-block. I want to get a list of possible headers to choose from, which I can get in this snippet (the org-babel-headers ...
4
votes
1answer
72 views

Yasnippet: How to automatically advance to next field after `yas-choose-value`

Yasnippet has a function called yas-choose-value which is used like this: <div align="${2:$$(yas-choose-value '("right" "center" "left"))}"> $0 </div> How can I automatically exit the ...
2
votes
1answer
63 views

Yasnippet: How to create multiple snippet key bindings

I have a yasnippet with # binding: TAB f o o in the header. This is processed by the yasnippet library as 9 102 111 111. With respect to a keymap of a major-mode, both \C-i and (kbd "TAB") are ...
0
votes
0answers
54 views

Yasnippet template for org-mode, placeholder in headings?

I am trying to use yasnippet templates with placeholders in org-mode headings. This is easy enough and works well, but the additional challenge is that I'd like to put org-mode markup at the end of ...
0
votes
1answer
45 views

Make yasnippet context sensitive

In LaTeX I often use pythontex in a way that there is a block \begin{pycode}[sessionname] ... \end{pycode} where I make some calculations. Then in the following text I refer to variables defined there ...
0
votes
2answers
59 views

Can't get automated c++ docstrings to work

I stumbled this thread and at first, it seems glorious, but I simply cannot get it to work. So when I try it on any program e.g.: #include <iostream> bool helloWorld(int a,int b){ dox<...
0
votes
1answer
66 views

Capitalize word as you type in emacs/spacemacs (YAS snippet)

Trying the following yas snippet # -*- mode: snippet -*- #name : vuex-action #key : va # -- [${1:$$(capitalize-word yas-text)}]: ({ commit, dispatch, getters, }, { $2, }) => { commit($1, { $2, })...
3
votes
0answers
60 views

Aligning (ditaa) rectangles with variable string width in yasnippet

To quickly add simple diagrams to notes, I've created yasnippets for ditaa boxes. The text inside each box is a $x - and therefore has a length I do not know at snippet design time. As a consequence, ...
0
votes
0answers
28 views

Define dummy variables from parameter list

Let's say I am experimenting with a codebase, and there's a function that takes a bunch of parameters, say void foobar(char A, char B, int m, float k, int n) I want to use the function somewhere, so ...
1
vote
1answer
57 views

How to insert leading spaces/tabs in yasnippet? [duplicate]

yasnippet does not respect spaces or tabs when they occur at the start a line. In my snippet file I have example which executes as example Escaping with \ doesn't work. How do I get leading ...
0
votes
0answers
20 views

Trigger an elisp function when user tabs into a specific field

Is it possible to define a snippet (using yasnippet) such that when user tabs into a specific tab stop field, an elisp function is triggered ? I was trying to achieve this through embedded elisp ...
0
votes
0answers
32 views

yasnippet resolve duplicate snippets for a given mode

In a C++ source file with yasnippets, I have two overlapping definitions for the snippets incl (expands to #include "...") and incs (expands to #include <...>). The snippets are the same in both ...
0
votes
0answers
230 views

In Spacemacs, how can I enable snippets without having an autocomplete popup/completion?

I'm using the auto-completion layer in Spacemacs with the following configuration: (auto-completion :variables auto-completion-return-key-behavior nil auto-...
2
votes
0answers
48 views

How to get a global available yasnippet snippet?

How to create a yasnippet snippet which is available in all modes? Lets say I have a function which evaluates the sexpr before the cursor and replaces is with its value, Link to code. Also I caught me ...
0
votes
2answers
64 views

Quick/electric text expansion

I've seen in some Emacs videos, the author would type #+BEGIN_SRC in their buffer, and emacs auto inserts #+END_SRC. Is this a feature I can "turn on" in vanilla Emacs? If not, which package can I ...
1
vote
1answer
85 views

Yasnippets: loading two major modes (`org-mode` and `LaTeX`)

I'm trying to load the yasnippets for the LaTeX mode every time I open an org file. Is it possible? How can this be achieved?
3
votes
1answer
74 views

Yasnippet expand snippet automatically instead of prompting possible completions

I have two snippets: e[TAB] expands to $ $1 $ $0 ($1 and $0 are placeholders); emph expands to \emph{$0} ($0 is a placeholder, this is a default snippet I suppose) I'm writing a lot of equations ...
2
votes
1answer
34 views

Problem redoing with yasnippet

I have had a problem with undoing lately, which seems rather dangerous and has almost lost me work. At first I thought it was due to undo-tree, so I deactivated that. But it persists and now I ...
0
votes
0answers
17 views

Can I get yasnippet to match symbols, not words?

Say I have a snippet s -> (setq $0) or whatever. Then if I type (global-s and TAB, I end up with (global-(setq ) which is really annoying. Is it possible to get yasnippet to match the current ...
1
vote
1answer
40 views

Does yasnippet support alternative placeholders?

Consider sample below: SERVER-1 [connection] 192.168.0.1 success [connection] 192.168.0.2 failed [disconnect] 192.168.0.3 pending [connection] 192.168.0.4 success but [${1:connection}] ${2:192.168.0....
0
votes
1answer
163 views

Menu bar drop-downs empty

I am using Emacs 25.3.2 on Linux Ubuntu 16.04. The problem is that several of the menu bar items produce empty drop-downs. A grey box appears, but with nothing inside. It looks like this: I ...
1
vote
2answers
47 views

How to use yasnippet's tab expansion in minibuffer?

I use yasnippet to insert some symbols (e.g., ✔), and I would like to do that in minibuffer too. When I press TAB in minibuffer, it said " is undefined". How to define it to use yasnippet? Is it ...
0
votes
1answer
42 views

Autoindent yas-snippets which call up another function

I use the snippet function_docstring_numpy (shortcut: fdn) in python to define nicely documented functions. They look like this: def flip(batch): """Flip a batch of images Works for a single ...
2
votes
1answer
66 views

how to define a yasnippet in init file?

My init file (.emacs) is version-controlled, my packages are installed with use-package, so my Emacs config is self-contained. I don't want to add (and manage) specific snippet files into my ...
2
votes
1answer
74 views

How can I define a Yasnippet for #if AND if?

I would like to define one snippet for a cc-mode if statement and a different one for the preprocessors #if statement. I tried just defining those two: For if: # -*- mode: snippet -*- # name : if (.....
2
votes
0answers
65 views

How do you make an optional field and comma in a yasnippet?

I want to make a snippet for a function with optional arguments. For example something like: myfunc($1, $2, $3) But in this case, $2 may be optional. I know I can press Ctrl-D to skip it, but it ...
4
votes
1answer
140 views

Multiple occurrences of variable in yasnippet snippet

I would like to do create a snippet in which the ${1:} command is present in multiple locations, allowing me to editing in multiple locations at once. In particular I would like this snippet to work ...
1
vote
1answer
81 views

How to define yasnippet templates using elisp instead of the file system?

I would like to use YASnippet template system to expand abbreviations. (I don't want to use abbrev-mode which use space or symbols for expansion.) It is not convenient to create a new file for each ...
1
vote
1answer
115 views

`expand-env: ((yas-indent-line 'fixed))` ignored

I have the following in a snippet's header expand-env: ((yas-indent-line 'fixed)) ...but when I attempt to insert the snippet, I still get a lot of unwanted indentation. What else can I do to ...
2
votes
0answers
44 views

Preferring org-cycle to yas-expand when hitting tab

If both org-mode and yasnippet are active, tab will expand a snippet if possible and otherwise execute org-cycle. Is it possible to reverse this priority? org mode version: 9.0.9. yasnippet version: ...
1
vote
1answer
121 views

Context suggestion for yasnippet

I would like to create a yasnippet snippet as follow: pressing weather I would like that would be inserted the following text current weather = with the cursor after the = (this can be done with ...
0
votes
1answer
104 views

yassnippet snippet to insert current timestamp

I would like to create a yasnippet snippet which will insert automatically the current timestamp. I have found a code which actually prints the timestamp but I do not know how to integrate into a ...
0
votes
1answer
56 views

Put placeholder and default value in yassnippet

I would like to create a yassnippet with a placeholder, so something like value = $1(insert_value) with the meaning that I would like to see the text "insert value" but when I press TAB and then ...
0
votes
1answer
69 views

Org subtree from yasnippet

Can yasnippet be used to insert an org subtree of the same level as the last? For example, if one often writes ***** $1 #+BEGIN_SRC latex \paragraph{$1.} $0 #+END_SRC how might one avoid ...
2
votes
2answers
95 views

How to limit when yasnippet fires?

I found that yasnippet suggests using this code to limit it to only expand when the trigger text has just been typed: (setq yas-expand-only-for-last-commands 'self-insert-command) Unfortunately when ...
0
votes
1answer
155 views

I cannot type left open bracket into buffer

I have a very weird problem, I cannot type left open bracket character ([) into any buffer. Bracket itself is recognized when I: type anywhere outside emacs type in minibuffer use it as part of ...
0
votes
1answer
107 views

Yasnippet for markdown code block

Trying to write a yasnippet for a markdown code block I wrote the following: #name: Code Block #contributor: Rovanion Luckey <rovanion.luckey@gmail.com> # -- \`\`\`${1:language} ${2:code} \`\`\...
0
votes
0answers
50 views

Yasnippets gives an unclear error (with example snippet)

I have the following snippet for PHP-mode, called Public. #contributor : ReneFroger #name : snippet for public # -- # -------------------------------------------------- # Method f${2:name}. # -----...
1
vote
0answers
41 views

using re-search-forward in yas-snippet

I'm trying to develop a new yas-snippet for expanding a common c++ log function I use a lot. The first parameter to the LOG function can be guessed by searching for existing LOG calls in the buffer. ...
1
vote
1answer
153 views

Yasnippet including backslash

I would like to use Yasnippet to insert the template for a latex inline equation: \( \) The snippet is defined: # -*- Mode: snippet -*- # name: inline equation # key: ineq # -- \( \) But ...
1
vote
1answer
36 views

Mirrors produce spurious indentation under mma-mode

NB: This problem seems to be limited to mma-mode (for Mathematica). For example, suppose I define a snippet like this: # key: test # name: test # -- $1 $1 Then, I test it (with C-c C-t). After I ...
0
votes
0answers
110 views

yasnippet doesn't work on Windows

I installed Emacs 25.1.2 on Windows 10 machine, then installed yasnippet library from Elpa. Copied all my snippets from Linux machine. But for some reason none of them work. When I open a file I get ...
3
votes
1answer
174 views

Nested Snippets

Let's say that I have the following snippet in Emacs: # -*- mode: snippet -*- # name: frac # key: frac # -- \frac{${1:numerator}}{${2:denominator}}$0 My problem is that when I write a snippet inside ...
1
vote
0answers
38 views

Conflict between org and yas: \Cc &

In org mode, \Cc & goes back to the reference to a link; but this binding is suppressed by yasnippet. Do I have to redefine it, or can I prevent yasnippet from creating these bindings in the ...
3
votes
1answer
71 views

Why does (indent-region …) insert a 't' into my buffer?

I'm using this yasnippet: # -*- mode: snippet -*- # name : case : {...} # key: case # -- `(indent-region (- (point) 20) (+ (point) 20) nil)`case ${2:constexpr}: ${3:\{} $0 break; ${3:$(if (...
0
votes
0answers
24 views

yasnippet, “Wrong number of arguments” when in X11 window

Using yasnippet, whenever I use the yas-expand function to expand a snippet, the result depends on whether the emacs session is in an X window or not. If I am in an in-terminal session of emacs, then ...
1
vote
1answer
36 views

How to temporary disable yassnipet snippet in snippet

I'm new to yassnipet and it's been awesome but I hit a wall. I have the following snippet: $1 = errors.WithMessage($1, $2))$0 In most of the use cases on $1 I enter err which expands to another ...
2
votes
1answer
170 views

How to define a yasnippet whose content depends on the value of an Elisp variable?

I want to define a yasnippet for shell-script mode that would insert a chunk of text whose content depends on the setting of the sh-shell variable. Since the possible different text insertions are ...