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
3
votes
0answers
63 views

Preferring org-cycle to yas-expand when hitting tab

If both org-mode and yasnippet are active, tab will expand a snippet if possible and otherwise execute org-cycle. Is it possible to reverse this priority? org mode version: 9.0.9. yasnippet version: ...
3
votes
0answers
73 views

Can I move imports to top of file from yasnippet using elisp code?

I want to add import statements in my yasnippets that go the top of the file (where they will be automatically sorted (or removed if the import already exists)). from subprocess import call # I want ...
3
votes
0answers
168 views

Jump sequence for placeholders in yasnippet not working in org-property blocks

I use the yasnippet bundle and it works like charm. When I want to include placeholders in a PROPERTIES section of an org-document it is not working. Here's the snipper: #type: snippet # -- :...
2
votes
2answers
218 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 ...
2
votes
1answer
650 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
2answers
753 views

Yasnippet invoked org-time-stamp function inserts double timestamp

I created a yasnippet template to quickly timestamp a note I'd like to make in org-mode. The body of the yasnippet file reads $0 :PROPERTIES: :CREATED: `(org-insert-time-stamp nil t t)` :END: ...
2
votes
2answers
118 views

How to limit when yasnippet fires?

I found that yasnippet suggests using this code to limit it to only expand when the trigger text has just been typed: (setq yas-expand-only-for-last-commands 'self-insert-command) Unfortunately when ...
2
votes
2answers
652 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 ...
2
votes
1answer
284 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
1answer
883 views

in yasnippet, how to insert variable date with fixed time of day?

I want a yasnippet to insert an org-mode date and time. The date should be today's date, but the time should be fixed. So far my snippet correctly inserts today's date, but not the time: # -*- ...
2
votes
1answer
1k views

disable TAB in company-mode

I'm trying to get several plugins all playing nicely: yasnippet, company-mode and ENSIME. I'm aware of How to make yasnippet and company work nicer? but I was thinking about another, simpler, ...
2
votes
1answer
2k views

Indent each yasnippet line according to major mode

I want to use yasnippets to generate control flow statements in Lua. -- a control flow statement in Lua if foo then return "foo" elseif bar then return "bar" else return "baz" end First I ...
2
votes
1answer
67 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 ...
2
votes
1answer
234 views

How can I define a Yasnippet for #if AND if?

I would like to define one snippet for a cc-mode if statement and a different one for the preprocessors #if statement. I tried just defining those two: For if: # -*- mode: snippet -*- # name : if (.....
2
votes
1answer
769 views

yasnippet truncates clipboard contents

I have a yasnippet that is intended to create a footnote in org-mode format and automatically insert the contents of the clipboard. # -*- mode: snippet -*- # name: footnote # key: fn # -- [fn:: `(...
2
votes
2answers
365 views

Find files interactively with a snippet

It should be nice to write yasnippets, which ask for filepath interactively using helm, predefining starting directory should be fine too.
2
votes
1answer
254 views

Why is this snippet working properly, and not here?

I stumbled upon this feature for functions, and was eager to try it out. However, I ran into an error message, after trying the snippet in python-mode: [yas] elisp error: Symbol’s value as variable ...
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 ...
2
votes
1answer
90 views

Problem redoing with yasnippet

I have had a problem with undoing lately, which seems rather dangerous and has almost lost me work. At first I thought it was due to undo-tree, so I deactivated that. But it persists and now I ...
2
votes
2answers
195 views

How to use yasnippet's tab expansion in minibuffer?

I use yasnippet to insert some symbols (e.g., ✔), and I would like to do that in minibuffer too. When I press TAB in minibuffer, it said " is undefined". How to define it to use yasnippet? Is it ...
2
votes
1answer
257 views

How to cycle back through parameters on a yasnippet?

When I got a snippet with a few parameters: <img src="http://lorempixel.com/${1:width}/${2:height}/${3:$$(yas-choose-value '("abstract" "city" "animals" "food" "people" "transport" "business" "...
2
votes
1answer
259 views

How to get the class name?

I'm trying to devise a function which returns the class name. I would like to call that function inside a Yasnippet snippet for PHP-mode, so the class name will be inserted inside the template snippet....
2
votes
1answer
121 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 ...
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 ...
2
votes
1answer
226 views

how to define a yasnippet in init file?

My init file (.emacs) is version-controlled, my packages are installed with use-package, so my Emacs config is self-contained. I don't want to add (and manage) specific snippet files into my ...
2
votes
1answer
269 views

`expand-env: ((yas-indent-line 'fixed))` ignored

I have the following in a snippet's header expand-env: ((yas-indent-line 'fixed)) ...but when I attempt to insert the snippet, I still get a lot of unwanted indentation. What else can I do to ...
2
votes
1answer
96 views

Why does (indent-region …) insert a 't' into my buffer?

I'm using this yasnippet: # -*- mode: snippet -*- # name : case : {...} # key: case # -- `(indent-region (- (point) 20) (+ (point) 20) nil)`case ${2:constexpr}: ${3:\{} $0 break; ${3:$(if (...
2
votes
1answer
325 views

Browse and search text snippets in emacs and insert them as LaTeX input

Suppose I have a lot of small text snippets (including some LaTeX-code). Now I want to create a LaTeX document with emacs which includes some of the text snippets. I know yasnippet which can expand ...
2
votes
1answer
185 views

Yank during yas-expand without aborting expansion

When expanding a yasnippet snippet and filling out completion fields yanking/pasting inserts text correctly among fields as expected, but interrupts the snippet expansion behavior (as if pressing C-g /...
2
votes
1answer
90 views

how to make yasnippet case insensitive

I want yasnippet to expand both "Cp" and "cp" into the same, say, "\citep{}". How can this be done? Is there a way to make yasnippet case insensitive? As a quick-and-dirty solution, I tried ...
2
votes
1answer
1k views

Yasnippet - No snippet tables active/ YASnippet tables empty

In .emacs, I bound the key for yasnippet as, (define-key yas-minor-mode-map (kbd "C-SPC") 'yas-expand) In a buffer with python as major mode and yasnippet, autocomplete as minor mode, yasnippet ...
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 #...
2
votes
1answer
292 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 ...
2
votes
0answers
180 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, ...
2
votes
0answers
822 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-...
2
votes
0answers
173 views

How to get a global available yasnippet snippet?

How to create a yasnippet snippet which is available in all modes? Lets say I have a function which evaluates the sexpr before the cursor and replaces is with its value, Link to code. Also I caught me ...
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 "...
2
votes
1answer
111 views

add an indicator or annotation on filed which current input is expandable in yasnippet

I have a snippet called struct. And I write text complex_struct in a snippet field. yasnippet will expand complex_struct with the snippet struct. I have to move backward one character to avoid this ...
2
votes
0answers
154 views

Set a field in yasnippet to edit/modify rather than replace default contents

I'm curious if it's possible to define a yasnippet completion field with a default value specified to initially edit/modify the value rather than replace it. For this elementary example: ${1:...
2
votes
0answers
730 views

Web-Mode + Yasnippets + Autocomplete, error before create-php-snippet

I am trying to use auto-complete + php-auto-yasnippets with web-mode, but I can't get the snippets to work correctly. If I start typing imp, I correctly get auto-completion to implode but if I press ...
2
votes
0answers
1k views

Stop Yasnippet from autoloading

Is there a way to stop Yasnippet from autoloading? I installed it from melpa (v.20141102.1554), and have no reference to it in my init files. However, keeps up autoloading whenever I run emacs. I only ...
1
vote
1answer
243 views

Org subtree from yasnippet

Can yasnippet be used to insert an org subtree of the same level as the last? For example, if one often writes ***** $1 #+BEGIN_SRC latex \paragraph{$1.} $0 #+END_SRC how might one avoid ...
1
vote
1answer
1k 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 -*- # ...
1
vote
1answer
41 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 ...
1
vote
1answer
200 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
409 views

Can I create a yasnippet with a repeating variable length list

Javascript Angular has a peculiar pattern for creating controllers that looks like this: myApp.controller('myController', ['$scope', 'foo', 'bar', function($scope, foo, bar) { ...
1
vote
2answers
64 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
1answer
69 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 ...
1
vote
1answer
294 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
165 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 ...