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
1answer
30 views

yas-new-snippet always duplicates the selected input. What might be causing it?

I've experienced this issue for some time. It's not a blocker but it is a bit annoying. Steps to reproduce: Select a region that you want to extract into YASnippet snippet("foo bar"). Eval ...
0
votes
0answers
31 views

Get yasnippets out of company completions list in lsp-mode

Using company-mode and yasnippet, when I tab, I can see my snippets in the drop down menu. I'd like to not see them, and I'm not sure what variables to check out to make it so. I looked through ...
0
votes
1answer
227 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
0answers
11 views

Yasnippet & AutoInsert cutting off template when inserting sub-snippet

So following some examples online, I've got autoinsert and yasnippet set up so that the template gets handled like a snippet. I'm trying to sort out how to include other templates but I'm running into ...
1
vote
1answer
44 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 ...
2
votes
1answer
2k 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 "...
0
votes
1answer
49 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+" &...
0
votes
1answer
53 views

how to append arbitrary string to yasnippet placeholder field

I would like to know how to append a default string to a placeholder. For example, I currently have: # -*- mode: snippet -*- # name: render template # key: rt # group: Flask # contributor: Jon ...
2
votes
1answer
26 views

Create yasnippet placeholder in lisp expression

I am trying to write a snippet to generate different python based on which directory I am in, as in some directories, I am using an older version of python. The snippet is # key: log # name: logger #...
0
votes
0answers
37 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} ...
0
votes
0answers
24 views

Snippet Works with `yas-expand-from-trigger-key` but not `yas-expand`

Emacs: 27.1 Doom: 2.0.9 Yasnippet: 0.14.0 I have the following snippet that I have been using for a while to record "mood" notes in my journal: # -*- mode: snippet -*- # name: New Mood Note ...
0
votes
0answers
25 views

Yasnippet trigger not working

I have installed yasnippet, and confirmed that the minor mode is active, but I can't seem to trigger expansions. This is in my init.el file: (add-to-list 'load-path "~/.emacs.d/...
0
votes
0answers
31 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} * @...
2
votes
1answer
130 views

Call Python from YaSnippet and insert result

I'm trying to build a comparable functionality as described here: https://castel.dev/post/lecture-notes-1/#sympy-and-mathematica Basically, he's using something comparable to yasnippet to send a ...
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 ...
0
votes
1answer
141 views

Make :tangle don't add a newline at the end of the file

The context I'm storing all my custom defined yasnippet snippets in an Org file (see below) $ cat ~/.emacs.d/snippets/snippets.org #+PROPERTY: header-args:yasnippet :mkdirp yes #+begin_src yasnippet :...
1
vote
1answer
145 views

Company-yasnippet doesn't see yasnippet template in lisp

Config: (use-package yasnippet :ensure t :hook (prog-mode . yas-minor-mode) ) (use-package yasnippet-snippets :ensure t :after yas) (use-package common-lisp-snippets :ensure t :after ...
1
vote
1answer
37 views

How to pass the current scopes function symbol as an argument to an elisp function

I am trying to create an org-capture template which works with yankpad and yasnippets to such that if I am working with some c code like this: example.c static int somefunc(int a) { if (a ==5) { ...
1
vote
0answers
26 views

Don't understand the keybinding for auto-yasnippet

I am looking to use auto-yasnippet but I don't understand the keybindings they are suggesting such as H-w and H-y. I haven't seen any keybinding that starts with H so I am not sure what that is. I ...
1
vote
2answers
67 views

Yasnippet conditional template depending on field value

I'm having an issue where I would like to be able to create a template which will conditionally insert a string into the template based on the value of one of the fields. This means I want some sort ...
1
vote
0answers
8 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 ...
0
votes
0answers
24 views

elisp to modify snippets in yasnippet

I have this elisp code from yasnippet: `(progn (goto-char (point-min)) (unless (re-search-forward "^using\\s-+namespace std;" nil 'no-errer) "std::")) `cout << $0${1:} <&...
0
votes
0answers
32 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:...
0
votes
1answer
51 views

yasnippet for org-mode templating : elisp list type problem

I want to use yasnippet to create a generic template for my org-mode files including latex export classe (letters, memos, articles, etc...) It's not that complicated, but I would like Yasnippet to ...
0
votes
1answer
79 views

How can I make abbreviations expand instantly?

Is there a way to make emacs expand abbreviations as soon as I finish typing them, rather than having to use a key combination, tab, or space? For example, I want "`a" to expand to "\alpha". It would ...
1
vote
1answer
73 views

How to expand different snippets depending upon file directory

I have a yasnippet for cperl-mode: # -*- mode: snippet -*- # name: print Dumper # key: vd # -- print Dumper($0); I need to expand this snippet to different strings depending upon the directory of ...
0
votes
0answers
9 views

How to mark fields as non-expandable in yasnippet

How do I selectively mark snippet fields as being expandable or non-expandable? For example, I have a snippet # name: read in vector # key: cinvec # -- std::vector<${1:_type_}> ${2:_name_}(${...
1
vote
0answers
40 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 ...
1
vote
1answer
27 views

How to replace the highlighted word in yasnippet?

After the snippet gets expanded the cursor is put to the first section (long_name). What key do I need to press in order to replace long_name? Evil operations like e.g. cw or ce change long or to ...
2
votes
1answer
26 views

Font-lock Yasnippet template from within Org-Babel block

I want to manage my library of snippets from a single org-mode document and tangle these to their respective snippet files, as needed. Now functionally, this works out-of-the box, with the one ...
5
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 ...
1
vote
0answers
22 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 ...
1
vote
0answers
52 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 ...
0
votes
2answers
70 views

Is it possible to repeat the last org-mode source block's headers

Lately I have been writing a lot of literate sysadmining, writing down my thoughts as I explore systems by executing commands on them. This means that I end up writing the following boilerplate over ...
0
votes
0answers
36 views

yasnippet: problems with text-mode snippets

The snippets in the text-mode subdir are authomatically loaded when I use certain other modes (e.g. latex-mode, cc-mode, ess-mode, etc). There is any way to stop loading snippets of parents mode? ...
4
votes
4answers
2k 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 ...
4
votes
3answers
146 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 ...
3
votes
1answer
373 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 ...
1
vote
1answer
101 views

YASnippet: Remove parts of expanded snippet when exiting the current active area based on condition

I want to write a snippet for LaTeX sum that behaves like this: I write "sum" and trigger snippet expansion. "sum" becomes "\sum_{$1}^{$2} $0", with $1 being the first entry point, $2 the second one ...
1
vote
0answers
177 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
0answers
35 views

`ALT-<return>` breaks ya-snippet

I have a short snippet template which I use to document my patient’s encounter in org-mode. It consists of * Subjective $1 * Objective - Examination: $2 - Investigations seem : $3 * Assessment ...
1
vote
0answers
29 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 ...
1
vote
0answers
1k 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 ...
0
votes
0answers
44 views

prevent yas from inserting a new-line after expansion

So I'm doing a recursive snippet with yas $>name: "${2:`(file-name-nondirectory (file-name-sans-extension (buffer-file-name)))`}"${3:, $>np}$0 but yas inserts a new-line at the end of every ...
2
votes
1answer
113 views

Yasnippets: How to add if statements that check for regex?

I would like to replicate some of the snippets shown in this blog post Some of the snippets shown in that post involved if statements that check for regexp in snippet fields as well as checking for ...
0
votes
2answers
135 views

Problem with org-insert-link and yas-expand

I have a problem when I want to yas-expand a link in Org-mode and it has a dash (-) in the text (url and description). Then the snippet break and exits. If I do the same in fundamental-mode it works. ...
1
vote
1answer
207 views

yasnippet not working on org

I created such a snippet $ cat snippets/diary_template # -*- mode: snippet -*- # name: diary template # key: dt # condition: t # -- **** Personal_Notes **** Personal_Tasks **** Project_Notes **...
1
vote
2answers
186 views

Yasnippets won't expand in git-commit-mode?

I have written a snippet for git-commit-mode. However when I'm writing a commit message (from Magit), the snippet won't trigger. Does anyone know how to fix this? I have yasnippet version 20160924....
0
votes
1answer
58 views

yasnippet color

I use yasnippet in orgmode to expand codeblocks of Python and start typing code. My snippet is defined as: # -*- mode: snippet -*- # name: emacs-jupyter code block for python (silent) # key: <spp #...
1
vote
1answer
307 views

Get autocomplete to display candidates only when tab is pressed

I've set up auto-complete on emacs to display completion candidates, and it seems to be working well so far. I'm finding the constant display (and changes in display) distracting when I type, and I ...