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
0answers
21 views

spacemacs: show yasnippets at top of completion popup list

yasnippet can be integrated into auto-compltion in spacemacs. I want to show snippets at the top of the auto-completions list. Default is at bottom. foo_______________ |foo -> foo snippet| |foo ...
0
votes
0answers
11 views

Find files interactively with a yassnippet with helm-find-files?

I've seen the answers to this question on inserting filenames interactively within a yasnippet. They are excellent and work great. I was wondering, however, if it's possible to expand them to use the ...
0
votes
1answer
26 views

yasnippet color

I use yasnippet in orgmode to expand codeblocks of Python and start typing code. My snippet is defined as: # -*- mode: snippet -*- # name: emacs-jupyter code block for python (silent) # key: <spp #...
1
vote
1answer
50 views

Get autocomplete to display candidates only when tab is pressed

I've set up auto-complete on emacs to display completion candidates, and it seems to be working well so far. I'm finding the constant display (and changes in display) distracting when I type, and I ...
0
votes
1answer
31 views

how to append arbitrary string to yasnippet placeholder field

I would like to know how to append a default string to a placeholder. For example, I currently have: # -*- mode: snippet -*- # name: render template # key: rt # group: Flask # contributor: Jon ...
4
votes
1answer
69 views

sh-script-mode: get [[ … ]] pair expansion to automatically include whitespace?

Say you're coding a shell script and you want to write something like: if [[ "$out" =~ 'none' ]]; then return $err fi If you're just typing it out and have any of the various electric/pair ...
2
votes
1answer
96 views

Yasnippets for active web-mode engine

Say I have a snippets folder: snippets/web-mode/ ├── django │   ├── else │   ├── for │   └── if └── erb ├── else ├── for └── if Both engines have different syntax ({% %} and {{ }} vs <...
2
votes
1answer
52 views

How to tell YASnippet to ignore placeholder?

I have a shell script which uses an array to check dependencies. I'd like to make this into a YASnippet, but YAS recognizes the array value statement ${dependencies[@]} as a placeholder. How can I ...
0
votes
2answers
51 views

Problem with org-insert-link and yas-expand

I have a problem when I want to yas-expand a link in Org-mode and it has a dash (-) in the text (url and description). Then the snippet break and exits. If I do the same in fundamental-mode it works. ...
0
votes
0answers
22 views

yasnippet in f90 mode

I'm using autocomplete and yasnippet, therefore I added (define-key yas-minor-mode-map (kbd "<tab>") nil) (define-key yas-minor-mode-map (kbd "TAB") nil) (define-key yas-minor-mode-map (kbd "&...
1
vote
2answers
76 views

Run function after specific snippet

I have a workflow that goes like, 1) use a snippet then 2) call a function. What a glorious opportunity to automate! But how? The snippet ipdb inserts import ipdb; ipdb.set_trace(). It has ...
1
vote
1answer
37 views

Setting An Org Heading Property From Yasnippet

I have a yasnippet snippet for adding the boilerplate to my "daily review" org document. Here's what it looks like: # key: ndr # name: newdailyreview # -- * Accomplishments :PROPERTIES: :CUSTOM_ID:...
0
votes
0answers
82 views

Whats the recommended way to install yasnippet for an emacs prelude user?

Is doing mkdir ~/.emacs.d/personal/snippets/ the correct way and putting snippets there? I've been reading https://github.com/bbatsov/prelude/issues/98 What I did: ;; personal.el (prelude-require-...
1
vote
1answer
80 views

How to make yasnippet fall back to self-insertion when it shouldn't expand

I've decided to try out yasnippet recently, and while it seems to work for me, I have an issue with how it handles comments. I've set my trigger key to SPC, which causes unnecessary snippet expansion ...
2
votes
1answer
91 views

Expand yasnippet only when it's at beginning of the line

How to write snippet condition to expand it only when it's positioned at the beginning of the line?
1
vote
1answer
110 views

Yasnippet: Prompting the user for information to fill in a latex snippet

I write a snippet to insert a theorem environment into a latex document, based upon some snippets created by another project: https://github.com/madsdk/yasnippets-latex . In the snippet below, the ...
0
votes
1answer
327 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
40 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
73 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
163 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
140 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
1answer
62 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
125 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
145 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, })...
2
votes
0answers
111 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, ...
1
vote
0answers
42 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
142 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 ...
2
votes
0answers
603 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
87 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
101 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 ...
2
votes
1answer
267 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?
5
votes
1answer
130 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
59 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 ...
1
vote
1answer
68 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
395 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 ...
2
votes
2answers
114 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
81 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
132 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
119 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 (.....
5
votes
1answer
166 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 ...
5
votes
1answer
258 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
128 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 ...
2
votes
1answer
190 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 ...
3
votes
0answers
58 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
197 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
186 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 ...
1
vote
1answer
170 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 ...
1
vote
1answer
136 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
108 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
266 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 ...