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.
194
questions
23
votes
2answers
8k views
How to make yasnippet and company work nicer?
In my emacs,
let's say, I use a "elisp" yasnippet to extend a lisp block in
org-mode. But before I extend it, company is triggered first, which gives
me a menu like "1. elisp1, 2. elisp2" without an ...
15
votes
1answer
7k views
Get Company to show suggestions for Yasnippet names
I use the packages Company mode and Yasnippet. When I'm typing in a buffer, I get autocompletion suggestions from Company.
For Yasnippet, I have a directory which contains the snippets. In that ...
15
votes
2answers
2k views
One yasnippet snippet for multiple modes
I have the following snippet:
# -*- mode: snippet -*-
# contributor: Song Qiang <tsiangsung@gmail.com>
# key: m
# group: Math
# name: Inline math \( ... \)
# --
\\($1\\)$0
and I want it to be ...
12
votes
3answers
2k 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 ...
11
votes
3answers
7k 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 ...
10
votes
2answers
3k views
Is there a yasnippet producing a prepopulated doxygen comment?
For the following C++ function:
bool importantStuff(double a, double b);
It should output the following snippet, perhaps without the tags:
/**
* <Insert description of importantStuff>
*
* @...
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: ...
8
votes
1answer
2k 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 ...
8
votes
1answer
1k views
yasnippet: how to expand a snippet from a string and have the fields recognized?
Q: how do I get yasnippet to expand a text string correctly (recognizing snippet fields) from inside elisp code?
A very simple snippet is a just a string of characters with some control characters ...
8
votes
1answer
638 views
How can I prevent yasnippet from breaking when I update my packages?
After packages have been updated, the location of the loaded elisp files will change to be in the folder of the new version of the package.
Yasnippet attempts to lazily load snippets for the file it ...
7
votes
1answer
4k views
Yasnippet not working with auto-complete-mode
I am just starting to experiment with Yasnippet, and it worked very well until I tried to combine it with auto-complete-mode. The problem is that Auto-Complete is taking over completely. For example, ...
6
votes
2answers
1k 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-...
6
votes
1answer
777 views
Auto-Complete stops working with C files
I am using Emacs24, and my auto-complete plugin was working when I opened my .emacs file. However, it doesn't work when I open some file like :
whatever.c
To add to this, the auto-complete-c-...
6
votes
1answer
468 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 ...
6
votes
1answer
465 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-...
5
votes
1answer
677 views
Disable default Yasnippet snippets?
How do I disable all pre-existing yasnippet snippets? I only want to use ones that I define myself.
5
votes
2answers
590 views
read clipboard into yasnippet
I am creating a yasnippet to create org-mode link with content like:
[[$1:value-read-from-clipboard][$0]]
I wish the $1 read value from clipboard (the use-case is: I copy the URL from chrome browser ...
5
votes
2answers
482 views
What templates are available for generating an elisp library?
At some point I remember encountering a command that generated a skeleton of a properly formatted emacs-lisp library as below:
;;; library.el --- summary
;; Copyright ...
;; Author:
;; Keywords:
;;...
5
votes
1answer
124 views
Need help for a snippet - a for in C
I was switching to vim for the C-support mode, and then I discover yasnippet for emacs, it is awesome I love it !
So now I'm adding basic snippets to insert code and I am currently having a bit of ...
5
votes
1answer
1k views
(setq yas-snippet-dirs …) not working
I am unable to set up yasnippet the way I want to set it up.
I only want to use yasnippet for a particular set of modes, so I don't want to use yas-global-mode.
I only want to use my own snippets, ...
5
votes
1answer
315 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
245 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 ...
5
votes
2answers
473 views
YASnippet: How to resume (or reactivate) snippets after exiting them
After exiting yasnippet snippets that contain one or more tab stops, I often find myself wanting to go back and modify content that I entered at the tab stops. Of course, I can do this using standard ...
4
votes
1answer
853 views
abbrev vs yasnippet for this use case
I have not done much with abbrev-mode or yasnippet, but I recently started using AucTex mode with great success, and I think some common TeX markup I'm inputting could benefit from expansion.
Example:...
4
votes
3answers
3k views
Convert the first character to uppercase/capital letter using yasnippet
Q: I have the following Yasnippet, which looks like this:
MYNAME - $1 (`(insert-mode-description)`).
$2
When I insert the snippet, the cursor starts on $1. Then I begin with typing. I would like ...
4
votes
1answer
1k views
How bind keys to a specific snippet in yasnippet folder?
Let's say I have a yasnippet snippet called foobar and I have configured it to work it with company-mode (which is not relevant here). Now each time I needed to type foobar I would select it from ...
4
votes
1answer
700 views
yasnippet configuration does not persist across emacs runs
yasnippet does not complete snippets that I add to yas/root-directory (typing the key and hitting tab does not complete).
If I remove .yas-compiled-snippets.el from an affected directory, then run ...
4
votes
1answer
1k views
Is there something I should do about “package assoc is obsolete” message?
Just noticed this message after emacs startup "Package assoc is obsolete!", but everything seems to work nice. The requirement seems to be called by yasnippet only.
I just want to know if I should ...
4
votes
1answer
394 views
How can I disable an individual snippet when in shell-script-mode?
I'm a fairly extensive user of YAsnippet but there is an annoying niggle when I'm working on shell scripts. The default prog-mode snippets includes "fi" which expands to FIXME. This would be fie but ...
4
votes
3answers
123 views
YASnippet: Avoid electric pairs at expansion time
I am used to bind my YASnippet trigger keys to sequences that start with < (e.g. when I type <hn in org-mode, it expands to a custom header for my notes).
The problem is that in some modes, the ...
4
votes
1answer
104 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 ...
4
votes
1answer
359 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 ...
4
votes
0answers
142 views
Conditionally remove parts of a snippet when the corresponding input field is left empty?
When writing LaTeX code I use a snippet that expands begin to the following
\begin{$1}
\label{$1:$2}
$0
\end{$1}
This suits most of my purposes well, since I use labels rather systematically....
4
votes
0answers
208 views
how to expand a yasnippet snippet after punctuation?
Q: how can I get yasnippet snippets to expand when placed immediately after punctuation?
Consider the snippet SNIP. It will expand if preceded by whitespace (eg, here's a SNIP expands), but not when ...
3
votes
4answers
1k 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 ...
3
votes
2answers
280 views
Org-mode: Disable `t` + `TAB` => `# TODO: ` autocomplete feature
There is a built-in org-mode shortcut where a t character followed by TAB key results in an auto-complete function that produces the # TODO: string literal. How can I disable this? Even better, how ...
3
votes
1answer
419 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 ...
3
votes
1answer
724 views
How configure keybinding for Yasnippet only?
When you insert a snippet from Yasnippet, you have this, for example
# --------------------------------------------------------------
# $1 (`(insert-date)`)
# ----------------------------------------...
3
votes
4answers
987 views
Autocomplete environments like in TeXStudio
TeXStudio autocompletes environments. How can I get AUCTeX to do the same?
I can begin typing an environment name (say myenvironment) and, after entering a part of it (my, myenv, etc.), I hit ...
3
votes
1answer
241 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 <...
3
votes
1answer
368 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 ...
3
votes
1answer
460 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 ...
3
votes
2answers
660 views
Org-mode: any keyboard shortcut for Latex code?
On p.33 of the Org-guide Carsten Dominek writes
you can use #+LATEX: and #+BEGIN_LATEX ... #+END_LATEX construct to add verbatim LATEX code
Is there a keyboard combination or default snippet that ...
3
votes
1answer
339 views
Yasnippet prompt when using commands interactively?
How can I use yasnippet to invoke LaTeX commands interactively?
If I use auctex to insert \usepackage it starts a minibuffer which lets me select the desired package (including tab completion). ...
3
votes
1answer
198 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?
3
votes
2answers
2k 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:
...
3
votes
1answer
508 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 ...
3
votes
1answer
133 views
Fill-column conflicts with YASnippet [Examples in gif]
I use fill-column in my dot-Emacs. And I have the following setting:
(turn-on-auto-fill)
(set-fill-column 60)
The result looks like this:
Every time when the input exceeds columnnumber 60, it will ...
3
votes
1answer
568 views
Yasnippet doesn't work when tab-always-indent set to true
It annoys, when autocompletion & indentation both gets called on TAB press. So, i configured to use TAB key only for indentation as,
(setq tab-always-indent t)
Now, when i enable yas-minor-mode ...
3
votes
1answer
842 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 ...