Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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.

60 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4 votes
0 answers
152 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....
Dan's user avatar
  • 243
4 votes
0 answers
289 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 ...
Dan's user avatar
  • 33.1k
3 votes
0 answers
286 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 ...
jue's user avatar
  • 4,576
3 votes
0 answers
90 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: ...
Toothrot's user avatar
  • 3,264
3 votes
0 answers
111 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 ...
The Unfun Cat's user avatar
3 votes
0 answers
245 views

Jump sequence for placeholders in yasnippet not working in org-property blocks

I use the yasnippet bundle and it works like charm. When I want to include placeholders in a PROPERTIES section of an org-document it is not working. Here's the snipper: #type: snippet # -- :...
cb0's user avatar
  • 1,077
2 votes
0 answers
2k 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 ...
GaryO's user avatar
  • 496
2 votes
0 answers
301 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, ...
Werner's user avatar
  • 355
2 votes
1 answer
1k 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-...
fowlduck's user avatar
  • 121
2 votes
0 answers
196 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:...
ebpa's user avatar
  • 7,499
2 votes
0 answers
800 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 ...
Holt's user avatar
  • 175
2 votes
0 answers
1k views

Stop Yasnippet from autoloading

Is there a way to stop Yasnippet from autoloading? I installed it from melpa (v.20141102.1554), and have no reference to it in my init files. However, keeps up autoloading whenever I run emacs. I only ...
NVaughan's user avatar
  • 1,481
1 vote
0 answers
23 views

Arbitrary number of fields in yasnippet

Is it possible in a yasnippet snippet to create an arbitrary number of fields following a template, stopping only once the user indicates they are done entering fields? Example One use case is to ...
holocronweaver's user avatar
1 vote
0 answers
116 views

Insert single date stamp with Yasnippet and date prompt or org-read-date

For kontext: The emacs package "Yasnippet" let's you replace a keyword (like "/newagenda") with a predefined text. It lets you also modify some variable fields quickly after the ...
breathe_in_breathe_out's user avatar
1 vote
0 answers
37 views

Don't understand the key binding for `auto-yasnippet`

I am looking to use auto-yasnippet but I don't understand the key bindings they are suggesting such as H-w and H-y. I haven't seen any key binding that starts with H so I am not sure what that is. I ...
user29896's user avatar
1 vote
0 answers
34 views

yas-expand doesn't trigger reindent in aggressive-indent-mode

I'm trying to make a call to yas-expand doesn't trigger aggressive-indent. I'm guessing this is because yas-expand, for some reason, doesn't trigger a call to after-change-functions into which ...
Nordlöw's user avatar
  • 507
1 vote
0 answers
47 views

Autodocument function for C Code

Suppose i have this line of code presenting a C function prototype: int sum_Func(int a, int *b) I want an Emacs lisp function that adds the function description (initialization) according to its ...
Ghost_tn's user avatar
1 vote
0 answers
94 views

How can insert a yasnippet snippet not from the current major mode?

Sometimes I am editing multiligual documents (like jinja templates) and I just want to insert a snippet from something that is not in the current major mode. Furthermore, some document types don't ...
salotz's user avatar
  • 1,410
1 vote
0 answers
107 views

using org table as yasnippet input

I'm using yasnippets to create code blocks in org mode to document and execute DevOps activities. To improve productivity, it would be nice to have a possibility to create org tables with rows of ...
Micl's user avatar
  • 21
1 vote
1 answer
453 views

Using auto-insert and yasnippet to insert variables into template

I've been reading this and this, trying to figure out how to have an org-mode in-buffer settings template such as this: # # -*- mode: org -*- # # -*- coding: utf-8 -*- #+TITLE: $1 #+AUTHOR: `(user-...
147pm's user avatar
  • 2,969
1 vote
0 answers
51 views

Massively long text boxes and yasnippet highlighting

Why are my text boxes and yasnippet field highlights so massively long? Is there a way to change this behavior? If so, what are the necessary steps that need to be taken to solve this issue? The ...
John DeBord's user avatar
1 vote
0 answers
100 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 ...
Prunus Persica's user avatar
1 vote
0 answers
110 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}. # -----...
ReneFroger's user avatar
  • 3,880
1 vote
0 answers
72 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. ...
Chris H's user avatar
  • 133
1 vote
0 answers
63 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 ...
Toothrot's user avatar
  • 3,264
1 vote
0 answers
153 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 ...
kjo's user avatar
  • 3,247
1 vote
0 answers
194 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 ...
Felix Hoffmann's user avatar
1 vote
0 answers
422 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 ...
n1k31t4's user avatar
  • 689
1 vote
0 answers
639 views

Autocomple not working with yasnippet

I have configured yasnippet and auto-complete bindings so it won't collide, auto complete uses <tab> and yasnippet uses <backtab>: (add-to-list 'load-path "~/.emacs.d/plugins/...
Fabman's user avatar
  • 578
1 vote
0 answers
1k views

Company Completion Within Yasnippet Snippet

I am trying to use company-completion within a Yasnippet header. I bound company-complete to C-SPC and use that for my auto-completion. When I hit control enter, I get a screen like this: And I hit ...
dpbriggs's user avatar
0 votes
0 answers
15 views

How to expand yas-snippets in eshell (under Doom)

(This may have nothing to do with Doom-emacs, but because I use it, I should mention it) The famous "for-loop" expansion (https://xenodium.com/yasnippet-in-emacs-eshell/) does not work for ...
jeffkowalski's user avatar
0 votes
0 answers
8 views

Error yas--advance-end-maybe-previous-fields with autoactivating yasnippets in latex environments in org mode

I get the error yas--advance-end-maybe-previous-fields: Assertion failed: (memq field (yas--snippet-fields snippet)) in org mode when I use snippets that: do not contain $1 in the snippet use auto ...
userrandrand's user avatar
0 votes
0 answers
43 views

Inserting newline in snippet start with YASnippet

I have the snippet # -*- mode: snippet -*- # name: LaTeX display math block # key: dm # -- \[\begin{align*} $1 \end{align*}\] $0 which works fine except for the fact that the newline at the start is ...
daedsidog's user avatar
  • 157
0 votes
0 answers
33 views

Yas-snippets not showing dropdown suggestions for python(only)

As the title says Yas snippets don't show a suggestion dropbox when in python mode.I can still tab complete the snippets(just no suggestions). It works as expected in other modes(tried in latex,org ...
je2144's user avatar
  • 1
0 votes
0 answers
77 views

how to create variable-length fields yasnippet snippet

I'm trying to create a snippet that generate a python docstring. I have a function that parses the current python function for arguments. now I want to use this function in the snippet to generate the ...
ntriisii's user avatar
0 votes
0 answers
11 views

Accessing yassnippet from other editors (namely jupyter lab)

I spend most of my time working in emacs, but some of the time I use jupyter lab (I've played with an emacs extension to talk to jupyter from emacs but have been bitten by bugs - and I also do pairing)...
Att Righ's user avatar
  • 775
0 votes
1 answer
67 views

Can I find snippets using yasnippet for the mode of an org-babel block (e.g. python / bash)?

I like snippets. I use yassnippet a lot. I also use babel in org mode. I would quite like to be able to use my snippets in org babel blocks, but they don't work because I am in the wrong mode. Is ...
Att Righ's user avatar
  • 775
0 votes
1 answer
45 views

How to reset yasnippet default snippet file

for some reason the content of my default +new-snippet+ file has changed from # -*- mode: snippet -*- # name: # key: # -- to # -*- mode: snippet -*- # name: # key: # -- The ...
aQuarkyName's user avatar
0 votes
1 answer
80 views

Make Yasnippet insert characters before the key

I want to create a snippet, which does the following: When I write . foo it creates A.B while the cursor is in front of B. I only found ways to insert text after the key and to delete text before, but ...
Sinthoras's user avatar
0 votes
0 answers
67 views

Is there any way I can have snippets (like yasnippet) but for a particular file?

Sometimes files have quite specific snippets that might be useful? Is there any easy way to have per file snippets? Approach I've got some code that get hold of the snippet text for a desired snippet. ...
Att Righ's user avatar
  • 775
0 votes
0 answers
37 views

How do I create a project tree from yasnippet

I have built a project prototype as a module in a directory tree in the following example: module main.ext module_feature item.ext another_item.ext I would like to insert the module ...
alexander's user avatar
  • 133
0 votes
2 answers
114 views

Does enabling by default a custom input method have any side effect on the default method?

I added these to my init.el: (use-package org :ensure nil :hook (org-mode . (lambda () (org-indent-mode) (variable-pitch-mode -1) (...
Zoli's user avatar
  • 441
0 votes
0 answers
162 views

When using company and lsp, why does the placeholder text sometimes not get replaced?

In a buffer in c-mode with the following content (with point after retu), pressing enter completes to return expression;. int main(int argc, char** argv) { retu } Point is now at the beginning of ...
ruds's user avatar
  • 143
0 votes
1 answer
50 views

History of yasnippet fields

Is it possible to have a history for the value of a yasnippet field? When I expand a second time a snippet like \begin{${1:environment}} I would like to get as suggestion the value I've used for $1 in ...
jo-so's user avatar
  • 51
0 votes
1 answer
106 views

How can I load some snippets depending on the extension of current file?

When I work on web files I usually use web-mode for javascript, php and css files, the problem I have is that yasnippet uses the current mode to find what snippets to load for that buffer ( as stated ...
Fabman's user avatar
  • 578
0 votes
0 answers
151 views

yasnippet: execute function before inserting snippet

I'm using yasnippet to insert text into RMarkdown (.Rmd) files. For example, I can insert a code block which will produce a web map with something like this: Snippet: # -*- mode: snippet -*- # name: ...
haff's user avatar
  • 218
0 votes
1 answer
143 views

Yasnippet-snippets indention not correct for Python functions

Yasnippet-snippets contains a snippet for Python mode to create a function with a docstring. The indention is not correct when I use it, I think it maybe has to do with some Spacemacs settings, but I ...
Cor's user avatar
  • 1
0 votes
0 answers
287 views

Conflict with TAB keybinding for Yasnippet and Orgmode heading

I tried to use Yasnippet to create a template for org-drill "flashcard" # -*- mode: snippet -*- # name: Orgdrill twosided card # key: drill2 # -- * ${1:Write title here} ...
user1683620's user avatar
0 votes
0 answers
167 views

How do I create a snippet that optiionally expands multiple lines using YASnippet(or some other tool)?

I know how to create basic snippets using YASnippet. For example, consider the following snippet: # -*- mode: snippet -*- # name: js-function # key: jsfunc # -- /** @function * @name ${1:fn-name} * @...
Ev3ryDay1sL3gDay's user avatar
0 votes
0 answers
65 views

How to resolve keybinding conflict, or set precedence of the bindings to the same keys for different functions?

How do I resolve keybinding conflict? Or if it's possible to have precedence of keybindings for the same key for different functions? I have the following snippet definition, in org-mode: #+name:${2:...
Yu Shen's user avatar
  • 471