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
42 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
0answers
20 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
11 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
20 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
21 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} * @...
0
votes
0answers
17 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 ...
2
votes
1answer
99 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 ...
1
vote
1answer
76 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
34 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) { ...
0
votes
1answer
91 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
0answers
25 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
0answers
7 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 ...
1
vote
2answers
58 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 ...
0
votes
0answers
21 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
31 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
40 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 ...
2
votes
1answer
23 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
1answer
67 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
50 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
39 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
26 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
25 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 ...
0
votes
0answers
19 views

Using yas-choose-value and a multi-level menu?

I am trying to finds some example code that uses YASnippet's yas-choose-value to display/select items from a GUI menu with sub-menus. My plan had been to use the popup-el package to implement this, ...
1
vote
0answers
19 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
47 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
59 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
32 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
3answers
116 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 ...
1
vote
1answer
83 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
148 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 ...
2
votes
0answers
875 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
38 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
105 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 ...
1
vote
1answer
178 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
1answer
50 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
241 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 ...
1
vote
1answer
50 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 ...
4
votes
1answer
101 views

sh-script-mode: get [[ … ]] pair expansion to automatically include whitespace?

Say you're coding a shell script and you want to write something like: if [[ "$out" =~ 'none' ]]; then return $err fi If you're just typing it out and have any of the various electric/pair ...
3
votes
1answer
223 views

Yasnippets for active web-mode engine

Say I have a snippets folder: snippets/web-mode/ ├── django │   ├── else │   ├── for │   └── if └── erb ├── else ├── for └── if Both engines have different syntax ({% %} and {{ }} vs <...
2
votes
1answer
63 views

How to tell YASnippet to ignore placeholder?

I have a shell script which uses an array to check dependencies. I'd like to make this into a YASnippet, but YAS recognizes the array value statement ${dependencies[@]} as a placeholder. How can I ...
0
votes
2answers
128 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. ...
2
votes
2answers
189 views

Run function after specific snippet

I have a workflow that goes like, 1) use a snippet then 2) call a function. What a glorious opportunity to automate! But how? The snippet ipdb inserts import ipdb; ipdb.set_trace(). It has ...
1
vote
1answer
65 views

Setting An Org Heading Property From Yasnippet

I have a yasnippet snippet for adding the boilerplate to my "daily review" org document. Here's what it looks like: # key: ndr # name: newdailyreview # -- * Accomplishments :PROPERTIES: :CUSTOM_ID:...
0
votes
0answers
254 views

Whats the recommended way to install yasnippet for an emacs prelude user?

Is doing mkdir ~/.emacs.d/personal/snippets/ the correct way and putting snippets there? I've been reading https://github.com/bbatsov/prelude/issues/98 What I did: ;; personal.el (prelude-require-...
1
vote
1answer
147 views

How to make yasnippet fall back to self-insertion when it shouldn't expand

I've decided to try out yasnippet recently, and while it seems to work for me, I have an issue with how it handles comments. I've set my trigger key to SPC, which causes unnecessary snippet expansion ...
3
votes
1answer
192 views

Expand yasnippet only when it's at beginning of the line

How to write snippet condition to expand it only when it's positioned at the beginning of the line?
1
vote
1answer
280 views

Yasnippet: Prompting the user for information to fill in a latex snippet

I write a snippet to insert a theorem environment into a latex document, based upon some snippets created by another project: https://github.com/madsdk/yasnippets-latex . In the snippet below, the ...