5 .. _Organizing Snippets: snippet-organization.html
6 .. _Expanding Snippets: snippet-expansion.html
7 .. _Writing Snippets: snippet-development.html
8 .. _The YASnippet Menu: snippet-menu.html
15 Snippet definitions are stored in files in the filesystem. Unless you
16 use the simpler `bundle version <index.html@installation>`_), these
17 are arranged so that YASnippet can load them into *snippet
18 tables*. The triggering mechanisms (see `Expanding snippets`_) will
19 look up these snippet tables and (hopefully) expand the snippet you
22 The non-bundle version of YASnippet, once unpacked, comes with a full
23 directory of snippets, which you can copy somewhere and use. You can
24 also create or download more directories.
26 Once these directories are in place reference them in the variable
27 ``yas/root-directory`` and load them with ``yas/load-directory``:
29 .. sourcecode:: common-lisp
31 ;; Develop and keep personal snippets under ~/emacs.d/mysnippets
32 (setq yas/root-directory "~/emacs.d/mysnippets")
35 (yas/load-directory yas/root-directory)
37 The point in using ``yas/root-directory`` (as opposed to calling
38 ``yas/load-directory`` directly) is considering "~/emacs.d/mysnippets"
39 for snippet development, so you can use commands like
40 ``yas/new-snippet`` and others described in section `Writing
43 You can make this variable a list and store more items into it:
45 .. sourcecode:: common-lisp
47 ;; Develop in ~/emacs.d/mysnippets, but also
48 ;; try out snippets in ~/Downloads/interesting-snippets
49 (setq yas/root-directory '("~/emacs.d/mysnippets"
50 "~/Downloads/interesting-snippets"))
52 ;; Map `yas/load-directory' to every element
53 (mapc 'yas/load-directory yas/root-directory)
55 In this last example, the all the directories are loaded and their
56 snippets considered for expansion. However development still happens
57 in the first element, "~/emacs.d/mysnippets".
62 Once you've setup ``yas/root-directory`` , you can store snippets
63 inside sub-directories of these directories.
65 Snippet definitions are put in plain text files. They are arranged
66 by sub-directories, and the snippet tables are named after these
69 The name corresponds to the Emacs mode where you want expansion to
70 take place. For example, snippets for ``c-mode`` are put in the
71 ``c-mode`` sub-directory.
73 The ``.yas.parents`` file
74 -------------------------
76 It's very useful to have certain modes share snippets between
77 themselves. To do this, choose a mode subdirectory and place a
78 ``.yas-parents`` containing a whitespace-separated list of other
79 mode names. When you reload those modes become parents of the
87 | |-- .yas-parents # contains "cc-mode text-mode"
93 | |-- .yas-parents # contains "cc-mode text-mode"
99 The ``.yas-make-groups`` file
100 -----------------------------
102 .. image:: images/menu-groups.png
105 If you place an empty plain text file ``.yas-make-groups`` inside one
106 of the mode directories, the names of these sub-directories are
107 considered groups of snippets and `The YASnippet Menu`_ is organized
108 much more cleanly, as you can see in the image.
110 Another alternative way to achieve this is to place a ``# group:``
111 directive inside the snippet definition. See `Writing Snippets`_.
121 |-- control structure
133 The most convenient way to define snippets for YASnippet is to put
134 them in a directory arranged by the mode and use
135 ``yas/load-directory`` to load them.
137 However, this might slow down the Emacs start-up speed if you have many
138 snippets. You can use ``yas/define-snippets`` to define a bunch of
139 snippets for a particular mode in an Emacs-lisp file.
141 Since this is hard to maintain, there's a better way: define your
142 snippets in directory and then call ``M-x yas/compile-bundle`` to
143 compile it into a bundle file when you modified your snippets.
145 The release bundle of YASnippet is produced by
146 ``yas/compile-bundle``. The bundle uses ``yas/define-snippets`` to
147 define snippets. This avoids the IO and parsing overhead when loading
150 Further more, the generated bundle is a stand-alone file not depending
151 on ``yasnippet.el``. The released bundles of YASnippet are all
154 See the internal documentation for these functions
156 * ``M-x describe-function RET yas/define-snippets RET``
157 * ``M-x describe-function RET yas/compile-bundle RET``.
159 Customizable variables
160 ======================
162 ``yas/root-directory``
163 ----------------------
165 Root directory that stores the snippets for each major mode.
167 If you set this from your .emacs, can also be a list of strings,
168 for multiple root directories. If you make this a list, the first
169 element is always the user-created snippets directory. Other
170 directories are used for bulk reloading of all snippets using
173 ``yas/ignore-filenames-as-triggers``
174 ------------------------------------
176 If non-nil, don't derive tab triggers from filenames.
178 This means a snippet without a ``# key:`` directive wont have a tab
181 .. LocalWords: html YASnippet filesystem yas sourcecode setq mapc printf perl
182 .. LocalWords: println cperl forin filenames filename ERb's yasnippet Avar el
183 .. LocalWords: rjs RET