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