The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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

How do I get code signature snippets with lsp-mode/lsp-ui/company-lsp?

I see on the front page of https://github.com/tigersoldier/company-lsp when you type the function name it autocompletes not just the rest of the name, but the signature as a snippet, enabling you to ...
0
votes
0answers
24 views

prevent yas from inserting a new-line after expansion

So I'm doing a recursive snippet with yas $>name: "${2:`(file-name-nondirectory (file-name-sans-extension (buffer-file-name)))`}"${3:, $>np}$0 but yas inserts a new-line at the end of every ...
2
votes
1answer
28 views

Yasnippets: How to add if statements that check for regex?

I would like to replicate some of the snippets shown in this blog post Some of the snippets shown in that post involved if statements that check for regexp in snippet fields as well as checking for ...
1
vote
1answer
38 views

yasnippet not working on org

I created such a snippet $ cat snippets/diary_template # -*- mode: snippet -*- # name: diary template # key: dt # condition: t # -- **** Personal_Notes **** Personal_Tasks **** Project_Notes **...
0
votes
0answers
29 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
15 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
30 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
53 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
33 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
76 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
101 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
54 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
62 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
23 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
86 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
38 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
103 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
87 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
99 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
133 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
371 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
44 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
77 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
185 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
159 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
64 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
131 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
149 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
117 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
43 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
161 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
666 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
97 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
107 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
305 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
148 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
64 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
74 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
419 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
129 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
88 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
150 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
131 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
181 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
276 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
143 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
200 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
59 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
202 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
201 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 ...