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.

Filter by
Sorted by
Tagged with
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 ...
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-...
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) (...
0 votes
0 answers
16 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 ...
0 votes
1 answer
144 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 ...
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 ...
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 ...
3 votes
1 answer
782 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 ...
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-...
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 ...
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 ...
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 ...
2 votes
1 answer
97 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 "ыуд&...
5 votes
3 answers
881 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 ...
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 ...
2 votes
2 answers
1k 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-...
4 votes
1 answer
4k 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 "...
1 vote
1 answer
41 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 ...
0 votes
1 answer
332 views

Capitalize word as you type in emacs/spacemacs (YAS snippet)

Trying the following yas snippet # -*- mode: snippet -*- #name : vuex-action #key : va # -- [${1:$$(capitalize-word yas-text)}]: ({ commit, dispatch, getters, }, { $2, }) => { commit($1, { $2, })...
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 ...
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 ...
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 ...
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)...
0 votes
1 answer
60 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 ...
0 votes
1 answer
130 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` \...
0 votes
2 answers
53 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 ...
0 votes
2 answers
378 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-...
0 votes
1 answer
30 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-...
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. ...
2 votes
1 answer
355 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 ...
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 -*- # ...
4 votes
2 answers
1k views

Yasnippets: loading two major modes (`org-mode` and `LaTeX`)

I'm trying to load the yasnippets for the LaTeX mode every time I open an org file. Is it possible? How can this be achieved?
2 votes
1 answer
58 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: ...
2 votes
1 answer
62 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 ...
0 votes
2 answers
758 views

Menu bar drop-downs empty

I am using Emacs 25.3.2 on Linux Ubuntu 16.04. The problem is that several of the menu bar items produce empty drop-downs. A grey box appears, but with nothing inside. It looks like this: I ...
0 votes
1 answer
135 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 ...
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 ...
0 votes
1 answer
53 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 ...
0 votes
1 answer
107 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 ...
0 votes
1 answer
63 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 ...
1 vote
1 answer
164 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 ...
0 votes
0 answers
163 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 ...
0 votes
1 answer
83 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 #+...
4 votes
3 answers
1k views

Creating a custom Yasnippet with conditions

I have a yasnippet that is conflicting with multiple-cursors because it is not exiting immediately. When multiple-cursors is not active, I would like the snippet to pause and permit me to enter the ...
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 ...
2 votes
1 answer
345 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)) ...
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 ...
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: ...
1 vote
2 answers
438 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 ...
0 votes
0 answers
164 views

how to suppress elisp evaluation output in yasnippet?

I'm trying to write a yasnippet template to write a standard header at the top of files. I have (goto-char (point-min)) at the beginning of the template in order to move point to the top of the buffer;...

1
2 3 4 5