Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Nested snippets and embedded elisp #269

joaotavora opened this Issue Jul 22, 2012 · 1 comment


None yet
2 participants

joaotavora commented Jul 22, 2012

---------- Forwarded message ----------
From: OMF obsessivemathsfreak@gmail.com
Date: Sun, Jul 22, 2012 at 6:09 PM
Subject: Nested Snippets behaviour: Value of yas/text
To: smart-snippet@googlegroups.com

I have written the following snippet for expanding the \sqrt function in latex. But There are problems when calling the snippet from within itself or any other snippets. ( I have yas/triggers-in-field set)

This function can be called as \sqrt{x} for a square root, or as \sqrt[n]{x} for an nth root. Calling it as \sqrt[]{x} causes problems, so the code below only prints the [] when n is a non-empty string

# -*- mode: snippet -*-
# key: rt
# group: math
# name : \sqrt[n]{x} or \sqrt{x}
# --
\sqrt${1:$(if (string-equal "" yas/text) "" "[")}${1:}${1:$(if (string-equal "" yas/text) "" "]")}{$2}$0

Now, this snippet works perfectly on its own, in latex-mode or using tryout-snippet. Typing
"rt TAB 3 TAB 2 TAB" produces \sqrt[3]{2}
and typing
"rt TAB TAB 2 TAB" produces \sqrt{2}
as expected

However, if it is called from within itself or another snippet, the snippet will not produce the square brackets. For example typing
"rt TAB 3 TAB rt TAB 5 TAB 2 TAB TAB"

The yas/text field in the elisp code appears to have been detected as null in the nested snippet call.

Is there a workaround for this behaviour? Is there another yas/variable which contains the text that the elisp could should be calling? Any help would be appreciated.

@joaotavora joaotavora was assigned Jul 22, 2012


npostavs commented Nov 30, 2013 edited

Simpler example:

# -*- mode: snippet; require-final-newline: nil -*-
# name: nest
# key: nest
# --
one($1:$1) two($2).$0

@npostavs npostavs closed this in #778 Mar 11, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment