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