Reference
Table of Contents
- Reference
- Interactive functions
yas-skip-and-clear-or-delete-char
(&optional field)yas-exit-all-snippets
()yas-exit-snippet
(snippet)yas-abort-snippet
(&optional snippet)yas-prev-field
()yas-next-field
(&optional arg)yas-next-field-or-maybe-expand
()yas-describe-tables
(&optional choose)yas-tryout-snippet
(&optional debug)yas-load-snippet-buffer
(table &optional interactive)yas-new-snippet
(&optional no-template)yas-visit-snippet-file
()yas-insert-snippet
(&optional no-condition)yas-expand-from-keymap
()yas-expand-from-trigger-key
(&optional field)yas-about
()yas-recompile-all
()yas-compile-directory
(top-level-dir)yas-reload-all
(&optional interactive)yas-load-directory
(top-level-dir &optional use-jit interactive)yas-minor-mode-on
()yas-direct-keymaps-reload
()yas-global-mode
(&optional arg)yas-minor-mode
(&optional arg)yas-expand
(&optional field)
- Customization variables
yas-expand-only-for-last-commands
yas-visit-from-menu
yas-good-grace
yas-wrap-around-region
yas-trigger-symbol
yas-use-menu
yas-choose-tables-first
yas-choose-keys-first
yas-fallback-behavior
yas-triggers-in-field
yas-snippet-revival
yas-also-auto-indent-first-line
yas-indent-line
yas-prompt-functions
yas-snippet-dirs
()
- Useful functions
yas-active-keys
()yas-hippie-try-expand
(first-time?)yas-define-condition-cache
(func doc &rest body)yas-unimplemented
(&optional missing-feature)yas-inside-string
()yas-default-from-field
(number)yas-selected-text
()yas-text
()yas-field-value
(number)yas-verify-value
(possibilities)yas-throw
(text)yas-key-to-value
(alist)yas-choose-value
(&rest possibilities)yas-substr
(str pattern &optional subexp)yas-text
()yas-define-menu
(mode menu &optional omit-items)yas-define-snippets
(mode snippets)yas-expand-snippet
(content &optional start end expand-env)yas-dropdown-prompt
(prompt choices &optional display-fn)yas-completing-prompt
(prompt choices &optional display-fn completion-fn)yas-no-prompt
(prompt choices &optional display-fn)yas-ido-prompt
(prompt choices &optional display-fn)yas-x-prompt
(prompt choices &optional display-fn)
- Useful variables
- Interactive functions
Reference
Interactive functions
yas-skip-and-clear-or-delete-char
(&optional field)
Clears unmodified field if at field start, skips to next tab.
Otherwise deletes a character normally by calling delete-char
.
yas-next-field
(&optional arg)
Navigate to the /ARG/th next field.
If there's none, exit the snippet.
yas-next-field-or-maybe-expand
()
Try to expand a snippet at a key before point.
Otherwise delegate to yas-next-field
.
yas-load-snippet-buffer
(table &optional interactive)
Parse and load current buffer's snippet definition into TABLE.
TABLE is a symbol naming a passed to yas–table-get-create
.
When called interactively, prompt for the table name.
yas-new-snippet
(&optional no-template)
Pops a new buffer for writing a snippet.
Expands a snippet-writing snippet, unless the optional prefix arg NO-TEMPLATE is non-nil.
yas-visit-snippet-file
()
Choose a snippet to edit, selection like yas-insert-snippet
.
Only success if selected snippet was loaded from a file. Put the
visited file in snippet-mode
.
yas-insert-snippet
(&optional no-condition)
Choose a snippet to expand, pop-up a list of choices according
to yas--prompt-function
.
With prefix argument NO-CONDITION, bypass filtering of snippets by condition.
yas-expand-from-keymap
()
Expand/run snippets from keymaps, possibly falling back to original binding.
yas-expand-from-trigger-key
(&optional field)
Expand a snippet before point.
If no snippet expansion is possible, fall back to the behaviour
defined in yas-fallback-behavior
.
Optional argument FIELD is for non-interactive use and is an
object satisfying yas–field-p
to restrict the expansion to.
yas-recompile-all
()
Compile every dir in yas-snippet-dirs
.
yas-compile-directory
(top-level-dir)
Create .yas-compiled-snippets.el files under subdirs of TOP-LEVEL-DIR.
This works by stubbing a few functions, then calling
yas-load-directory
.
yas-reload-all
(&optional interactive)
Reload all snippets and rebuild the /YAS/nippet menu.
When called interactively force immediate reload of all known
snippets under yas-snippet-dirs
, otherwise use just-in-time
loading.
yas-load-directory
(top-level-dir &optional use-jit interactive)
Load snippets in directory hierarchy TOP-LEVEL-DIR.
Below TOP-LEVEL-DIR each directory should be a mode name.
Optional USE-JIT use jit-loading of snippets.
yas-minor-mode-on
()
Turn on /YAS/nippet minor mode.
Honour yas-dont-activate
, which see.
yas-global-mode
(&optional arg)
Toggle Yas minor mode in all buffers. With prefix ARG, enable Yas-Global mode if ARG is positive; otherwise, disable it. If called from Lisp, enable the mode if ARG is omitted or nil.
Yas minor mode is enabled in all buffers where
yas-minor-mode-on
would do it.
See yas-minor-mode
for more information on Yas minor mode.
yas-minor-mode
(&optional arg)
Toggle /YAS/nippet mode.
When /YAS/nippet mode is enabled, yas-expand
, normally bound to the TAB key, expands snippets of code depending on the major
mode.
With no argument, this command toggles the mode. positive prefix argument turns on the mode. Negative prefix argument turns off the mode.
Key bindings: \{yas-minor-mode-map}
yas-expand
(&optional field)
Expand a snippet before point. If no snippet
expansion is possible, defer to yas-fallback-behaviour
(which see).
Optional argument FIELD is for non-interactive use and is an
object satisfying yas–field-p
to restrict the expansion to.
Customization variables
yas-expand-only-for-last-commands
List of last-command
values to restrict tab-triggering to, or nil.
Leave this set at nil (the default) to be able to trigger an expansion simply by placing the cursor after a valid tab trigger, using whichever commands.
Optionally, set this to something like '(self-insert-command) if you to wish restrict expansion to only happen when the last letter of the snippet tab trigger was typed immediately before the trigger key itself.
yas-good-grace
If non-nil, don't raise errors in inline elisp evaluation.
An error string "[yas] error" is returned instead.
yas-wrap-around-region
If non-nil, snippet expansion wraps around selected region.
The wrapping occurs just before the snippet's exit marker. This can be overridden on a per-snippet basis.
yas-choose-tables-first
If non-nil, and multiple eligible snippet tables, prompts user for tables first.
Otherwise, user chooses between the merging together of all eligible tables.
This affects yas-insert-snippet
, yas-visit-snippet-file
yas-choose-keys-first
If non-nil, prompt for snippet key first, then for template.
Otherwise prompts for all possible snippet names.
This affects yas-insert-snippet
and yas-visit-snippet-file
.
yas-fallback-behavior
How to act when yas-expand
does not expand a snippet.
call-other-command
means try to temporarily disable /YAS/nippet and call the next command bound to whatever key was used to invokeyas-expand
.- nil or the symbol
return-nil
mean do nothing. (andyas-expand
returns nil) - A Lisp form (apply COMMAND . ARGS) means interactively call COMMAND, if ARGS is non-nil, call COMMAND non-interactively with ARGS as arguments.
yas-triggers-in-field
If non-nil, allow stacked expansions (snippets inside snippets).
Otherwise yas-next-field-or-maybe-expand
just moves on to the
next field
yas-also-auto-indent-first-line
Non-nil means also auto indent first line according to mode.
Naturally this is only valid when yas-indent-line
is auto
yas-indent-line
Controls indenting applied to a recent snippet expansion.
The following values are possible:
fixed
Indent the snippet to the current column;auto
Indent each line of the snippet withindent-according-to-mode
Every other value means don't apply any snippet-side indentation after expansion (the manual per-line "$>" indentation still applies).
yas-prompt-functions
Functions to prompt for keys, templates, etc interactively.
These functions are called with the following arguments:
- PROMPT: A string to prompt the user
- CHOICES: a list of strings or objects.
- optional DISPLAY-FN : A function that, when applied to each of
the objects in CHOICES will return a string.
The return value of any function you put here should be one of the objects in CHOICES, properly formatted with DISPLAY-FN (if that is passed).
- To signal that your particular style of prompting is
unavailable at the moment, you can also have the function return nil.
- To signal that the user quit the prompting process, you can
signal quit
with
(signal 'quit "user quit!").
yas-snippet-dirs
()
Return yas-snippet-dirs
(which see) as a list.
Useful functions
yas-hippie-try-expand
(first-time?)
Integrate with hippie expand.
Just put this function in hippie-expand-try-functions-list
.
yas-define-condition-cache
(func doc &rest body)
Define a function FUNC with doc DOC and body BODY. BODY is executed at most once every snippet expansion attempt, to check expansion conditions.
It doesn't make any sense to call FUNC programatically.
yas-selected-text
()
Return yas-selected-text
if that exists and is non-empty, else nil.
yas-text
()
Return yas-text
if that exists and is non-empty, else nil.
yas-field-value
(number)
Get the string for field with NUMBER.
Use this in primary and mirror transformations to tget.
yas-verify-value
(possibilities)
Verify that the current field value is in POSSIBILITIES.
Otherwise throw exception.
yas-choose-value
(&rest possibilities)
Prompt for a string in POSSIBILITIES and return it.
The last element of POSSIBILITIES may be a list of strings.
yas-substr
(str pattern &optional subexp)
Search PATTERN in STR and return /SUBEXP/th match.
If found, the content of subexp group SUBEXP (default 0) is returned, or else the original STR will be returned.
yas-text
()
Return yas-text
if that exists and is non-empty, else nil.
yas-define-snippets
(mode snippets)
Define SNIPPETS for MODE.
SNIPPETS is a list of snippet definitions, each taking the following form
(KEY TEMPLATE NAME CONDITION GROUP EXPAND-ENV FILE KEYBINDING UUID)
Within these, only KEY and TEMPLATE are actually mandatory.
TEMPLATE might be a Lisp form or a string, depending on whether this is a snippet or a snippet-command.
CONDITION, EXPAND-ENV and KEYBINDING are Lisp forms, they have
been yas–read-lisp
-ed and will eventually be
yas–eval-lisp
-ed.
The remaining elements are strings.
FILE is probably of very little use if you're programatically defining snippets.
UUID is the snippets "unique-id". Loading a second snippet file with the same uuid replaced the previous snippet.
You can use yas–parse-template
to return such lists based on
the current buffers contents.
yas-expand-snippet
(content &optional start end expand-env)
Expand snippet CONTENT at current point.
Text between START and END will be deleted before inserting template. EXPAND-ENV is are let-style variable to value bindings considered when expanding the snippet.
yas-dropdown-prompt
(prompt choices &optional display-fn)
/WARNING/: no doc for symbol yas-dropdown-prompt
Useful variables
yas-dont-activate
If non-nil don't let yas-global-mode
affect some buffers.
If a function of zero arguments, then its result is used.
If a list of functions, then all functions must return nil to activate yas for this buffer.
In Emacsen <= 23, this variable is buffer-local. Because
yas-minor-mode-on
is called by yas-global-mode
after
executing the buffer's major mode hook, setting this variable
there is an effective way to define exceptions to the "global"
activation behaviour.
In Emacsen > 23, only the global value is used. To define
per-mode exceptions to the "global" activation behaviour, call
yas-minor-mode
with a negative argument directily in the major
mode's hook.
yas-buffer-local-condition
Snippet expanding condition.
This variable is a Lisp form which is evaluated every time a snippet expansion is attempted:
- If it evaluates to nil, no snippets can be expanded.
- If it evaluates to the a cons (require-snippet-condition
. REQUIREMENT)
- Snippets bearing no "# condition:" directive are not considered
- Snippets bearing conditions that evaluate to nil (or produce an error) won't be considered.
- If the snippet has a condition that evaluates to non-nil
RESULT:
- If REQUIREMENT is t, the snippet is considered
- If REQUIREMENT is
eq
RESULT, the snippet is considered - Otherwise, the snippet is not considered.
- If it evaluates to the symbol 'always, all snippets are considered for expansion, regardless of any conditions.
- If it evaluates to t or some other non-nil value
- Snippet bearing no conditions, or conditions that evaluate to non-nil, are considered for expansion.
- Otherwise, the snippet is not considered.
Here's an example preventing snippets from being expanded from
inside comments, in python-mode
only, with the exception of
snippets returning the symbol 'force-in-comment in their
conditions.
(add-hook 'python-mode-hook '(lambda () (setq yas-buffer-local-condition '(if (python-in-string/comment) '(require-snippet-condition . force-in-comment) t))))
The default value is similar, it filters out potential snippet
expansions inside comments and string literals, unless the
snippet itself contains a condition that returns the symbol
force-in-comment
.
yas-after-exit-snippet-hook
Hooks to run after a snippet exited.
The hooks will be run in an environment where some variables bound to proper values:
yas-snippet-beg
: The beginning of the region of the snippet.
yas-snippet-end
: Similar to beg.
Attention: These hooks are not run when exiting nested/stacked snippet expansion!
yas-key-syntaxes
List of character syntaxes used to find a trigger key before point. The list is tried in the order while scanning characters backwards from point. For example, if the list is '("w" "w_") first look for trigger keys which are composed exclusively of "word"-syntax characters, and then, if that fails, look for keys which are either of "word" or "symbol" syntax. Triggering after
foo-bar
will, according to the "w" element first try "bar". If that isn't a trigger key, "foo-bar" is tried, respecting a second "w_" element.
yas-verbosity
Log level for yas–message
4 means trace most anything, 0 means nothing.