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
1
vote
1answer
170 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
218 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
61 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
208 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
219 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
207 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
171 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
115 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
291 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
188 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} \`\`\...
1
vote
0answers
58 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
53 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. ...
2
votes
1answer
285 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
64 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
162 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
326 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
47 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 ...
2
votes
1answer
84 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
42 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
65 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
282 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 ...
1
vote
0answers
95 views

How to save a yasnippet placeholder's final value in an Elisp variable?

In its more recent versions, shell-script mode tailors its behavior in response to the sh-shell variable's value, which indicates the shell variant (zsh, bash, etc.) that the script is for. I've ...
0
votes
1answer
1k views

How to assign TAB to indentation and to yasnippet expand key

i'm trying to have the key TAB to: Indent my code (like in any other text editor) Trigger Yasnippet I have theses lines in my config: (global-set-key (kbd "TAB") 'yas-expand) (global-set-key (kbd "...
3
votes
1answer
584 views

yasnippets and org-mode: yas-next-field-or-maybe-expand does not expand

In org mode, the TAB key maps to yas-next-field-or-maybe-expand. But it is not working. But if I run yas-expand (by hand) it works as expected. TAB does expand in other modes. Any ideas what might ...
1
vote
1answer
265 views

Some yasnippets don't load anymore

I recently upgraded to yasnippet 0.10.0, on emacs 24.5.1/OS X and noticed that some of my yasnippets are not loaded anymore, but this only affects some. I can see that these are still in the compiled ...
1
vote
1answer
84 views

Yasnippet increment function name

I have a small snippet like this: # -*- mode: snippet -*- # name: options # key: vop # -- var options = { target: '#$1', beforeSubmit: showRequest, success: showResponse }$0 ...
2
votes
3answers
985 views

yasnippets - finding and modifying some snippets

I'm struggling a bit with yasnippet. My question must be very basic but I would like to modify some snippets but I can't locate them. I have for example a snippet style for html-mode but it does not ...
0
votes
1answer
66 views

Emacs init file with yasnippets and magit submodule update error

I have cloned yasnippets repo repo in ~/.emacs.d/yasnippet-snippets. I would like to synchronize it each time I start Emacs (btw, it would be nice to do it only if there is a connection available), my ...
1
vote
2answers
149 views

Yasnippets won't expand in git-commit-mode?

I have written a snippet for git-commit-mode. However when I'm writing a commit message (from Magit), the snippet won't trigger. Does anyone know how to fix this? I have yasnippet version 20160924....
0
votes
1answer
149 views

snippet not recognized — yasnippet

my question is pretty basic but I don't know how to create yasnippets properly. I have created some snippets for Java or html with yas-new-snippets, installed them under emacs.d/snippets/org-mode, but ...
2
votes
1answer
287 views

What's the best way to remove some of the builtin yasnippet and make emacs upgradable?

I have custom yasnippets and I noticed they are located in the ~/.emacs.d/snippets folder. The builtin snippets are located at ~/.emacs.d/elpa/yasnippet-20161008.804. There are some builtin snippets ...
1
vote
1answer
101 views

Getting the value of previos field with yasnippet

Sometimes it would be handy to get the previously entered field values, and process them. Example: the second field (function name) of this snippet is always the camelCase version of the first field ...
1
vote
1answer
787 views

yasnippet : How to expand snippet inside snippet?

In yasnippet's manual expansion of snippet inside a snippet is mentioned but I wasn't able to achieve this. Can someone tell me what I'm doing wrong ? I have two snippets : # -*- mode: snippet -*- # ...
10
votes
1answer
1k views

Insert code chunk in R Markdown with yasnippet and polymode

I am trying to write a yasnippet to insert code chunks into an R Markdown file. I use polymode to have multiple major modes (markdown, ESS[S]) in a single file. This is my snippet: # -*- mode: ...
7
votes
1answer
1k views

Insert current date with yasnippet

Since several years I've been using this snippet to insert a date into buffer: # -*- coding: utf-8 -*- # name: date # key: date # -- `(insert (format-time-string "%Y-%m-%d"))`$0 However nowadays I ...
10
votes
3answers
988 views

Is it possible to make yasnippets to expand snippets inside an org-mode babel section in the appropriate mode?

For example I have an org mode that has the following #+BEGIN_SRC emacs-lisp #+END_SRC Is it possible to configure yasnippets in such a way so all emacs-lisp-mode snippets can be expanded inside ...
1
vote
1answer
257 views

Space eaten in yasnippet template

NOTE: I use the symbol ␣ to represent the character SPACE (U+0020) for visibility. I have a template like this: ${1:$$(yas-choose-value (with-current-buffer "foo-buf" (foo-get-name-list)))}␣[label="$...
0
votes
1answer
301 views

Problem with company-anaconda and company-yasnippet

I have tried several setups and I just can't seem to be able to get anaconda and yasnippet working at the same time (dabbrev would be nice as well). First I tried reorganizing the order, it was a ...
6
votes
1answer
348 views

How to put whitespace into Yasnippet Templates?

When I create a new yasnippet template using the 'yas-new-snippet' command, I'm unable to get the leading whitespace to show when the template is expanded in a new document or even tested using 'yas-...
1
vote
1answer
77 views

How can I get “this->” by inputting “this.”?

I want to input this. and get this-> in c++-mode. I tried abbrev-mode and yasnippet, but failed. In abbrev-mode, I defined an abbrev this to get this using . as a trigger key, but soon as I typed ...
2
votes
1answer
105 views

add an indicator or annotation on filed which current input is expandable in yasnippet

I have a snippet called struct. And I write text complex_struct in a snippet field. yasnippet will expand complex_struct with the snippet struct. I have to move backward one character to avoid this ...
2
votes
1answer
191 views

How to cycle back through parameters on a yasnippet?

When I got a snippet with a few parameters: <img src="http://lorempixel.com/${1:width}/${2:height}/${3:$$(yas-choose-value '("abstract" "city" "animals" "food" "people" "transport" "business" "...
2
votes
1answer
272 views

Browse and search text snippets in emacs and insert them as LaTeX input

Suppose I have a lot of small text snippets (including some LaTeX-code). Now I want to create a LaTeX document with emacs which includes some of the text snippets. I know yasnippet which can expand ...
6
votes
2answers
842 views

Warning (yasnippet): modified buffer in a backquote expression

When I use yasnippet, I keep getting this error: Warning (yasnippet): `foo-snippet' modified buffer in a backquote expression. To hide this warning, add (yasnippet backquote-change) to `warning-...
2
votes
1answer
553 views

yasnippet truncates clipboard contents

I have a yasnippet that is intended to create a footnote in org-mode format and automatically insert the contents of the clipboard. # -*- mode: snippet -*- # name: footnote # key: fn # -- [fn:: `(...
0
votes
1answer
234 views

Hippie doesn't use yasnippet and fallback to emmet with emacs-lisp-mode

I use hippie-expand with emmet and yasnippet. (use-package emmet-mode :init (add-hook 'css-mode-hook 'emmet-mode) (add-hook 'sgml-mode-hook 'emmet-mode) :config (unbind-key "<C-return>" ...
8
votes
3answers
6k views

Expanding Snippets in evil-insert-mode

I just moved to spacemacs from vim and am a complete newbie with emacs. I cannot figure out how to expand yasnippets while in evil-insert-mode. I know yasnippet is available because I can choose from ...
1
vote
1answer
28 views

Yasnippet stops compile error highlighting

I have been compiling my C++ project using M-x compile which I like because it provides highlighted links to my errors: However after adding: (add-to-list 'load-path "~/.emacs.d/plugins/...
2
votes
2answers
244 views

Find files interactively with a snippet

It should be nice to write yasnippets, which ask for filepath interactively using helm, predefining starting directory should be fine too.
2
votes
2answers
1k views

Python docstrings only allow two indent levels

I am trying to write a docstring that follows Google's style guide such that it looks something like: def testFunction(a, b): """ Args: a (str): b (str): Returns: ...