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
6 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
35 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
18 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
20 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
1answer
41 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 ...
0
votes
1answer
191 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, })...
3
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 ...
0
votes
0answers
11 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
33 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
38 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
4answers
1k 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 ...
2
votes
3answers
57 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 ...
2
votes
1answer
314 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
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 "...
1
vote
1answer
52 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
86 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
38 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
493 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
58 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
96 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
104 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
161 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
0answers
78 views

spacemacs: show yasnippets at top of completion popup list

yasnippet can be integrated into auto-compltion in spacemacs. I want to show snippets at the top of the auto-completions list. Default is at bottom. foo_______________ |foo -> foo snippet| |foo ...
0
votes
0answers
19 views

Find files interactively with a yassnippet with helm-find-files?

I've seen the answers to this question on inserting filenames interactively within a yasnippet. They are excellent and work great. I was wondering, however, if it's possible to expand them to use the ...
0
votes
1answer
40 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
119 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
109 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 ...
2
votes
2answers
1k views

Python docstrings only allow two indent levels

I am trying to write a docstring that follows Google's style guide such that it looks something like: def testFunction(a, b): """ Args: a (str): b (str): Returns: ...
2
votes
1answer
158 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 <...
4
votes
1answer
99 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 ...
2
votes
1answer
58 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 ...
1
vote
1answer
51 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:...
2
votes
2answers
138 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 ...
0
votes
0answers
155 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-...
6
votes
2answers
920 views

Warning (yasnippet): modified buffer in a backquote expression

When I use yasnippet, I keep getting this error: Warning (yasnippet): `foo-snippet' modified buffer in a backquote expression. To hide this warning, add (yasnippet backquote-change) to `warning-...
5
votes
1answer
235 views

How do you make an optional field and comma in a yasnippet?

I want to make a snippet for a function with optional arguments. For example something like: myfunc($1, $2, $3) But in this case, $2 may be optional. I know I can press Ctrl-D to skip it, but it ...
5
votes
2answers
425 views

YASnippet: How to resume (or reactivate) snippets after exiting them

After exiting yasnippet snippets that contain one or more tab stops, I often find myself wanting to go back and modify content that I entered at the tab stops. Of course, I can do this using standard ...
5
votes
1answer
193 views

Yasnippet expand snippet automatically instead of prompting possible completions

I have two snippets: e[TAB] expands to $ $1 $ $0 ($1 and $0 are placeholders); emph expands to \emph{$0} ($0 is a placeholder, this is a default snippet I suppose) I'm writing a lot of equations ...
2
votes
0answers
774 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-...
3
votes
1answer
142 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
195 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 ...
3
votes
1answer
130 views

Fill-column conflicts with YASnippet [Examples in gif]

I use fill-column in my dot-Emacs. And I have the following setting: (turn-on-auto-fill) (set-fill-column 60) The result looks like this: Every time when the input exceeds columnnumber 60, it will ...
13
votes
1answer
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
544 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-...
4
votes
1answer
253 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 ...