ya-snippet.org
Table of Contents
yasnippet on the Github
Writing snippets
Template syntax
Plain Text
Arbitrary text can be included as the content of a template. They are usually interpreted as plain text, except $ and `. You need to use \ to escape them: \$ and \`. The \ itself may also needed to be escaped as \\ sometimes.
Embedded Emacs-lisp code
Emacs-Lisp code can be embedded inside the template, written inside back-quotes (`). The lisp forms are evaluated when the snippet is being expanded. The evaluation is done in the same buffer as the snippet being expanded.
Here's an example for c-mode to calculate the header file guard dynamically:
#ifndef ${1:_`(upcase (file-name-nondirectory (file-name-sans-extension (buffer-file-name))))`_H_} #define $1 $0 #endif /* $1 */
Tab step fields
Placeholder fields
Mirrors
We refer the tab stops with placeholders as a field. A field can have mirrors. Its mirrors will get updated when you change the text of a field.
Post by: Jalen Wang (转载请注明出处)