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
0answers
9 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
24 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
30 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 ...
1
vote
0answers
17 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
49 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 ...
0
votes
1answer
27 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
8 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
37 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
25 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
22 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
14 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, ...
0
votes
0answers
13 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
37 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
42 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
27 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? ...
2
votes
3answers
68 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
57 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
103 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
49 views

Unable to use yasnippet with Emacs on Mac or Windows

I've been trying to make yasnippet work with my Emacs on Mac OS 10.15 and Windows 10 but have failed till now. Along with a few other routes that I took, below is one of them: Install the package ...
0
votes
0answers
34 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
28 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
610 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
35 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
66 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
119 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 **...
0
votes
1answer
41 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
145 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 ...
0
votes
1answer
42 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
100 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
182 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
61 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
105 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
148 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
55 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
180 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
114 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
154 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
212 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 ...
0
votes
1answer
589 views

Best pratice advices for abbrev vs. completion vs. snippets

I am not sure if this is really a proper question but I am interested in having some opinions about the most efficient usage of Emacs' abbreviations features (abbrev/dabbrev) in combination with auto-...
0
votes
1answer
54 views

yasnippet: jump at the beginning of inserted snippet

Is it possible to define that after inserting a snippet, the cursor will jump at the beginning of what has been inserted? It will make it even more fun.
1
vote
1answer
95 views

Can you setup a snippet with two choices, where the second choice depends on the first choice?

I am trying to setup a snippet to add a src-block header to an emacs org-mode src-block. I want to get a list of possible headers to choose from, which I can get in this snippet (the org-babel-headers ...
4
votes
1answer
271 views

Yasnippet: How to automatically advance to next field after `yas-choose-value`

Yasnippet has a function called yas-choose-value which is used like this: <div align="${2:$$(yas-choose-value '("right" "center" "left"))}"> $0 </div> How can I automatically exit the ...
2
votes
1answer
233 views

Yasnippet: How to create multiple snippet key bindings

I have a yasnippet with # binding: TAB f o o in the header. This is processed by the yasnippet library as 9 102 111 111. With respect to a keymap of a major-mode, both \C-i and (kbd "TAB") are ...
0
votes
1answer
79 views

Make yasnippet context sensitive

In LaTeX I often use pythontex in a way that there is a block \begin{pycode}[sessionname] ... \end{pycode} where I make some calculations. Then in the following text I refer to variables defined there ...
0
votes
2answers
147 views

Can't get automated c++ docstrings to work

I stumbled this thread and at first, it seems glorious, but I simply cannot get it to work. So when I try it on any program e.g.: #include <iostream> bool helloWorld(int a,int b){ dox<...
0
votes
1answer
197 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, })...
2
votes
0answers
156 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, ...
1
vote
0answers
53 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 ...
2
votes
1answer
230 views

How to insert leading spaces/tabs in yasnippet? [duplicate]

yasnippet does not respect spaces or tabs when they occur at the start a line. In my snippet file I have example which executes as example Escaping with \ doesn't work. How do I get leading ...
2
votes
0answers
785 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-...