diff --git a/doc/define_snippet.rst b/doc/define_snippet.rst index 9a98cdb..1eee201 100644 --- a/doc/define_snippet.rst +++ b/doc/define_snippet.rst @@ -176,8 +176,18 @@ Meta data are specified in the syntax of #data-name : data value Any other text above ``# --`` is considered as comment and -ignored. You might want to refer to the list of currently `supported -meta data`_ . +ignored. Here's a list of currently supported meta data: + +* ``name``: The name of the snippet. This is a one-line description of + the snippet. It will be displayed in the menu. So it's a good idea + to select a descriptive name fo a snippet -- especially + distinguishable among similar snippets. +* ``contributor``: The contributor of the snippet. +* ``condition``: The condition of the snippet. This is a piece of + elisp code. If a snippet has a condition, then it will only be + expanded when the condition code evaluate to some non-nil value. + + Define snippets using elisp code -------------------------------- @@ -561,16 +571,152 @@ also indicate where to insert and expand the ``template``. The Syntax of the Template ========================== -.. _supported meta data: +The syntax of the snippet template is simple but powerful, very +similar to TextMate's. -* ``name``: The name of the snippet. This is a one-line description of - the snippet. It will be displayed in the menu. So it's a good idea - to select a descriptive name fo a snippet -- especially - distinguishable among similar snippets. -* ``contributor``: The contributor of the snippet. -* ``condition``: The condition of the snippet. This is a piece of - elisp code. If a snippet has a condition, then it will only be - expanded when the condition code evaluate to some non-nil value. +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 elisp code +------------------- + +Elisp code can be embedded inside the template. They are written +inside back-quotes (`````): + +They 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: + +.. sourcecode:: text + + #ifndef ${1:_`(upcase (file-name-nondirectory (file-name-sans-extension (buffer-file-name))))`_H_} + #define $1 + + $0 + + #endif /* $1 */ + +Tab Stops +--------- + +Tab stops are fields that you can navigate back and forth by ``TAB`` +and ``S-TAB`` [3]_. They are written by ``$`` followed with a +number. ``$0`` has the special meaning of the *exit point* of a +snippet. That is the last place to go when you've traveled all the +fields. Here's a typical example: + +.. sourcecode:: text + +