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.
237 questions
1
vote
1
answer
251
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 ...
2
votes
2
answers
2k
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 -*-
# ...
11
votes
1
answer
2k
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: ...
13
votes
1
answer
3k
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 ...
13
votes
3
answers
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 ...
1
vote
1
answer
447
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
1
answer
422
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 ...
8
votes
1
answer
759
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
1
answer
96
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
1
answer
126
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 ...
3
votes
1
answer
396
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
1
answer
451
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 ...
9
votes
2
answers
2k
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-...
4
votes
1
answer
1k
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
1
answer
371
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>" ...
12
votes
3
answers
8k
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
1
answer
39
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
2
answers
506
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.
3
votes
2
answers
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:
...
2
votes
0
answers
199
views
Set a field in yasnippet to edit/modify rather than replace default contents
I'm curious if it's possible to define a yasnippet completion field with a default value specified to initially edit/modify the value rather than replace it. For this elementary example:
${1:...
2
votes
1
answer
331
views
Why is this snippet working properly, and not here?
I stumbled upon this feature for functions, and was eager to try it out.
However, I ran into an error message, after trying the snippet in python-mode:
[yas] elisp error: Symbol’s value as variable ...
1
vote
1
answer
619
views
Can I create a yasnippet with a repeating variable length list
Javascript Angular has a peculiar pattern for creating controllers that looks like this:
myApp.controller('myController', ['$scope', 'foo', 'bar',
function($scope, foo, bar) {
...
2
votes
0
answers
803
views
Web-Mode + Yasnippets + Autocomplete, error before create-php-snippet
I am trying to use auto-complete + php-auto-yasnippets with web-mode, but I can't get the snippets to work correctly.
If I start typing imp, I correctly get auto-completion to implode but if I press ...
1
vote
1
answer
298
views
yasnippet won't replace default values (placeholders) in org-table caption
I'm using yasnippet to create a template for org-mode tables. This works fine, and allows me to create default values (placeholders) for the column headers. The default values are highlighted by ...
0
votes
0
answers
64
views
A problem of first line of yasnippet
My yasnippet version is 0.8.0 and emacs is 25.0.50
I want to add a default value
And I use following code.
# -*- mode: snippet; require-final-newline: nil -*-
# name: matrix
# key: y_ma
# binding: ...
2
votes
1
answer
250
views
Yank during yas-expand without aborting expansion
When expanding a yasnippet snippet and filling out completion fields yanking/pasting inserts text correctly among fields as expected, but interrupts the snippet expansion behavior (as if pressing C-g /...
1
vote
1
answer
284
views
Is an "Electric" YASnippet possible?
I want to emulate (and even replace) some electric modes (eg. cperl-electric, ruby-electric) with my own custom templates using yasnippet, but it doesn't seem to be possible - can someone enlighten me?...
4
votes
0
answers
116
views
Can I move imports to top of file from yasnippet using elisp code?
I want to add import statements in my yasnippets that go the top of the file (where they will be automatically sorted (or removed if the import already exists)).
from subprocess import call # I want ...
4
votes
0
answers
156
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....
1
vote
0
answers
196
views
Triggering abbreviation expansion or auto completion automatically from a regular expression match?
With abbrev mode, I can define abbreviations that trigger when I type a certain term. For example, typing "yn" would be expanded to "Your Name". For this, "yn" must have been defined as an ...
3
votes
1
answer
319
views
Iterate over string in YAS Snippet?
I'm new to emacs/LISP and would like guidance how to achieve the following output
I'd like to type
"color glass hat sport" in a single string ($1) that will be converted to the following:
Color = "C"...
3
votes
1
answer
157
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
1
answer
462
views
How to get the class name?
I'm trying to devise a function which returns the class name. I would like to call that function inside a Yasnippet snippet for PHP-mode, so the class name will be inserted inside the template snippet....
1
vote
1
answer
490
views
How mirror another line in Yasnippet?
I have the following snippet
/* ----------------------------------------------------
* METHOD ${1:$$(upcase yas-text)}.
* ---------------------------------------------------- */
public function f$1($...
5
votes
1
answer
913
views
Disable default Yasnippet snippets?
How do I disable all pre-existing yasnippet snippets? I only want to use ones that I define myself.
3
votes
2
answers
864
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 ...
0
votes
0
answers
27
views
Yasnippet with CEDET [duplicate]
I used to launch yasnippet just with c-mode with a hook in my .emacs but after adding some code to use CEDET and ECB yasnippet doesn't run automatically. I guess some modes may have been overwritten ...
5
votes
1
answer
137
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 ...
2
votes
1
answer
111
views
how to make yasnippet case insensitive
I want yasnippet to expand both "Cp" and "cp" into the same, say, "\citep{}".
How can this be done? Is there a way to make yasnippet case insensitive? As a quick-and-dirty solution, I tried ...
1
vote
1
answer
395
views
.yas-parents have no effect with web-mode
I'm using web-mode and yasnippet for coding PHP and HTML.
To use yasnippet in web-mode, will have to install php-mode, php-auto-yasnippets, emmet-mode and ac-emmet as suggested in web-mode.org. But I ...
5
votes
3
answers
903
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 ...
0
votes
0
answers
152
views
Need help with a snippet
Can someone help me with this snippet? I found it here
# -*- mode: snippet -*-
# name: jsdoc comment
# key: doc
# --
/**
* $0
`(save-excursion
(let* ((pos-fun (re-search-forward "\\<function\\s-*(...
0
votes
1
answer
1k
views
How to install/setup yasnippet for buffer-local usage?
The instructions for installing yasnippet globally are set forth in the Github README.mdown -- https://github.com/capitaomorte/yasnippet -- and also in the comments at the top of yasnippet.el library.
...
4
votes
1
answer
1k
views
in yasnippet, how to insert variable date with fixed time of day?
I want a yasnippet to insert an org-mode date and time.
The date should be today's date, but the time should be fixed.
So far my snippet correctly inserts today's date, but not the time:
# -*- ...
1
vote
0
answers
425
views
Remove strange keybindings from YASnippet
I have YASnippet installed in emacs 24.5, which wasn't working and after a lot of different attempts at a fix, I now have the basics working, however - somewhere along the way - I have collected the ...
-1
votes
1
answer
656
views
yasnippet doesn't recognize $0 placeholder, why?
My emacs is running on Window 7 and I have just installed yasnippet via M-x package-list and added few lines to my .emacs file because I read around the web that it needs to be initialized.
I tried ...
3
votes
1
answer
2k
views
disable TAB in company-mode
I'm trying to get several plugins all playing nicely: yasnippet, company-mode and ENSIME.
I'm aware of How to make yasnippet and company work nicer? but I was thinking about another, simpler, ...
0
votes
2
answers
411
views
Mirror with character replacement in yasnippet
I would like to do 2 things: first mirror a field and replace spaces with "-". If nothing is typed in the field, junto to the mirror. The code is:
\begin{theorem}[$1]
\label{thm-${1:$( ???? )}}
$0
...
0
votes
1
answer
248
views
Why does a theme change cause reloading - YASnippet
The problem:
Before installing YASnippet changing themes was instantaneous, now it YASnippet reloads itself in someway making changes take a few seconds.
Is this functionality necessary? Can I turn ...
1
vote
1
answer
273
views
Yasnipped expand also after character
I am trying to write a snipped mode for writing subscripts in LaTeX:
# -*- mode: snippet -*-
# name: sub
# key: _
# --
_{\text{$1}}$0
If I type just _ + TAB it expands correctly as expencted. But ...