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