]> code.delx.au - gnu-emacs-elpa/blob - doc/manual.org
84746e9c87b707b21a319b7d29ded7fadd1cb8a4
[gnu-emacs-elpa] / doc / manual.org
1 # -*- mode: org; fill-column: 80 -*-
2 #+TITLE: Yet another snippet extension
3 #+OPTIONS: toc:1
4 #+STARTUP: showall
5
6 #+STYLE: <link rel="stylesheet" type="text/css" href="assets/stylesheet.css" />
7
8 # External links
9 #
10 #+LINK: smart-snippet http://code.google.com/p/smart-snippet
11 #+LINK: pluskid http://pluskid.lifegoo.org
12
13
14 #+LINK: screencast http://www.youtube.com/watch?v=ZCGmZK4V7Sg
15 #+LINK: docs http://capitaomorte.github.com/yasnippet
16 #+LINK: issues https://github.com/capitaomorte/yasnippet/issues
17 #+LINK: googlecode-tracker http://code.google.com/p/yasnippet/issues/list
18 #+LINK: forum http://groups.google.com/group/smart-snippet
19
20
21 # Internal links
22
23 .. _Organizing Snippets: snippet-organization.html
24 .. _Expanding Snippets: snippet-expansion.html
25 .. _Writing Snippets: snippet-development.html
26 .. _The YASnippet Menu: snippet-menu.html
27
28 *YASnippet* is a template system for Emacs. It allows you to type an
29 abbreviation and automatically expand it into function templates. Bundled
30 language templates includes: C, C++, C#, Perl, Python, Ruby, SQL, LaTeX, HTML,
31 CSS and more. The snippet syntax is inspired from TextMate's syntax, you can
32 even [[#import-textmate][import most TextMate snippets]]
33
34 YASnippet is an original creation of [[pluskid]] who also wrote its predecessor
35 [[smart-snippet]].
36
37 * Quick start
38
39 ** Watch a demo [[screencast]]
40
41 *YASnippet* is a template system for Emacs. It allows you to type an
42
43 ** Install the most recent version with git
44
45 Clone this repository somewhere
46
47 $ cd ~/.emacs.d/plugins
48 $ git clone https://github.com/capitaomorte/yasnippet
49
50 Add the following in your =.emacs= file:
51
52 example
53 (add-to-list 'load-path
54 "~/.emacs.d/plugins/yasnippet")
55 (require 'yasnippet)
56 (yas/global-mode 1)
57
58 Add your own snippets to `~/.emacs.d/snippets` by placing files there or invoking `yas/new-snippet`.
59
60 ## Install yasnippet with el-get
61
62 El-get is a nice way to get the most recent version, too
63
64 ** Import textmate snippets (rails example)
65 :PROPERTIES:
66 :CUSTOM_ID: import-textmate
67 :END:
68
69 Clone the yasnippet repository to `~/.emacs.d/plugins/yasnippet`
70
71 cd ~/.emacs.d/plugins/yasnippet
72 git submodule init
73 git submodule update
74 gem install plist trollop
75 rake convert_bundles # will convert ruby, rails and html bundles from drnic
76
77 Then, in your .emacs file
78
79 (add-to-list 'load-path
80 "~/.emacs.d/plugins/yasnippet")
81 (require 'yasnippet)
82 (setq yas/snippet-dirs '("~/.emacs.d/snippets" "~/.emacs.d/extras/imported"))
83 (yas/global-mode 1)
84
85 Open some rails file (model, app, etc) and start using the textmate snippets.
86
87 ** Contributing snippets
88
89 Please do not ask me to add snippets to the default collection under
90 =/snippets=. This is considered frozen and by customizing =yas/snippet-dirs= you
91 can point yasnippet to good snippet collections out there.
92
93 The =extras/textmate-import.rb= tool can import many actual Textmate
94 snippets. See [[import-textmate]].
95
96 I'm focusing on developping =textmate-import.rb= tool and the =yas-setup.el=
97 files that guide it with more difficult importation. In the future =/snippets=
98 snippets will be deprecated and replaced with =extras/imported=.
99
100 ** Documentation, issues, etc
101
102 Please refer to the comprehensive [[docs][documentation]] for full customization and
103 support. If you think you've found a bug, please report it on [[issues][the GitHub issue
104 tracker]]. (please **do not** submit new issues to the old [[googlecode-tracker][googlecode tracker]])
105
106 If you run into problems using YASnippet, or have snippets to contribute, post
107 to the [[forum][yasnippet forum]]. Thank you very much for using YASnippet!
108
109 * Organizing snippets
110 ** Setting up =yas/snippet-dirs= before calling =yas/global-mode=
111
112 Snippet collections are stored in specially organized file hierarchies. These
113 are loaded by YASnippet into *snippet tables* which the triggering mechanism
114 (see [[expand-snippets][Expanding snippets]]) looks up and (hopefully) cause the right snippet to be
115 expanded for you.
116
117 An emacs variable =yas/snippet-dirs= tells YASnippet which collections to
118 consider.
119
120 If you don't tweak it the default value of =yas/snippet-dirs= considers:
121
122 - a personal collection that YASnippet decides lives in =~/.emacs.d/snippets=
123 - the bundled collection, taken as a relative path to =yasnippet.el= localtion
124
125 You might and probably want to try out more snippet collections though:
126
127 #+begin_src emacs-lisp :exports both
128 ;; Develop in ~/emacs.d/mysnippets, but also
129 ;; try out snippets in ~/Downloads/interesting-snippets
130 (setq yas/snippet-dirs '("~/emacs.d/mysnippets"
131 "~/Downloads/interesting-snippets"))
132
133 ;; OR, keeping yasnippet's defaults try out ~/Downloads/interesting-snippets
134 (setq yas/snippet-dirs (append yas/snippet-dirs
135 '("~/Downloads/interesting-snippets")))
136 #+end_src
137
138 Collections appearing earlier in the list shadow any conflicting snippets from
139 collections later in the list. =yas/new-snippet= always stores snippets in the
140 first collection.
141
142 # Snippet definitions are put in plain text files. They are arranged
143 # by sub-directories, and the snippet tables are named after these
144 # directories.
145
146 # The name corresponds to the Emacs mode where you want expansion to
147 # take place. For example, snippets for ``c-mode`` are put in the
148 # ``c-mode`` sub-directory.
149
150
151
152 # 2. `Expanding Snippets`_
153
154 # Describes how YASnippet chooses snippets for expansion at point.
155
156 # Maybe, you'll want some snippets to be expanded in a particular
157 # mode, or only under certain conditions, or be prompted using
158 # ``ido``, etc...
159
160 # 3. `Writing Snippets`_
161
162 # Describes the YASnippet definition syntax, which is very close (but
163 # not equivalent) to Textmate's. Includes a section about converting
164 # TextMate snippets.
165
166 # 4. `The YASnippet menu`_
167
168 # Explains how to use the YASnippet menu to explore, learn and modify
169 # snippets.
170
171
172
173 # Loading snippets
174 # ================
175
176
177
178 # Organizing snippets
179 # ===================
180
181 # Once you've setup ``yas/root-directory`` , you can store snippets
182 # inside sub-directories of these directories.
183
184
185
186 # The ``.yas.parents`` file
187 # -------------------------
188
189 # It's very useful to have certain modes share snippets between
190 # themselves. To do this, choose a mode subdirectory and place a
191 # ``.yas-parents`` containing a whitespace-separated list of other
192 # mode names. When you reload those modes become parents of the
193 # original mode.
194
195 # .. sourcecode:: text
196
197 # $ tree
198 # .
199 # |-- c-mode
200 # | |-- .yas-parents # contains "cc-mode text-mode"
201 # | `-- printf
202 # |-- cc-mode
203 # | |-- for
204 # | `-- while
205 # |-- java-mode
206 # | |-- .yas-parents # contains "cc-mode text-mode"
207 # | `-- println
208 # `-- text-mode
209 # |-- email
210 # `-- time
211
212 # The ``.yas-make-groups`` file
213 # -----------------------------
214
215 # .. image:: images/menu-groups.png
216 # :align: right
217
218 # If you place an empty plain text file ``.yas-make-groups`` inside one
219 # of the mode directories, the names of these sub-directories are
220 # considered groups of snippets and `The YASnippet Menu`_ is organized
221 # much more cleanly, as you can see in the image.
222
223 # Another alternative way to achieve this is to place a ``# group:``
224 # directive inside the snippet definition. See `Writing Snippets`_.
225
226 # .. sourcecode:: text
227
228 # $ tree ruby-mode/
229 # ruby-mode/
230 # |-- .yas-make-groups
231 # |-- collections
232 # | |-- each
233 # | `-- ...
234 # |-- control structure
235 # | |-- forin
236 # | `-- ...
237 # |-- definitions
238 # | `-- ...
239 # `-- general
240 # `-- ...
241
242
243 # YASnippet bundle
244 # ================
245
246 # The most convenient way to define snippets for YASnippet is to put
247 # them in a directory arranged by the mode and use
248 # ``yas/load-directory`` to load them.
249
250 # However, this might slow down the Emacs start-up speed if you have many
251 # snippets. You can use ``yas/define-snippets`` to define a bunch of
252 # snippets for a particular mode in an Emacs-lisp file.
253
254 # Since this is hard to maintain, there's a better way: define your
255 # snippets in directory and then call ``M-x yas/compile-bundle`` to
256 # compile it into a bundle file when you modified your snippets.
257
258 # The release bundle of YASnippet is produced by
259 # ``yas/compile-bundle``. The bundle uses ``yas/define-snippets`` to
260 # define snippets. This avoids the IO and parsing overhead when loading
261 # snippets.
262
263 # Further more, the generated bundle is a stand-alone file not depending
264 # on ``yasnippet.el``. The released bundles of YASnippet are all
265 # generated this way.
266
267 # See the internal documentation for these functions
268
269 # \* ``M-x describe-function RET yas/define-snippets RET``
270 # \* ``M-x describe-function RET yas/compile-bundle RET``.
271
272 # Customizable variables
273 # ======================
274
275 # ``yas/root-directory``
276 # ----------------------
277
278 # Root directory that stores the snippets for each major mode.
279
280 # If you set this from your .emacs, can also be a list of strings,
281 # for multiple root directories. If you make this a list, the first
282 # element is always the user-created snippets directory. Other
283 # directories are used for bulk reloading of all snippets using
284 # ``yas/reload-all``
285
286 # ``yas/ignore-filenames-as-triggers``
287 # ------------------------------------
288
289 # If non-nil, don't derive tab triggers from filenames.
290
291 # This means a snippet without a ``# key:`` directive wont have a tab
292 # trigger.
293
294 # .. LocalWords: html YASnippet filesystem yas sourcecode setq mapc printf perl
295 # .. LocalWords: println cperl forin filenames filename ERb's yasnippet Avar el
296 # .. LocalWords: rjs RET
297
298 # * snippet-expansion.org
299 # ==================
300 # Expanding snippets
301 # ==================
302
303 # .. _Organizing Snippets: snippet-organization.html
304 # .. _Expanding Snippets: snippet-expansion.html
305 # .. _Writing Snippets: snippet-development.html
306 # .. _The YASnippet Menu: snippet-menu.html
307
308 # .. contents::
309
310
311 # Triggering expansion
312 # ====================
313
314 # You can use YASnippet to expand snippets in different ways:
315
316 # \* By typing an abbrev, the snippet *trigger key*, and then pressing
317 # the key defined in ``yas/trigger-key`` (which defaults to
318 # "TAB"). This works in buffers where the minor mode
319 # ``yas/minor-mode`` is active;
320
321 # \* By invoking the command ``yas/insert-snippet`` (either by typing
322 # ``M-x yas/insert-snippet`` or its keybinding). This does *not*
323 # require ``yas/minor-mode`` to be active.
324
325 # \* By using the keybinding associated with an active snippet. This also
326 # requires ``yas/minor-mode`` to be active;
327
328 # \* By expanding directly from the "YASnippet" menu in the menu-bar
329
330 # \* By using hippie-expand
331
332 # \* Expanding from emacs-lisp code
333
334 # Trigger key
335 # -----------
336
337 # When ``yas/minor-mode`` is enabled, the keybinding taken from
338 # ``yas/trigger-key`` will take effect.
339
340 # ``yas/trigger-key`` invokes ``yas/expand``, which tries to expand a
341 # \*snippet abbrev* (also known as *snippet key*) before point.
342
343 # The default key is ``"TAB"``, however, you can freely set it to some
344 # other key.
345
346 # .. image:: images/minor-mode-indicator.png
347 # :align: left
348
349 # To enable the YASnippet minor mode in all buffers globally use the
350 # command ``yas/global-mode``.
351
352 # When you use ``yas/global-mode`` you can also selectively disable
353 # YASnippet in some buffers by setting the buffer-local variable
354 # ``yas/dont-active`` in the buffer's mode hook.
355
356 # Trouble when using or understanding the ``yas/trigger-key`` is easily
357 # the most controversial issue in YASsnippet. See the `FAQ <faq.html>`_.
358
359 # Fallback bahaviour
360 # ~~~~~~~~~~~~~~~~~~
361
362 # ``yas/fallback-behaviour`` is a customization variable bound to
363 # ``'call-other-command`` by default. If ``yas/expand`` failed to find
364 # any suitable snippet to expand, it will disable the minor mode
365 # temporarily and find if there's any other command bound the
366 # ``yas/trigger-key``.
367
368 # If found, the command will be called. Usually this works very well --
369 # when there's a snippet, expand it, otherwise, call whatever command
370 # originally bind to the trigger key.
371
372 # However, you can change this behavior by customizing the
373 # ``yas/fallback-behavior`` variable. If you set this variable to
374 # ``'return-nil``, it will return ``nil`` instead of trying to call the
375 # \*original* command when no snippet is found.
376
377 # Insert at point
378 # ---------------
379
380 # The command ``M-x yas/insert-snippet`` lets you insert snippets at
381 # point *for you current major mode*. It prompts you for the snippet
382 # key first, and then for a snippet template if more than one template
383 # exists for the same key.
384
385 # The list presented contains the snippets that can be inserted at
386 # point, according to the condition system. If you want to see all
387 # applicable snippets for the major mode, prefix this command with
388 # ``C-u``.
389
390 # The prompting methods used are again controlled by
391 # ``yas/prompt-functions``.
392
393 # Snippet keybinding
394 # ------------------
395
396 # See the section of the ``# binding:`` directive in `Writing
397 # Snippets`_.
398
399
400 # Expanding from the menu
401 # -----------------------
402
403 # See `the YASnippet Menu`_.
404
405 # Expanding with ``hippie-expand``
406 # ----------------------------------
407
408 # To integrate with ``hippie-expand``, just put
409 # ``yas/hippie-try-expand`` in
410 # ``hippie-expand-try-functions-list``. This probably makes more sense
411 # when placed at the top of the list, but it can be put anywhere you
412 # prefer.
413
414 # Expanding from emacs-lisp code
415 # ------------------------------
416
417 # Sometimes you might want to expand a snippet directly from you own
418 # elisp code. You should call ``yas/expand-snippet`` instead of
419 # ``yas/expand`` in this case.
420
421 # As with expanding from the menubar, the condition system and multiple
422 # candidates doesn't affect expansion. In fact, expanding from the
423 # YASnippet menu has the same effect of evaluating the follow code:
424
425 # .. sourcecode:: common-lisp
426
427 # (yas/expand-snippet template)
428
429 # See the internal documentation on ``yas/expand-snippet`` for more
430 # information.
431
432 # Controlling expansion
433 # =====================
434
435 # Eligible snippets
436 # -----------------
437
438 # YASnippet does quite a bit of filtering to find out which snippets are
439 # eligible for expanding at the current cursor position.
440
441 # In particular, the following things matter:
442
443 # \* Currently loaded snippets tables
444
445 # These are loaded from a directory hierarchy in your file system. See
446 # `Organizing Snippets`_. They are named after major modes like
447 # ``html-mode``, ``ruby-mode``, etc...
448
449 # \* Major mode of the current buffer
450
451 # If the currrent major mode matches one of the loaded snippet tables,
452 # then all that table's snippets are considered for expansion. Use
453 # ``M-x describe-variable RET major-mode RET`` to find out which major
454 # mode you are in currently.
455
456 # \* Parent tables
457
458 # Snippet tables defined as the parent of some other eligible table
459 # are also considered. This works recursively, i.e. parents of parents
460 # of eligible tables are also considered.
461
462 # \* Buffer-local ``yas/mode-symbol`` variable
463
464 # This can be used to consider snippet tables whose name does not
465 # correspond to a major mode. If you set this variable to a name ,
466 # like ``rinari-minor-mode``, you can have some snippets expand only
467 # in that minor mode. Naturally, you want to set this conditionally,
468 # i.e. only when entering that minor mode, so using a hook is a good
469 # idea.
470
471 # .. sourcecode:: common-lisp
472
473 # ;; When entering rinari-minor-mode, consider also the snippets in the
474 # ;; snippet table "rails-mode"
475 # (add-hook 'rinari-minor-mode-hook
476 # #'(lambda ()
477 # (setq yas/mode-symbol 'rails-mode)))
478
479 # \* Buffer-local ``yas/buffer-local-condition`` variable
480
481 # This variable provides finer grained control over what snippets can
482 # be expanded in the current buffer. The default value won't let you
483 # expand snippets inside comments or string literals for example. See
484 # `The condition system`_ for more info.
485
486 # The condition system
487 # --------------------
488
489 # Consider this scenario: you are an old Emacs hacker. You like the
490 # abbrev-way and set ``yas/trigger-key`` to ``"SPC"``. However,
491 # you don't want ``if`` to be expanded as a snippet when you are typing
492 # in a comment block or a string (e.g. in ``python-mode``).
493
494 # If you use the ``# condition :`` directive (see `Writing Snippets`_)
495 # you could just specify the condition for ``if`` to be ``(not
496 # (python-in-string/comment))``. But how about ``while``, ``for``,
497 # etc. ? Writing the same condition for all the snippets is just
498 # boring. So has a buffer local variable
499 # ``yas/buffer-local-condition``. You can set this variable to ``(not
500 # (python-in-string/comment))`` in ``python-mode-hook``.
501
502 # Then, what if you really want some particular snippet to expand even
503 # inside a comment? This is also possible! But let's stop telling the
504 # story and look at the rules:
505
506 # \* If ``yas/buffer-local-condition`` evaluate to nil, no snippets will
507 # be considered for expansion.
508
509 # \* If it evaluates to the a *cons cell* where the ``car`` is the symbol
510 # ``require-snippet-condition`` and the ``cdr`` is a symbol (let's
511 # call it ``requirement``), then:
512
513 # * Snippets having no ``# condition:`` directive won't be considered;
514
515 # * Snippets with conditions that evaluate to nil (or produce an
516 # error) won't be considered;
517
518 # * If the snippet has a condition that evaluates to non-nil (let's
519 # call it ``result``):
520
521 # * If ``requirement`` is ``t``, the snippet is ready to be
522 # expanded;
523
524 # * If ``requirement`` is ``eq`` to ``result``, the snippet is ready
525 # to be expanded;
526
527 # * Otherwise the snippet won't be considered.
528
529 # \* If it evaluates to the symbol ``always``, all snippets are
530 # considered for expansion, regardless of any conditions.
531
532 # \* If it evaluate to ``t`` or some other non-nil value:
533
534 # * If the snippet has no condition, or has a condition that evaluate
535 # to non-nil, it is ready to be expanded.
536
537 # * Otherwise, it won't be considered.
538
539 # In the mentioned scenario, set ``yas/buffer-local-condition`` like
540 # this
541
542 # .. sourcecode:: common-lisp
543
544 # (add-hook 'python-mode-hook
545 # '(lambda ()
546 # (setq yas/buffer-local-condition
547 # '(if (python-in-string/comment)
548 # '(require-snippet-condition . force-in-comment)
549 # t))))
550
551 # ... and specify the condition for a snippet that you're going to
552 # expand in comment to be evaluated to the symbol
553 # ``force-in-comment``. Then it can be expanded as you expected, while
554 # other snippets like ``if`` still can't expanded in comment.
555
556 # Multiples snippet with the same key
557 # -----------------------------------
558
559 # The rules outlined `above <Eligible snippets>`_ can return more than
560 # one snippet to be expanded at point.
561
562 # When there are multiple candidates, YASnippet will let you select
563 # one. The UI for selecting multiple candidate can be customized through
564 # ``yas/prompt-functions`` , which defines your preferred methods of
565 # being prompted for snippets.
566
567 # You can customize it with ``M-x customize-variable RET
568 # yas/prompt-functions RET``. Alternatively you can put in your
569 # emacs-file:
570
571 # .. sourcecode:: common-lisp
572
573 # (setq yas/prompt-functions '(yas/x-prompt yas/dropdown-prompt))
574
575 # Currently there are some alternatives solution with YASnippet.
576
577 # .. image:: images/x-menu.png
578 # :align: right
579
580 # Use the X window system
581 # ~~~~~~~~~~~~~~~~~~~~~~~
582
583 # The function ``yas/x-prompt`` can be used to show a popup menu for you
584 # to select. This menu will be part of you native window system widget,
585 # which means:
586
587 # \* It usually looks beautiful. E.g. when you compile Emacs with gtk
588 # support, this menu will be rendered with your gtk theme.
589 # \* Your window system may or may not allow to you use ``C-n``, ``C-p``
590 # to navigate this menu.
591 # \* This function can't be used when in a terminal.
592
593 # .. image:: images/ido-menu.png
594 # :align: right
595
596 # Minibuffer prompting
597 # ~~~~~~~~~~~~~~~~~~~~
598
599 # You can use functions ``yas/completing-prompt`` for the classic emacs
600 # completion method or ``yas/ido-prompt`` for a much nicer looking
601 # method. The best way is to try it. This works in a terminal.
602
603 # .. image:: images/dropdown-menu.png
604 # :align: right
605
606 # Use ``dropdown-menu.el``
607 # ~~~~~~~~~~~~~~~~~~~~~~~~
608
609 # The function ``yas/dropdown-prompt`` can also be placed in the
610 # ``yas/prompt-functions`` list.
611
612 # This works in both window system and terminal and is customizable, you
613 # can use ``C-n``, ``C-p`` to navigate, ``q`` to quit and even press
614 # ``6`` as a shortcut to select the 6th candidate.
615
616 # Roll your own
617 # ~~~~~~~~~~~~~
618
619 # See below for the documentation on variable ``yas/prompt-functions``
620
621 # Customizable Variables
622 # ======================
623
624 # ``yas/prompt-functions``
625 # ------------------------
626
627 # You can write a function and add it to the ``yas/prompt-functions``
628 # list. These functions are called with the following arguments:
629
630 # \* PROMPT: A string to prompt the user;
631
632 # \* CHOICES: A list of strings or objects;
633
634 # \* optional DISPLAY-FN : A function. When applied to each of the
635 # objects in CHOICES it will return a string;
636
637 # The return value of any function you put here should be one of
638 # the objects in CHOICES, properly formatted with DISPLAY-FN (if
639 # that is passed).
640
641 # \* To signal that your particular style of prompting is unavailable at
642 # the moment, you can also have the function return nil.
643
644 # \* To signal that the user quit the prompting process, you can signal
645 # ``quit`` with ``(signal 'quit "user quit!")``
646
647 # ``yas/fallback-behavior``
648 # -------------------------
649
650 # How to act when ``yas/expand`` does *not* expand a snippet.
651
652 # ``call-other-command`` means try to temporarily disable YASnippet and
653 # call the next command bound to ``yas/trigger-key``.
654
655 # ``return-nil`` means return nil. (i.e. do nothing)
656
657 # An entry (apply COMMAND . ARGS) means interactively call COMMAND, if
658 # ARGS is non-nil, call COMMAND non-interactively with ARGS as
659 # arguments.
660
661 # ``yas/choose-keys-first``
662 # -------------------------
663
664 # If non-nil, prompt for snippet key first, then for template.
665
666 # Otherwise prompts for all possible snippet names.
667
668 # This affects ``yas/insert-snippet`` and ``yas/visit-snippet-file``.
669
670 # ``yas/choose-tables-first``
671 # ---------------------------
672
673 # If non-nil, and multiple eligible snippet tables, prompts user for
674 # tables first.
675
676 # Otherwise, user chooses between the merging together of all
677 # eligible tables.
678
679 # This affects ``yas/insert-snippet``, ``yas/visit-snippet-file``
680
681 # ``yas/key-syntaxes``
682 # --------------------
683
684 # The default searching strategy is quite powerful. For example, in
685 # ``c-mode``, ``bar``, ``foo_bar``, ``"#foo_bar"`` can all be recognized
686 # as a snippet key. Furthermore, the searching is in that order. In
687 # other words, if ``bar`` is found to be a key to some *valid* snippet,
688 # then that snippet is expanded and replaces the ``bar``. Snippets
689 # pointed to by ``foo_bar`` and ``"#foobar`` won't be considered.
690
691 # However, this strategy can also be customized easily from the
692 # ``yas/key-syntaxes`` variable. It is a list of syntax rules, the
693 # default value is ``("w" "w_" "w_." "^ ")``. Which means search the
694 # following thing until found one:
695
696 # \* a word.
697 # \* a symbol. In lisp, ``-`` and ``?`` can all be part of a symbol.
698 # \* a sequence of characters of either word, symbol or punctuation.
699 # \* a sequence of characters of non-whitespace characters.
700
701 # But you'd better keep the default value unless you want to understand
702 # how Emacs's syntax rules work...
703
704
705
706 # * snippet-development.org
707 # ================
708 # Writing snippets
709 # ================
710
711 # .. _Organizing Snippets: snippet-organization.html
712 # .. _Expanding Snippets: snippet-expansion.html
713 # .. _Writing Snippets: snippet-development.html
714 # .. _The YASnippet Menu: snippet-menu.html
715
716 # .. contents::
717
718 # Snippet development
719 # ===================
720
721 # Quickly finding snippets
722 # ------------------------
723
724 # There are some ways you can quickly find a snippet file:
725
726 # \* ``M-x yas/new-snippet``
727
728 # Prompts you for a snippet name, then tries to guess a suitable
729 # directory to store it, prompting you for creation if it does not
730 # exist. Finally, places you in a new buffer set to ``snippet-mode``
731 # so you can write your snippet.
732
733 # \* ``M-x yas/find-snippets``
734
735 # Lets you find the snippet file in the directory the snippet was
736 # loaded from (if it exists) like ``find-file-other-window``. The
737 # directory searching logic is similar to ``M-x yas/new-snippet``.
738
739 # \* ``M-x yas/visit-snippet-file``
740
741 # Prompts you for possible snippet expansions like
742 # ``yas/insert-snippet``, but instead of expanding it, takes you
743 # directly to the snippet definition's file, if it exists.
744
745 # Once you find this file it will be set to ``snippet-mode`` (see ahead)
746 # and you can start editing your snippet.
747
748
749 # Using the ``snippet-mode`` major mode
750 # -------------------------------------
751
752 # There is a major mode ``snippet-mode`` to edit snippets. You can set
753 # the buffer to this mode with ``M-x snippet-mode``. It provides
754 # reasonably useful syntax highlighting.
755
756 # Two commands are defined in this mode:
757
758 # \* ``M-x yas/load-snippet-buffer``
759
760 # When editing a snippet, this loads the snippet into the correct
761 # mode and menu. Bound to ``C-c C-c`` by default while in
762 # ``snippet-mode``.
763
764 # \* ``M-x yas/tryout-snippet``
765
766 # When editing a snippet, this opens a new empty buffer, sets it to
767 # the appropriate major mode and inserts the snippet there, so you
768 # can see what it looks like. This is bound to ``C-c C-t`` while in
769 # ``snippet-mode``.
770
771 # There are also *snippets for writing snippets*: ``vars``, ``$f`` and
772 # ``$m`` :-).
773
774 # File content
775 # ============
776
777 # A file defining a snippet generally contains the template to be
778 # expanded.
779
780 # Optionally, if the file contains a line of ``# --``, the lines above
781 # it count as comments, some of which can be *directives* (or meta
782 # data). Snippet directives look like ``# property: value`` and tweak
783 # certain snippets properties described below. If no ``# --`` is found,
784 # the whole file is considered the snippet template.
785
786 # Here's a typical example:
787
788 # .. sourcecode:: text
789
790 # # contributor: pluskid <pluskid@gmail.com>
791 # # name: __...__
792 # # --
793 # __${init}__
794
795 # Here's a list of currently supported directives:
796
797 # ``# key:`` snippet abbrev
798 # --------------------------
799
800 # This is the probably the most important directive, it's the abbreviation you
801 # type to expand a snippet just before hitting ``yas/trigger-key``. If you don't
802 # specify this the snippet will not be expandable through the key mechanism.
803
804 # ``# name:`` snippet name
805 # ------------------------
806
807 # This is a one-line description of the snippet. It will be displayed in
808 # the menu. It's a good idea to select a descriptive name for a
809 # snippet -- especially distinguishable among similar snippets.
810
811 # If you omit this name it will default to the file name the snippet was
812 # loaded from.
813
814 # ``# condition:`` snippet condition
815 # ----------------------------------
816 # This is a piece of Emacs-lisp code. If a snippet has a condition, then it
817 # will only be expanded when the condition code evaluate to some non-nil
818 # value.
819
820 # See also ``yas/buffer-local-condition`` in `Expanding snippets`_
821
822
823 # ``# group:`` snippet menu grouping
824 # ----------------------------------
825
826 # When expanding/visiting snippets from the menu-bar menu, snippets for a
827 # given mode can be grouped into sub-menus . This is useful if one has
828 # too many snippets for a mode which will make the menu too
829 # long.
830
831 # The ``# group:`` property only affect menu construction (See `the
832 # YASnippet menu`_) and the same effect can be achieved by grouping
833 # snippets into sub-directories and using the ``.yas-make-groups``
834 # special file (for this see `Organizing Snippets`_
835
836
837 # Refer to the bundled snippets for ``ruby-mode`` for examples on the
838 # ``# group:`` directive. Group can also be nested, e.g. ``control
839 # structure.loops`` tells that the snippet is under the ``loops`` group
840 # which is under the ``control structure`` group.
841
842 # ``# expand-env:`` expand environment
843 # ------------------------------------
844
845 # This is another piece of Emacs-lisp code in the form of a ``let``
846 # \*varlist form*, i.e. a list of lists assigning values to variables. It
847 # can be used to override variable values while the snippet is being
848 # expanded.
849
850 # Interesting variables to override are ``yas/wrap-around-region`` and
851 # ``yas/indent-line`` (see `Expanding Snippets`_).
852
853 # As an example, you might normally have ``yas/indent-line`` set to
854 # ``'auto`` and ``yas/wrap-around-region`` set to ``t``, but for this
855 # particularly brilliant piece of ASCII art these values would mess up
856 # your hard work. You can then use:
857
858 # .. sourcecode:: text
859
860 # # name: ASCII home
861 # # expand-env: ((yas/indent-line 'fixed) (yas/wrap-around-region 'nil))
862 # # --
863 # welcome to my
864 # X humble
865 # / \ home,
866 # / \ $0
867 # / \
868 # /-------\
869 # | |
870 # | +-+ |
871 # | | | |
872 # +--+-+--+
873
874 # ``# binding:`` direct keybinding
875 # ---------------------------------
876
877 # You can use this directive to expand a snippet directly from a normal
878 # Emacs keybinding. The keybinding will be registered in the Emacs
879 # keymap named after the major mode the snippet is active
880 # for.
881
882 # Additionally a variable ``yas/prefix`` is set to to the prefix
883 # argument you normally use for a command. This allows for small
884 # variations on the same snippet, for example in this "html-mode"
885 # snippet.
886
887 # .. sourcecode:: text
888
889 # # name: <p>...</p>
890 # # binding: C-c C-c C-m
891 # # --
892 # <p>`(when yas/prefix "\n")`$0`(when yas/prefix "\n")`</p>
893
894 # This binding will be recorded in the keymap
895 # ``html-mode-map``. To expand a paragraph tag newlines, just
896 # press ``C-u C-c C-c C-m``. Omitting the ``C-u`` will expand the
897 # paragraph tag without newlines.
898
899 # ``# contributor:`` snippet author
900 # ---------------------------------------------------
901
902 # This is optional and has no effect whatsoever on snippet
903 # functionality, but it looks nice.
904
905 # Template syntax
906 # ===============
907
908 # The syntax of the snippet template is simple but powerful, very
909 # similar to TextMate's.
910
911 # Plain Text
912 # ----------
913
914 # Arbitrary text can be included as the content of a template. They are
915 # usually interpreted as plain text, except ``$`` and `````. You need to
916 # use ``\`` to escape them: ``\$`` and ``\```. The ``\`` itself may also
917 # needed to be escaped as ``\\`` sometimes.
918
919 # Embedded Emacs-lisp code
920 # ------------------------
921
922 # Emacs-Lisp code can be embedded inside the template, written inside
923 # back-quotes (`````). The lisp forms are evaluated when the snippet is
924 # being expanded. The evaluation is done in the same buffer as the
925 # snippet being expanded.
926
927 # Here's an example for ``c-mode`` to calculate the header file guard
928 # dynamically:
929
930 # .. sourcecode:: text
931
932 # #ifndef ${1:_`(upcase (file-name-nondirectory (file-name-sans-extension (buffer-file-name))))`_H_}
933 # #define $1
934
935 # $0
936
937 # #endif /* $1 */
938
939 # From version 0.6, snippets expansions are run with some special
940 # Emacs-lisp variables bound. One of this is ``yas/selected-text``. You
941 # can therefore define a snippet like:
942
943 # .. sourcecode:: text
944
945 # for ($1;$2;$3) {
946 # `yas/selected-text`$0
947 # }
948
949 # to "wrap" the selected region inside your recently inserted
950 # snippet. Alternatively, you can also customize the variable
951 # ``yas/wrap-around-region`` to ``t`` which will do this automatically.
952
953 # Tab stop fields
954 # ---------------
955
956 # Tab stops are fields that you can navigate back and forth by ``TAB``
957 # and ``S-TAB``. They are written by ``$`` followed with a
958 # number. ``$0`` has the special meaning of the *exit point* of a
959 # snippet. That is the last place to go when you've traveled all the
960 # fields. Here's a typical example:
961
962 # .. sourcecode:: text
963
964 # <div$1>
965 # $0
966 # </div>
967
968 # Placeholder fields
969 # ------------------
970
971 # Tab stops can have default values -- a.k.a placeholders. The syntax is
972 # like this:
973
974 # .. sourcecode:: text
975
976 # ${N:default value}
977
978 # They acts as the default value for a tab stop. But when you firstly
979 # type at a tab stop, the default value will be replaced by your
980 # typing. The number can be omitted if you don't want to create
981 # `mirrors`_ or `transformations`_ for this field.
982
983 # .. _mirrors:
984
985 # Mirrors
986 # -------
987
988 # We refer the tab stops with placeholders as a *field*. A field can have
989 # mirrors. Its mirrors will get updated when you change the text of a
990 # field. Here's an example:
991
992 # .. sourcecode:: text
993
994 # \begin{${1:enumerate}}
995 # $0
996 # \end{$1}
997
998 # When you type ``"document"`` at ``${1:enumerate}``, the word
999 # ``"document"`` will also be inserted at ``\end{$1}``. The best
1000 # explanation is to see the screencast(`YouTube
1001 # <http://www.youtube.com/watch?v=vOj7btx3ATg>`_ or `avi video
1002 # <http://yasnippet.googlecode.com/files/yasnippet.avi>`_).
1003
1004 # The tab stops with the same number to the field act as its mirrors. If
1005 # none of the tab stops has an initial value, the first one is selected
1006 # as the field and others mirrors.
1007
1008 # .. _transformations:
1009
1010 # Mirrors with transformations
1011 # ----------------------------
1012
1013 # If the value of an ``${n:``-construct starts with and contains ``$(``,
1014 # then it is interpreted as a mirror for field ``n`` with a
1015 # transformation. The mirror's text content is calculated according to
1016 # this transformation, which is Emacs-lisp code that gets evaluated in
1017 # an environment where the variable ``text`` (or ``yas/text``) is bound
1018 # to the text content (string) contained in the field ``n``.Here's an
1019 # example for Objective-C:
1020
1021 # .. sourcecode:: text
1022
1023 # - (${1:id})${2:foo}
1024 # {
1025 # return $2;
1026 # }
1027
1028 # - (void)set${2:$(capitalize text)}:($1)aValue
1029 # {
1030 # [$2 autorelease];
1031 # $2 = [aValue retain];
1032 # }
1033 # $0
1034
1035 # Look at ``${2:$(capitalize text)}``, it is a mirror with
1036 # transformation instead of a field. The actual field is at the first
1037 # line: ``${2:foo}``. When you type text in ``${2:foo}``, the
1038 # transformation will be evaluated and the result will be placed there
1039 # as the transformed text. So in this example, if you type "baz" in the
1040 # field, the transformed text will be "Baz". This example is also
1041 # available in the screencast.
1042
1043 # Another example is for ``rst-mode``. In reStructuredText, the document
1044 # title can be some text surrounded by "===" below and above. The "==="
1045 # should be at least as long as the text. So
1046
1047 # .. sourcecode:: text
1048
1049 # =====
1050 # Title
1051 # =====
1052
1053 # is a valid title but
1054
1055 # .. sourcecode:: text
1056
1057 # ===
1058 # Title
1059 # ===
1060
1061 # is not. Here's an snippet for rst title:
1062
1063 # .. sourcecode:: text
1064
1065 # ${1:$(make-string (string-width text) ?\=)}
1066 # ${1:Title}
1067 # ${1:$(make-string (string-width text) ?\=)}
1068
1069 # $0
1070
1071 # Fields with transformations
1072 # ---------------------------
1073
1074 # From version 0.6 on, you can also have lisp transformation inside
1075 # fields. These work mostly mirror transformations but are evaluated
1076 # when you first enter the field, after each change you make to the
1077 # field and also just before you exit the field.
1078
1079 # The syntax is also a tiny bit different, so that the parser can
1080 # distinguish between fields and mirrors. In the following example
1081
1082 # .. sourcecode:: text
1083
1084 # #define "${1:mydefine$(upcase yas/text)}"
1085
1086 # ``mydefine`` gets automatically upcased to ``MYDEFINE`` once you enter
1087 # the field. As you type text, it gets filtered through the
1088 # transformation every time.
1089
1090 # Note that to tell this kind of expression from a mirror with a
1091 # transformation, YASnippet needs extra text between the ``:`` and the
1092 # transformation's ``$``. If you don't want this extra-text, you can use
1093 # two ``$``'s instead.
1094
1095 # .. sourcecode:: text
1096
1097 # #define "${1:$$(upcase yas/text)}"
1098
1099 # Please note that as soon as a transformation takes place, it changes
1100 # the value of the field and sets it its internal modification state to
1101 # ``true``. As a consequence, the auto-deletion behaviour of normal
1102 # fields does not take place. This is by design.
1103
1104 # Choosing fields value from a list and other tricks
1105 # --------------------------------------------------
1106
1107 # As mentioned, the field transformation is invoked just after you enter
1108 # the field, and with some useful variables bound, notably
1109 # ``yas/modified-p`` and ``yas/moving-away-p``. Because of this
1110 # feature you can place a transformation in the primary field that lets
1111 # you select default values for it.
1112
1113 # The ``yas/choose-value`` does this work for you. For example:
1114
1115 # .. sourcecode:: text
1116
1117 # <div align="${2:$$(yas/choose-value '("right" "center" "left"))}">
1118 # $0
1119 # </div>
1120
1121 # See the definition of ``yas/choose-value`` to see how it was written
1122 # using the two variables.
1123
1124 # Here's another use, for LaTeX-mode, which calls reftex-label just as
1125 # you enter snippet field 2. This one makes use of ``yas/modified-p``
1126 # directly.
1127
1128 # .. sourcecode:: text
1129
1130 # \section{${1:"Titel der Tour"}}%
1131 # \index{$1}%
1132 # \label{{2:"waiting for reftex-label call..."$(unless yas/modified-p (reftex-label nil 'dont-
1133 # insert))}}%
1134
1135 # The function ``yas/verify-value`` has another neat trick, and makes
1136 # use of ``yas/moving-away-p``. Try it and see! Also, check out this
1137 # `thread
1138 # <http://groups.google.com/group/smart-snippet/browse_thread/thread/282a90a118e1b662>`_
1139
1140 # Nested placeholder fields
1141 # -------------------------
1142
1143 # From version 0.6 on, you can also have nested placeholders of the type:
1144
1145 # .. sourcecode:: text
1146
1147 # <div${1: id="${2:some_id}"}>$0</div>
1148
1149 # This allows you to choose if you want to give this ``div`` an ``id``
1150 # attribute. If you tab forward after expanding it will let you change
1151 # "some_id" to whatever you like. Alternatively, you can just press
1152 # ``C-d`` (which executes ``yas/skip-and-clear-or-delete-char``) and go
1153 # straight to the exit marker.
1154
1155 # By the way, ``C-d`` will only clear the field if you cursor is at the
1156 # beginning of the field *and* it hasn't been changed yet. Otherwise, it
1157 # performs the normal Emacs ``delete-char`` command.
1158
1159 # Customizable variables
1160 # ======================
1161
1162 # ``yas/trigger-key``
1163 # -------------------
1164
1165 # The key bound to ``yas/expand`` when function ``yas/minor-mode`` is
1166 # active.
1167
1168 # Value is a string that is converted to the internal Emacs key
1169 # representation using ``read-kbd-macro``.
1170
1171 # Default value is ``"TAB"``.
1172
1173 # ``yas/next-field-key``
1174 # ----------------------
1175
1176 # The key to navigate to next field when a snippet is active.
1177
1178 # Value is a string that is converted to the internal Emacs key
1179 # representation using ``read-kbd-macro``.
1180
1181 # Can also be a list of keys.
1182
1183 # Default value is ``"TAB"``.
1184
1185 # ``yas/prev-field-key``
1186 # ----------------------
1187
1188 # The key to navigate to previous field when a snippet is active.
1189
1190 # Value is a string that is converted to the internal Emacs key
1191 # representation using ``read-kbd-macro``.
1192
1193 # Can also be a list of keys.
1194
1195 # Default value is ``("<backtab>" "<S-tab>)"``.
1196
1197 # ``yas/skip-and-clear-key``
1198 # --------------------------
1199
1200 # The key to clear the currently active field.
1201
1202 # Value is a string that is converted to the internal Emacs key
1203 # representation using ``read-kbd-macro``.
1204
1205 # Can also be a list of keys.
1206
1207 # Default value is ``"C-d"``.
1208
1209 # ``yas/good-grace``
1210 # ------------------
1211
1212 # If non-nil, don't raise errors in inline Emacs-lisp evaluation inside
1213 # snippet definitions. An error string "[yas] error" is returned instead.
1214
1215 # ``yas/indent-line``
1216 # -------------------
1217
1218 # The variable ``yas/indent-line`` controls the indenting. It is bound
1219 # to ``'auto`` by default, which causes your snippet to be indented
1220 # according to the mode of the buffer it was inserted in.
1221
1222 # Another variable ``yas/also-auto-indent-first-line``, when non-nil
1223 # does exactly that :-).
1224
1225 # To use the hard-coded indentation in your snippet template, set this
1226 # variable to ``fixed``.
1227
1228 # To control indentation on a per-snippet basis, see also the directive
1229 # ``# expand-env:`` in `Writing Snippets`_.
1230
1231 # For backward compatibility with earlier versions of YASnippet, you can
1232 # also place a ``$>`` in your snippet, an ``(indent-according-to-mode)``
1233 # will be executed there to indent the line. This only takes effect when
1234 # ``yas/indent-line`` is set to something other than ``'auto``.
1235
1236 # .. sourcecode:: text
1237
1238 # for (${int i = 0}; ${i < 10}; ${++i})
1239 # {$>
1240 # $0$>
1241 # }$>
1242
1243 # ``yas/wrap-around-region``
1244 # --------------------------
1245
1246 # If non-nil, YASnippet will try to expand the snippet's exit marker
1247 # around the currently selected region. When this variable is set to t,
1248 # this has the same effect has using the ```yas/selected-text``` inline
1249 # evaluation.
1250
1251 # Because on most systems starting to type deletes the currently
1252 # selected region, this works mostly for snippets with direct
1253 # keybindings or with the ``yas/insert-snippet`` command.
1254
1255 # However, when the value is of this variable is ``cua`` YASnippet will
1256 # additionally look-up any recently selected that you deleted by starting
1257 # typing. This allows you select a region, type a snippet key (deleting
1258 # the region), then press ``yas/trigger-key`` to see the deleted region
1259 # spring back to life inside your new snippet.
1260
1261 # ``yas/triggers-in-field``
1262 # --------------------------
1263
1264 # If non-nil, ``yas/next-field-key`` can trigger stacked expansions,
1265 # that is a snippet expansion inside another snippet
1266 # expansion. Otherwise, ``yas/next-field-key`` just tries to move on to
1267 # the next field.
1268
1269 # ``yas/snippet-revival``
1270 # -----------------------
1271
1272 # Non-nil means re-activate snippet fields after undo/redo.
1273
1274 # ``yas/after-exit-snippet-hook`` and ``yas/before-expand-snippet-hook``
1275 # ----------------------------------------------------------------------
1276
1277 # These hooks are called, respectively, before the insertion of a
1278 # snippet and after exiting the snippet. If you find any strange but
1279 # functional use for them, that's probably a design flaw in YASnippet,
1280 # so let us know.
1281
1282 # Importing TextMate snippets
1283 # ===========================
1284
1285 # There are a couple of tools that take TextMate's ".tmSnippet" xml
1286 # files and create YASnippet definitions:
1287
1288 # * `a python script by Jeff Wheeler
1289 # <http://code.nokrev.com/?p=snippet-copier.git;a=blob_plain;f=snippet_copier.py>`_
1290
1291 # * a `ruby tool
1292 # <http://yasnippet.googlecode.com/svn/trunk/extras/textmate_import.rb>`_
1293 # , ``textmate_import.rb`` adapted from `Rob Christie's
1294 # <http://www.neutronflux.net/2009/07/28/shoulda-snippets-for-emacs/>`_,
1295 # which I have uploaded to the repository.
1296
1297 # In this section, i'll shortly cover the **second** option.
1298
1299 # Download the ``textmate_import.rb`` tool and the TextMate
1300 # bundle you're interested in.
1301
1302 # .. sourcecode:: text
1303
1304 # $ curl -O http://yasnippet.googlecode.com/svn/trunk/extras/textmate_import.rb
1305 # $ svn export http://svn.textmate.org/trunk/Bundles/HTML.tmbundle/
1306
1307
1308 # Then invoke ``textmate_import.rb`` like this:
1309
1310 # .. sourcecode:: text
1311
1312 # $ ./textmate_import.rb -d HTML.tmbundle/Snippets/ -o html-mode -g HTML.tmbundle/info.plist
1313
1314 # You should end up with a ``html-mode`` subdir containing snippets
1315 # exported from textmate.
1316
1317 # .. sourcecode:: text
1318
1319 # $ tree html-mode # to view dir contents, if you have 'tree' installed
1320
1321 # The ``-g`` is optional but helps the tool figure out the grouping.
1322 # According to `Organizing Snippets`_, don't forget to touch
1323 # ``.yas-make-groups`` and ``.yas-ignore-filename-triggers`` inside the
1324 # ``html-mode`` dir.
1325
1326 # Also try ``textmate_import.rb --help`` for a list of options.
1327
1328 # Please note that snippet importation is not yet perfect. You'll
1329 # probably have some adjustments to some/many snippets. Please
1330 # contribute these adjustments to the google group or, better yet, patch
1331 # the ``textmate_import.rb`` to automatically perform them and submit
1332 # that.
1333
1334 # .. LocalWords: html YASnippet yas sourcecode pluskid init filenames filename
1335 # .. LocalWords: env varlist keybinding keymap rinari ifndef upcase endif
1336 # .. LocalWords: nondirectory autorelease aValue inline
1337
1338 # * snippet-menu.org
1339 # ==============
1340 # YASnippet menu
1341 # ==============
1342
1343 # .. contents::
1344
1345 # When ``yas/minor-mode`` is active, YASnippet will setup a menu just
1346 # after the "Buffers" menu in the menubar.
1347
1348 # In this menu, you can find
1349
1350 # \* The currently loaded snippet definitions, organized by major mode,
1351 # and optional grouping.
1352
1353 # \* A rundown of the most common commands, (followed by their
1354 # keybindings) including commands to load directories and reload all
1355 # snippet definitions.
1356
1357 # \* A series of submenus for customizing and exploring YASnippet
1358 # behavior.
1359
1360 # .. image:: images/menu-1.png
1361 # :align: right
1362
1363 # Loading snippets from menu
1364 # --------------------------
1365
1366 # Invoking "Load snippets..." from the menu invokes
1367 # ``yas/load-directory`` and prompts you for a snippet directory
1368 # hierarchy to load.
1369
1370 # Also useful is the "Reload all" options which uncondionally reloads
1371 # all the snippets directories defined in ``yas/root-directory`` and
1372 # rebuilds the menus.
1373
1374 # Snippet menu behavior
1375 # ---------------------
1376
1377 # YASnippet will list in this section all the loaded snippet definitions
1378 # organized by snippet table name.
1379
1380 # You can use this section to explore currently loaded snippets. If you
1381 # click on one of them, the default behavior is to expand it,
1382 # unconditionally, inside the current buffer.
1383
1384 # You can however, customize variable ``yas/visit-from-menu`` to be
1385 # ``t`` which will take you to the snippet definition file when you
1386 # select it from the menu.
1387
1388 # If you want the menu show only snippet tables whose name corresponds
1389 # to a "real" major mode. You do this by setting ``yas/use-menu`` to
1390 # ``'real-modes``.
1391
1392 # Finally, to have the menu show only the tables for the currently
1393 # active mode, set ``yas/use-menu`` to ``abbreviate``.
1394
1395 # These customizations can also be found in the menu itself, under the
1396 # "Snippet menu behavior" submenu.
1397
1398
1399 # Controlling indenting
1400 # ---------------------
1401
1402 # The "Indenting" submenu contains options to control the values of
1403 # ``yas/indent-line`` and ``yas/also-auto-indent-first-line``. See
1404 # `Writing snippets <snippet-development.html>`_ .
1405
1406 # Prompting method
1407 # ----------------
1408
1409 # The "Prompting method" submenu contains options to control the value
1410 # of ``yas/prompt-functions``. See `Expanding snippets <snippet-expansion.html>`_ .
1411
1412 # Misc
1413 # ----
1414
1415 # The "Misc" submenu contains options to control the values of more
1416 # variables.
1417
1418
1419
1420
1421
1422
1423
1424
1425 # * faq.org
1426 # ============================
1427 # Frequently Asked Questions
1428 # ============================
1429
1430 # Why is there an extra newline?
1431 # ==============================
1432
1433 # If you have a newline at the end of the snippet definition file, then
1434 # YASnippet will add a newline when you expanding a snippet. Please
1435 # don't add a newline at the end if you don't want it when you saving
1436 # the snippet file.
1437
1438 # Note some editors will automatically add a newline for you. In Emacs,
1439 # if you set ``require-final-newline`` to ``t``, it will add the final
1440 # newline for you automatically.
1441
1442 # Why doesn't TAB expand a snippet?
1443 # =================================
1444
1445 # First check the mode line to see if there's ``yas``. If not, then try
1446 # ``M-x yas/minor-mode`` to manually turn on the minor mode and try to
1447 # expand the snippet again. If it works, then, you can add the following
1448 # code to your ``.emacs`` *before* loading YASnippet:
1449
1450 # .. sourcecode:: lisp
1451
1452 # (add-hook 'the-major-mode-hook 'yas/minor-mode-on)
1453
1454 # where ``the-major-mode`` is the major mode in which ``yas/minor-mode``
1455 # isn't enabled by default.
1456
1457 # From YASnippet 0.6 you can also use the command ``M-x
1458 # yas/global-mode`` to turn on YASnippet automatically for *all* major
1459 # modes.
1460
1461 # If ``yas/minor-mode`` is on but the snippet still not expanded. Then
1462 # try to see what command is bound to the ``TAB`` key: press ``C-h k``
1463 # and then press ``TAB``. Emacs will show you the result.
1464
1465 # You'll see a buffer prompted by Emacs saying that ``TAB runs the
1466 # command ...``. Alternatively, you might see ``<tab> runs the command
1467 # ...``, note the difference between ``TAB`` and ``<tab>`` where the
1468 # latter has priority. If you see ``<tab>`` bound to a command other
1469 # than ``yas/expand``, (e.g. in ``org-mode``) you can try the following
1470 # code to work around:
1471
1472 # .. sourcecode:: lisp
1473
1474 # (add-hook 'org-mode-hook
1475 # (let ((original-command (lookup-key org-mode-map [tab])))
1476 # `(lambda ()
1477 # (setq yas/fallback-behavior
1478 # '(apply ,original-command))
1479 # (local-set-key [tab] 'yas/expand))))
1480
1481 # replace ``org-mode-hook`` and ``org-mode-map`` with the major mode
1482 # hook you are dealing with (Use ``C-h m`` to see what major mode you
1483 # are in).
1484
1485 # As an alternative, you can also try
1486
1487 # .. sourcecode:: lisp
1488
1489 # (defun yas/advise-indent-function (function-symbol)
1490 # (eval `(defadvice ,function-symbol (around yas/try-expand-first activate)
1491 # ,(format
1492 # "Try to expand a snippet before point, then call `%s' as usual"
1493 # function-symbol)
1494 # (let ((yas/fallback-behavior nil))
1495 # (unless (and (interactive-p)
1496 # (yas/expand))
1497 # ad-do-it)))))
1498
1499 # (yas/advise-indent-function 'ruby-indent-line)
1500
1501 # To *advise* the modes indentation function bound to TAB, (in this case
1502 # ``ruby-indent-line``) to first try to run ``yas/expand``.
1503
1504 # If the output of ``C-h k RET <tab>`` tells you that ``<tab>`` is
1505 # indeed bound to ``yas/expand`` but YASnippet still doesn't work, check
1506 # your configuration and you may also ask for help on the `discussion
1507 # group <http://groups.google.com/group/smart-snippet>`_. See this
1508 # particular `thread
1509 # <http://code.google.com/p/yasnippet/issues/detail?id=93&can=1>`_ for
1510 # quite some solutions and alternatives.
1511
1512 # Don't forget to attach the information on what command is bound to TAB
1513 # as well as the mode information (Can be obtained by ``C-h m``).
1514
1515 # Why doesn't TAB navigation work with flyspell
1516 # =============================================
1517
1518 # A workaround is to inhibit flyspell overlays while the snippet is active:
1519
1520 # .. sourcecode:: lisp
1521
1522 # (add-hook 'flyspell-incorrect-hook
1523 # #'(lambda (dummy1 dummy2 dymmy3)
1524 # (and yas/active-field-overlay
1525 # (overlay-buffer yas/active-field-overlay))))
1526
1527 # This is apparently related to overlay priorities. For some reason, the
1528 # ``keymap`` property of flyspell's overlays always takes priority over
1529 # the same property in yasnippet's overlays, even if one sets the
1530 # latter's ``priority`` property to something big. If you know
1531 # emacs-lisp and can solve this problem, drop a line in the `discussion
1532 # group`_.
1533
1534 # How do I turn off the minor mode where in some buffers
1535 # ======================================================
1536
1537 # The best way, since version 0.6.1c, is to set the default value of the
1538 # variable ``yas/dont-activate`` to a lambda function like so:
1539
1540 # .. sourcecode:: lisp
1541
1542 # (set-default 'yas/dont-activate
1543 # #'(lambda ()
1544 # (and yas/root-directory
1545 # (null (yas/get-snippet-tables)))))
1546
1547 # This is also the default value starting for that version. It skips the
1548 # minor mode in buffers where it is not applicable (no snippet tables),
1549 # but only once you have setup your yas/root-directory.
1550
1551
1552 # How do I define an abbrev key containing characters not supported by the filesystem?
1553 # ====================================================================================
1554
1555 # \**Note**: This question applies if you're still defining snippets
1556 # whose key *is* the filename. This is behavior stil provided by
1557 # version 0.6 for backward compatibilty, but is somewhat deprecated...
1558
1559 # For example, you want to define a snippet by the key ``<`` which is
1560 # not a valid character for filename on Windows. This means you can't
1561 # use the filename as a trigger key in this case.
1562
1563 # You should rather use the ``# key:`` directive to specify the key of
1564 # the defined snippet explicitly and name your snippet with an arbitrary
1565 # valid filename, ``lt.yasnippet`` for example, using ``<`` for the
1566 # ``# key:`` directive:
1567
1568 # .. sourcecode:: text
1569
1570 # # key: <
1571 # # name: <...></...>
1572 # # --
1573 # <${1:div}>$0</$1>
1574
1575 # .. _discussion group: http://groups.google.com/group/smart-snippet
1576
1577 # * changelog.org
1578 # =========
1579 # ChangeLog
1580 # =========
1581
1582 # .. _Organizing Snippets: snippet-organization.html
1583 # .. _Expanding Snippets: snippet-expansion.html
1584 # .. _Writing Snippets: snippet-development.html
1585 # .. _The YASnippet Menu: snippet-menu.html
1586
1587 # 0.7.0b / ????-??-??
1588 # ===================
1589
1590 # \* Filenames can no longer be snippet triggers. Please upgrade your snippet
1591 # collections.
1592
1593
1594 # 0.6.1c / 2009-08-13
1595 # ===================
1596
1597 # \* Fixed `issues <http://code.google.com/p/yasnippet/issues>`_ 99, 98, 93,
1598 # 90, 91, 88, 87. Thanks everybody.
1599 # \* More compliant customization group `Issue94
1600 # <http://code.google.com/p/yasnippet/issues/detail?id=94>`_, (thanks
1601 # wyuenho).
1602 # \* Added workaround for issue 97 in the FAQ
1603 # \* Small updates to documentation.
1604
1605 # 0.6.1b / 2009-08-29
1606 # ===================
1607
1608 # \* Much more powerful menu. See `The YASnippet menu`_.
1609 # \* New ways to organize snippets. See `Organizing snippets`_.
1610 # \* Added ``yas/also-auto-indent-first-line`` customization variable.
1611 # \* Renamed directive ``# env:`` to ``# expand-env:``
1612 # \* Rewrote much of the documentation.
1613 # \* Added TextMate import tool ``textmate-import.rb`` to to svn
1614 # repository (see "extras/")
1615 # \* Added *experimental* bundle of textmate snippets
1616 # ``yasnippet-textmate-bundle.el``
1617 # \* Fixed `Issue 74
1618 # <http://code.google.com/p/yasnippet/issues/detail?id=74>`_ (thanks
1619 # rmartin.k...@gmail.com)
1620 # \* Fixed `Issues 80 through 84
1621 # <http://code.google.com/p/yasnippet/issues/detail?id=80>`_ (thanks
1622 # Moritz Bunkus)
1623 # \* Fixed many more issues...
1624
1625
1626 # 0.6.0c / 2009-07-27
1627 # ===================
1628
1629 # \* Now byte compiles correctly with no warnings.
1630 # \* Fixed `Issue 68
1631 # <http://code.google.com/p/yasnippet/issues/detail?id=68>`_ with
1632 # mouse-clicking alternatives in ``ido-mode``.
1633 # \* Added ``yas/also-auto-indent-first-line`` customization variable.
1634
1635
1636 # 0.6.0b / 2009-07-25
1637 # ===================
1638
1639 # \* Nested placeholders of the type ``<div${1: id="${2:someid}"}> $0``.
1640
1641 # \* More robust undo/redo support.
1642
1643 # \* Stacked snippet expansion (*snippet in snippet*).
1644
1645 # \* Transformation on a primary field with syntax ``${1:default$(transform)}``
1646
1647 # \* Validations on field exit through the ``yas/verify-value``
1648 # primary field transformation.
1649
1650 # \* Wrapping the region in the exit marker ``$0`` of the snippet. Use
1651 # ``yas/wrap-around-region``.
1652
1653 # \* Auto-indentation. Use ``yas/indent-line`` set to ``'auto``
1654
1655 # \* Easier definition of snippets. Use ``yas/find-snippets`` or
1656 # ``yas/visit-snippet-file``. In the new ``snippet-mode`` use
1657 # ``yas/load-snippet-buffer`` and ``yas/tryout-snippet``.
1658
1659 # \* Customization group ``yasnippet``.
1660
1661 # \* Overriding customization variables in snippets. Use the ``env:
1662 # let-form`` template keyword.
1663
1664 # \* Fixed `Issue 60
1665 # <http://code.google.com/p/yasnippet/issues/detail?id=60>`_
1666 # \* Fixed `Issue 65
1667 # <http://code.google.com/p/yasnippet/issues/detail?id=65>`_
1668 # \* Fixed `Issue 56
1669 # <http://code.google.com/p/yasnippet/issues/detail?id=56>`_
1670
1671 # 0.5.10 / 2009-02-11
1672 # ===================
1673
1674 # \* Added *grouping* support so that the snippets in the menu can be
1675 # groupped together.
1676 # \* Make the bundle `ELPA <http://tromey.com/elpa/index.html>`_
1677 # compatible.
1678
1679 # 0.5.9 / 2009-01-21
1680 # ==================
1681
1682 # \* Fixed the bug of disabling the auto-indenting of ``cc-mode``.
1683
1684 # 0.5.8 / 2009-01-15
1685 # ==================
1686
1687 # \* Added a ``key`` property in snippet definition for snippet names
1688 # that are not valid path name.
1689 # \* Fixed some bugs of indenting (`Issue 44
1690 # <http://code.google.com/p/yasnippet/issues/detail?id=44>`_, `Issue
1691 # 46 <http://code.google.com/p/yasnippet/issues/detail?id=46>`_).
1692 # \* Fixed `Issue 45
1693 # <http://code.google.com/p/yasnippet/issues/detail?id=45>`_ by
1694 # providing a proper default value for ``yas/buffer-local-condition``.
1695 # \* Added helper function ``yas/substr`` for convenient mirror
1696 # transformation.
1697 # \* Make variable ``yas/registered-snippet`` properly initialized.
1698 # \* Fixed the overlay error when overlay becomes empty (`Issue 49
1699 # <http://code.google.com/p/yasnippet/issues/detail?id=49>`_ and
1700 # `Issue 48
1701 # <http://code.google.com/p/yasnippet/issues/detail?id=48>`_). This
1702 # bug has occurred and been fixed earlier, and should not have
1703 # happened if we have proper regression test.
1704 # \* Added a workaround for ``c-electric-`` serial commands (`Issue 27
1705 # <http://code.google.com/p/yasnippet/issues/detail?id=27>`_).
1706
1707 # 0.5.7 / 2008-12-03
1708 # ==================
1709
1710 # \* Fixed `Issue 28
1711 # <http://code.google.com/p/yasnippet/issues/detail?id=28>`_ of
1712 # properly clean up snippet (by joaotavora).
1713 # \* Added a new section "Field-level undo functionality" to correct
1714 # `Issue 33 <http://code.google.com/p/yasnippet/issues/detail?id=33>`_
1715 # (by joaotavora).
1716 # \* Added some snippets from users for sql, erlang, scala, html, xml, latex, etc.
1717 # \* Fixed `Issue 16
1718 # <http://code.google.com/p/yasnippet/issues/detail?id=16>`_ by adding
1719 # ``$>`` support. Here's the `doc for $> indenting
1720 # <http://pluskid.lifegoo.com/upload/project/yasnippet/doc/define_snippet.html#indenting>`_.
1721
1722 # 0.5.6 / 2008-08-07
1723 # ==================
1724
1725 # \* Added a buffer local variable ``yas/dont-activate`` to turn off
1726 # ``yas/minor-mode`` in some major modes. See `Issue 29
1727 # <http://code.google.com/p/yasnippet/issues/detail?id=29>`_.
1728 # \* Make the environment of elisp evaluation more friendly to
1729 # ``(current-column)``.
1730 # \* Fixed the regular expression bug in python-mode snippets.
1731 # \* Use filename or full key extension for snippet name if no ``name``
1732 # property is defined.
1733
1734 # 0.5.5 / 2008-05-29
1735 # ==================
1736
1737 # \* Tweak ``yas/extra-mode-hooks`` so that it can be more easily
1738 # customized.
1739 # \* Add an entry in FAQ about why ``TAB`` key doesn't work in some
1740 # modes.
1741
1742 # 0.5.4 / 2008-05-15
1743 # ==================
1744
1745 # \* Added ``ox-mode-hook`` and ``python-mode-hook`` to
1746 # ``yas/extra-mode-hooks`` to fix the problem YASnippet is not enabled
1747 # in those modes.
1748
1749 # 0.5.3 / 2008-05-07
1750 # ==================
1751
1752 # \* Fix indent of python-mode snippets.
1753 # \* Fix a bug of dropdown-list: conflicts with color-theme (`Issue 23
1754 # <http://code.google.com/p/yasnippet/issues/detail?id=23>`_). Thanks
1755 # Mike.
1756 # \* Fix a bug of condition system.
1757
1758 # 0.5.2 / 2008-04-20
1759 # ==================
1760
1761 # \* Fix a bug for comparing string to symbol using ``string=`` (which
1762 # will fire an error).
1763
1764 # 0.5.1 / 2008-04-14
1765 # ==================
1766
1767 # \* Use a beautiful css style in the document.
1768
1769 # 0.5.0 / 2008-04-10
1770 # ==================
1771
1772 # \* Integrate with hippie-expand. Just add ``yas/hippie-try-expand`` to
1773 # ``hippie-expand-try-functions-list``.
1774 # \* If you set ``yas/fall-back-behavior`` to ``'return-nil``, YASnippet
1775 # will return nil when it can't find a snippet to expand.
1776 # \* Defect fix: the condition of a snippet was evaluated twice in
1777 # earlier version.
1778 # \* Deleting snippet (using ``C-w`` or ``C-k``) won't cause serious
1779 # problem now.
1780 # \* Several complex snippet for python-mode from Yasser included in the
1781 # distribution.
1782
1783 # 0.4.5 / 2008-04-07
1784 # ==================
1785
1786 # \* Merge the latest dropdown-list.el.
1787 # \* Add snippets for f90-mode from Li Zhu.
1788 # \* Bug fix: l-safe-expr-p: Lisp nesting exceeds ``max-lisp-eval-depth``
1789 # error when several (more than two) snippets overlaps. Thanks
1790 # sunwaybupt@newsmth for reporting this bug.
1791
1792 # 0.4.4 / 2008-03-24
1793 # ==================
1794
1795 # \* Bug fix: dropdown-list.el doesn't recognize [return] properly.
1796
1797 # 0.4.3 / 2008-03-23
1798 # ==================
1799
1800 # \* Bug fix: failed to recognize user customized yas/trigger-key.
1801
1802 # 0.4.2 / 2008-03-22
1803 # ==================
1804
1805 # \* Make a separate document package for release. Also make document
1806 # available online.
1807
1808 # 0.4.1 / 2008-03-21
1809 # ==================
1810
1811 # \* Make sure ``yas/minor-mode``'s key bindings always take priority to
1812 # other minor modes.
1813
1814 # 0.4.0 / 2008-03-20
1815 # ==================
1816
1817 # \* Document refinement and released with YASnippet. Most of the Online
1818 # wiki document will be deprecated soon.
1819 # \* Powerful condition system added to yasnippet!
1820 # \* Incorporate ``dropdown-list.el`` and make it default way for
1821 # selecting multiple candidates. Thanks to `Jaeyoun Chung
1822 # <http://groups.google.com/group/smart-snippet/browse_thread/thread/c869158b76addeb3/e7c6372ba457189e>`_.
1823 # \* yas/before-expand-snippet-hook
1824
1825 # 0.3.2 / 2008-03-19
1826 # ==================
1827
1828 # \* Enhancement: A better way to define minor-mode. Thanks to Kentaro
1829 # Kuribayashi. See `this thread
1830 # <https://groups.google.com/group/smart-snippet/browse_thread/thread/65cb3b5583eda887?hl=en>`_
1831 # for more details.
1832
1833 # 0.3.1 / 2008-03-17
1834 # ==================
1835
1836 # \* Bug fix: Emacs get confused when a field is deleted. See `issue 10
1837 # <http://code.google.com/p/yasnippet/issues/detail?id=10>`_.
1838
1839 # 0.3.0 / 2008-03-16
1840 # ==================
1841
1842 # \* Add a ``yas/after-exit-snippet-hook`` so that you can do something like
1843 # ``indent-region`` or ``fill-region`` after finish the snippet.
1844 # \* Use minor-mode instead of ``global-set-key`` to bind the trigger
1845 # key. Now the trigger key and fall-back behavior can be more
1846 # flexible. Not constrained to ``<tab>``. Thanks to Trey Jackson. See
1847 # this `thread
1848 # <https://groups.google.com/group/smart-snippet/browse_thread/thread/937f32a2a6dea4f2?hl=en>`_
1849 # for more details.
1850 # \* Now user can customize the popup function for selecting multiple
1851 # candidate for the same snippet key.
1852 # \* Support ``dropdown-list.el`` to be a better way to select multiple
1853 # candidate when in text mode.
1854
1855 # 0.2.3 / 2008-03-15
1856 # ==================
1857
1858 # \* Bug in non-window (-nw) mode when there's multiple candidate to
1859 # expand. See `issue 7
1860 # <http://code.google.com/p/yasnippet/issues/detail?id=7>`_.
1861 # \* Allow expanding another snippet as long as not currently inside a
1862 # field.
1863
1864 # 0.2.2 / 2008-03-13
1865 # ==================
1866
1867 # \* Added customized face for fields and mirrors. Better in dark
1868 # background. And users can customize it.
1869
1870 # 0.2.1 / 2008-03-10
1871 # ==================
1872
1873 # \* Fix the insert-behind problem under both Emacs 22 and Emacs 23.
1874
1875 # 0.2.0 / 2008-03-10
1876 # ==================
1877
1878 # \* Use big keymap overlay to detect ``insert-behind`` event manually to
1879 # avoid sometimes missed hook calls. See `issue 3
1880 # <http://code.google.com/p/yasnippet/issues/detail?id=3>`_ for more
1881 # details.
1882 # \* Support parent snippet table. Now you can set (for example)
1883 # ``cc-mode`` as common mode for ``c++-mode``, ``c-mode`` and
1884 # ``java-mode``. They'll share snippets defined for ``cc-mode``.
1885
1886 # 0.1.1 / 2008-03-08
1887 # ==================
1888
1889 # \* Add a rake task to upload to google code.
1890 # \* Use elisp compile-bundle function instead of python scrip
1891
1892 # 0.1.0 / 2008-03-07
1893 # ==================
1894
1895 # \* Embedded elisp support.
1896 # \* Fields navigation support.
1897 # \* Mirror of fields support.
1898 # \* Menu-bar support.
1899 # \* Multiple snippets with same name support.
1900 # \* Popup menu for multiple snippet with same name support.
1901 # \* Transformation of fields support.
1902 # \* Load directory support.
1903 # \* Compile bundle support.