Skip to main content

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
0 answers
5 views

comment-dwim inserting leading spaces in prog-mode

I started using yasnippet today, and was surprised with this buffer when using yas-new-snippet: # -*- mode: snippet -*- # name: # key: # -- I could see there was nothing unusual ...
dmvianna's user avatar
  • 392
0 votes
1 answer
23 views

How to fix "does not contain : exactly once" Yasnippet warning?

I have the following yasnippet warning message for each major mode and .yas-parents directory: yatemplate: ~/snippets/org-mode does not contain : exactly once yatemplate: ~/snippets/lua-mode does not ...
Nikita Fedyashev's user avatar
0 votes
0 answers
38 views

Wrong type argument: symbolp, 'yas-minor-mode

Whenever I type, Emacs gives me the warning 'wrong type argument: symbolp, 'yas-minor-mode'.
Beginner's user avatar
0 votes
0 answers
57 views

'fr<Tab>' doesn't expand at all

I'm trying to take lecture notes using org-mode and cdlatex-mode. The problem I meet is when I try to use Tab to expand fr it doesn't expand correctly. \(fr<Tab>\) will become \(\begin{frame}[]\...
Beginner's user avatar
0 votes
0 answers
54 views

Yasnippet not working properly in Latex but works in other Modes

As the title says, when I am editing a LaTeX document I cannot do yas-expand. Note that yas-insert-snippet works fine (although also here the shortcut does not work, I have to call it using M-x 'yas-...
julian's user avatar
  • 1
0 votes
0 answers
19 views

yas-expand-snippet and yas-lookup-snippet?

I've two small snippets, where I'm trying to expand one snippet inside another. As the snippet that gets expanded is always the same one, and it's always expanded I've been trying to use yas-expand-...
Andy's user avatar
  • 21
0 votes
1 answer
56 views

Use contents of a heading in Yasnippet

Is it possible to define a yasnippet that will pick up contents of a heading? Say, I have something like this: * Heading 1 :PROPERTIES: :CUSTOM_ID: MyHead :END: Text under Heading 1 I will like to ...
Deshmukh's user avatar
0 votes
1 answer
64 views

Yasnippet returns Wrong type argument: listp

After inserting the snippet I'm able to type the function name. But after tabbing to args, I get the error Wrong type argument: listp on typing Is it python-args-to-docstring failing at it's job? I've ...
jjk's user avatar
  • 758
0 votes
2 answers
48 views

In LaTex mode, check if we are not in math mode for aas package

I am using the aas package (auto-activating snippets). When I want a snippet to expand we can do so by putting the following in the use-package declaration in the .emacs file: :cond #'texmathp "...
DennisJohnson's user avatar
0 votes
1 answer
23 views

help: yasnippets won't load table

I'm having trouble with yasnippets. I install it but it won't work -- it does not expand anything. When I do yas-describe-table-by-namehash it lists "Snippet table LaTex-mode" "Snippet ...
DennisJohnson's user avatar
0 votes
0 answers
18 views

How to stop yasnippet from triggering multiple times on same instance

I am having trouble with yasnippet triggering multiple times. If I type $times$ it will trigger and change to $\times$ but then everytime I move my cursor through $\times$ it will trigger again. So if ...
DennisJohnson's user avatar
0 votes
0 answers
40 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
14 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
1 vote
0 answers
34 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
1 answer
42 views

emacs as CLI to transform strings

Is it possible to use emacs as just an CLI tool to transform some strings? What I want is to use yasnippet to generate file by template. I use emacs, but my team doesn't and it would be nice to have ...
Andrey's user avatar
  • 13
1 vote
1 answer
81 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
  • 189
0 votes
1 answer
95 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
  • 805
0 votes
1 answer
61 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
101 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
1 answer
81 views

Coding system issues broke my emacs

I was messing with trying to get emojis to display and I broke my emacs by messing with the coding system settings somehow. After my desktop file failed to load, I uninstalled unicode-fonts and ...
firstname gklsodascb's user avatar
0 votes
1 answer
187 views

Why does this yas-snippet (with yas-selected-text) not moving the cursor as intended?

I have following yas-snippet for inserting latex equation parenthesis in selected region. # -*- mode: snippet -*- # name: parenthesis_region_() # binding: M-r ( ) # -- \left( `yas-selected-text` \...
Garid's user avatar
  • 760
0 votes
2 answers
61 views

How to insert kbd macros in Yas-snippets?

I'm trying to learn how to: Define a kbd-macro, (here I'm using kbd-macros, because I'm bad at elisp currently). Letting that to be executed when yas-snippet to expand. (here I'm struggling with) My ...
Garid's user avatar
  • 760
0 votes
1 answer
46 views

Cannot expand yasnippets in .el files

I want to use yasnippet in three modes. I have this in my init.el: ;;; Yasnippet (use-package yasnippet :commands yas-minor-mode :config (yas-reload-all) :hook ((org-mode text-mode emacs-lisp-...
Edman's user avatar
  • 1,229
0 votes
0 answers
109 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
  • 805
2 votes
1 answer
429 views

How to expand yas-snippet, when trigger-key is part of a word?

I have following yas-snippet (for python-mode): # -*- mode: snippet -*- # name: .s-np_array_shape # key: .s # -- .shape And now, .s Tab gives .shape as expected. What I want: This doesn't expand if ...
Garid's user avatar
  • 760
2 votes
1 answer
72 views

Any yasnippet to evaluate infix math expression?

I would like to have a yasnippet to evaluate infix math expression on the current line. E.g., If the line is 1 + 2 = and I trigger yasnippet at the end of line, it will append the result at the end: ...
AhLeung's user avatar
  • 1,113
0 votes
1 answer
216 views

Company doesn't load with Yasnippet

Facing strange problem with auto-completion company-mode. I use the packages Company mode and Yasnippet. When I'm typing in a buffer, I get autocompletion suggestions from Company with Yasnipper. But ...
Likhon BaRoy's user avatar
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
1 answer
56 views

How can I control the order of entries in the YASnippet menu?

I use YASnippets for everything and often use them through YASnippet menu. For any given major-mode, I use the .yas-parents file and put the directory/names in the order that I want them. But they ...
Mohsen Banan's user avatar
0 votes
2 answers
543 views

Is there a default folder for yas-snippets?

Does anyone know where yas-lookup-snippet gets its snippets from? I recently did a few changes with my snippets and now face that every time I want to open a new file I get the message: yas-lookup-...
Qohelet's user avatar
  • 185
0 votes
1 answer
161 views

Call an interactive elisp-function inside an YaSnippet

When trying to evaluate an interactive elisp-function which needs an argument in a yasnippet, it gives the error wrong number of arguments. I assume, the reason is, that the function is interactive ...
Sinthoras's user avatar
0 votes
1 answer
152 views

Help with yasnippets installation

Recently, I asked about inserting a snippet with auto-insert-alist. That works but now I thought about using Snippets for blockquote, for inserting images, etc. I’ve been trying to install Yasnippets ...
zeynel's user avatar
  • 407
2 votes
1 answer
77 views

How do I move the cursor back after completing yas-choose-value?

I have a snippet set like so: import React from 'react' const ${1:$$(file-name-base)} = ( ${2:$$(yas-choose-value '("\{ \}" "props"))} ) => { return ( $0 ) } export ...
mustaqim's user avatar
1 vote
1 answer
211 views

How to use a Template for creating YaSnippet snippets

I want to have a way, to efficiently create new YaSnippet-snippets. YaSnippet has the functionality, that via pressing C-c C-n one can create a new snippet. However, the empty new snippet is very ...
Sinthoras's user avatar
0 votes
2 answers
134 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
  • 491
0 votes
0 answers
176 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
115 views

Why does yasnippet insert a newline before the cursor?

This is my snippet, in org-mode: # key: quote # name: quote block # -- #+begin_quote `%`$0 #+end_quote Result: #+begin_quote | <- cursor #+end_quote Desired: #+begin_quote | <- cursor #+...
Josh Friedlander's user avatar
1 vote
0 answers
164 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
0 votes
1 answer
54 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
2 votes
1 answer
116 views

Binding several keys to one yasnippet

Suppose we have a snippet for sql mode: # -*- mode: snippet -*- # name: select * # key: sel # -- SELECT ${1:*} FROM $2; Sometimes I forget to switch the keyboard layout and type Russian "ыуд&...
user4035's user avatar
  • 1,089
0 votes
1 answer
113 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
  • 588
0 votes
0 answers
180 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
  • 228
2 votes
1 answer
482 views

Calling elisp functions from inside yasnippet

I created a yasnippet that calls a function: # -*- mode: snippet -*- # name: print # key: pr # -- `(cperl-print)` The function code: (defun cperl-print () (interactive) (let* ((current (point)) ...
user4035's user avatar
  • 1,089
0 votes
1 answer
195 views

How to use yasnippets from js- and css- modes in html-mode?

I have latest YASnippet package installed on GNU Emacs 27.2 via MELPA. Snippets work, for example in *.js files, let expands to snippet after hitting TAB. However, when I edit HTML file (in html-mode),...
Vlad Havriuk's user avatar
2 votes
2 answers
2k views

How to enable yasnippets for all modes?

Company doesn't show snippets in some modes e.g. python or sh. Yet yas/describe-tables displays all snippets. In other modes e.g. org,emacs-lisp, snippets are shown as expected. Looking at company-...
jjk's user avatar
  • 758
0 votes
1 answer
164 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
50 views

How to apply `yasnippets` only for keywords at the beginning of the line? [duplicate]

I am using Python but some pre-defineted snippets. I was wondering is it possible to apply them if the keyword is the first word. if and [TAB] converted into if cond:. I want this behaviour if the ...
alper's user avatar
  • 1,460
2 votes
2 answers
1k views

How to remove or overwrite a `yasnippets`?

I am using Python but some pre-defineted snippets are acting not as I wanted, hence I want to remove some, if possible. In most cases, I am using TAB for indent alignment, hence yasnippets apply ...
alper's user avatar
  • 1,460
1 vote
1 answer
375 views

How to turn on "helm-mode" for a specific function?

The context I've defined a big set of yasnippet snippets and sometimes I forget the shortcut for those snippets. I've found out recently that the function yas-insert-snippet can be used to insert a ...
Rodrigo Morales's user avatar
1 vote
1 answer
203 views

Is it possible to add descriptions for the yas-choose-value choices?

I got a simple snippet for the opening a file in PHP: fopen('${1:./filename.txt}', '${2:$$(yas-choose-value '("r" "w" "a" "x" "r+" "w+" &...
Fabman's user avatar
  • 588

1
2 3 4 5