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