]> code.delx.au - gnu-emacs-elpa/blob - doc/manual.mdown
Merge pull request #424 from ljos/de/activate-extra-mode
[gnu-emacs-elpa] / doc / manual.mdown
1 Quick start
2 ===========
3
4 *YASnippet* is a template system for Emacs. It allows you to type an
5 abbreviation and automatically expand it into function templates. Bundled
6 language templates includes: C, C++, C#, Perl, Python, Ruby, SQL, LaTeX, HTML,
7 CSS and more. The snippet syntax is inspired from TextMate's syntax, you can
8 even [import most TextMate snippets](#import-textmate)
9
10 YASnippet is an original creation of [pluskid][pluskid] who also wrote its predecessor
11 [smart-snippet][smart-snippet].
12
13 Watch a demo
14 ------------
15
16 Do so on [youtube][youtube]
17
18 Installation
19 ------------
20
21 Clone this repository somewhere
22
23 $ cd ~/.emacs.d/plugins
24 $ git clone https://github.com/capitaomorte/yasnippet
25
26 Add the following in your =.emacs= file:
27
28 (add-to-list 'load-path
29 "~/.emacs.d/plugins/yasnippet")
30 (require 'yasnippet)
31 (yas/global-mode 1)
32
33 Add your own snippets to `~/.emacs.d/snippets` by placing files there or
34 invoking `yas-new-snippet`.
35
36 Import textmate snippets (rails example)
37 ----------------------------------------
38
39 YASnippet lets you use TextMate bundles directly:
40
41 $ cd ~/.emacs.d/plugins
42 $ git clone https://github.com/capitaomorte/yasnippet
43 $ cd yasnippet
44 $ git submodule init
45 $ git submodule update
46 $ gem install plist trollop
47 $ rake convert_bundles # will convert ruby, rails and html bundles from drnic
48
49 Then, in your `.emacs` file
50
51
52 (add-to-list 'load-path
53 "~/.emacs.d/plugins/yasnippet")
54 (require 'yasnippet)
55 (setq yas/snippet-dirs '("~/.emacs.d/snippets" "~/.emacs.d/extras/imported"))
56 (yas/global-mode 1)
57
58 Open some rails file (model, app, etc) and start using the textmate
59 snippets. Consider that this is a work-in-progress and many snippets/commands
60 might not work. Patches welcome!
61
62 Contributing snippets
63 ---------------------
64
65 Please *do not ask me* to add snippets to the default collection under
66 `/snippets`. This collection is considered frozen. By customizing
67 `yas-snippet-dirs` you can point yasnippet to good snippet collections out
68 there.
69
70 The `extras/textmate-import.rb` tool can import many actual Textmate snippets.
71 I'm focusing on developing it and the accompanying `yas-setup.el` files that
72 guide it with more difficult importations. The idea is to deprecate `/snippets=
73 and replace it with =extras/imported`.
74
75 Documentation, issues, etc
76 --------------------------
77
78 Please refer to the comprehensive [documentation](docs) for full
79 customization and support. If you think you've found a bug, please report it
80 on [the GitHub issue tracker](issues). (please **do not** submit new
81 issues to the old [googlecode tracker](googlecode-tracker))
82
83 If you run into problems using YASnippet, or have snippets to contribute,
84 post to the [yasnippet forum](forum). Thank you very much for using
85 YASnippet!
86
87 Organizing snippets
88 ===================
89
90 Basic structure
91 ---------------
92
93 Snippet collections can be stored in plain text files. They are arranged by
94 sub-directories naming *snippet tables*. These mostly name Emacs major names.
95
96 .
97 |-- c-mode
98 | `-- printf
99 |-- java-mode
100 | `-- println
101 `-- text-mode
102 |-- email
103 `-- time
104
105 The collections are loaded into *snippet tables* which the triggering
106 mechanism (see [Expanding snippets](#expand-snippets)) looks up and
107 (hopefully) cause the right snippet to be expanded for you.
108
109 Setting up `yas-snippet-dirs`
110 -----------------------------
111
112 The emacs variable `yas-snippet-dirs` tells YASnippet
113 which collections to consider. It's used when you activate
114 `yas-global-mode` or call
115 `yas-reload-all` interactively.
116
117 The default considers:
118
119 - a personal collection that lives in `~/.emacs.d/snippets`
120 - the bundled collection, taken as a relative path to `yasnippet.el` localtion
121
122 When you come across other snippet collections, do the following to try them
123 out:
124
125 ;; Develop in ~/emacs.d/mysnippets, but also
126 ;; try out snippets in ~/Downloads/interesting-snippets
127 (setq yas/snippet-dirs '("~/emacs.d/mysnippets"
128 "~/Downloads/interesting-snippets"))
129
130 ;; OR, keeping yasnippet's defaults try out ~/Downloads/interesting-snippets
131 (setq yas/snippet-dirs (append yas/snippet-dirs
132 '("~/Downloads/interesting-snippets")))
133
134 Collections appearing earlier in the list shadow snippets with same names
135 appearing in collections later in the list. `yas-new-snippet` always stores
136 snippets in the first collection.
137
138 The `.yas-parents` file
139 -----------------------
140
141 It's very useful to have certain modes share snippets between themselves. To do
142 this, choose a mode subdirectory and place a `.yas-parents` containing a
143 whitespace-separated list of other mode names. When you reload those modes
144 become parents of the original mode.
145
146 .
147 |-- c-mode
148 | |-- .yas-parents # contains "cc-mode text-mode"
149 | `-- printf
150 |-- cc-mode
151 | |-- for
152 | `-- while
153 |-- java-mode
154 | |-- .yas-parents # contains "cc-mode text-mode"
155 | `-- println
156 `-- text-mode
157 |-- email
158 `-- time
159
160 The `.yas-make-groups` file
161 ---------------------------
162
163 If you place an empty plain text file `.yas-make-groups` inside one of the mode
164 directories, the names of these sub-directories are considered groups of
165 snippets and [the menu](snippet-menu) is organized much more cleanly:
166
167 (TODO image)
168
169 Another alternative way to achieve this is to place a `# group:` directive
170 inside the snippet definition. See [Writing Snippets](#writing-snippets)
171
172
173 $ tree ruby-mode/
174 ruby-mode/
175 |-- .yas-make-groups
176 |-- collections
177 | |-- each
178 | `-- ...
179 |-- control structure
180 | |-- forin
181 | `-- ...
182 |-- definitions
183 | `-- ...
184 `-- general
185 `-- ...
186
187
188 Yet another way to create a nice snippet menu is to write into
189 `.yas-make-groups` a menu definition. TODO
190
191 TODO The `.yas-setup.el` file
192 -----------------------------
193
194 *** TODO
195
196 TODO The `.yas-compiled-snippet.el` file
197 ----------------------------------------
198
199 *** TODO
200
201 The `.yas-skip` file
202 --------------------
203
204 Expanding Snippets
205 ==================
206
207 This section describes how YASnippet chooses snippets for expansion at point.
208
209 Maybe, you'll want some snippets to be expanded in a particular
210 mode, or only under certain conditions, or be prompted using
211
212 Triggering expansion
213 --------------------
214
215 To make a snippet expand after the cursor:
216
217 * Type an the snippet's *trigger key* then press the key defined in
218 `yas-trigger-key`.
219
220 * Use the snippet's *keybinding*.
221
222 * Call [`yas-insert-snippet=](#yas-insert-snippet) (use `M-x
223 yas-insert-snippet`= or its keybinding =C-c & C-s`).
224
225 * By expanding directly from the "YASnippet" menu in the menu-bar
226
227 * Using hippie-expand
228
229 * Use m2m's excellent [auto-complete](http://github.com/m2m/autocomplete)
230
231 Reference
232 =========
233
234 (yas--document-symbols 2 `("Interactive functions" . ,#'interactive-form)
235 `("Customization variables" . ,#'(lambda (sym)
236 (and (boundp sym)
237 (get sym 'standard-value))))
238 `("Useful functions" . ,#'fboundp)
239 `("Useful variables" . ,#'boundp))
240
241 [smart-snippet]: http://code.google.com/p/smart-snippet
242 [pluskid]: http://pluskid.lifegoo.org
243 [screencast]: http://www.youtube.com/watch?v=ZCGmZK4V7Sg
244 [docs]: http://capitaomorte.github.com/yasnippet
245 [issues]: https://github.com/capitaomorte/yasnippet/issues
246 [googlecode-tracker]: http://code.google.com/p/yasnippet/issues/list
247 [forum]: http://groups.google.com/group/smart-snippet
248
249
250
251 <!--
252 !-- Local Variables:
253 !-- mode: markdown
254 !-- fill-column: 80
255 !-- coding: utf-8
256 !-- End:
257 !-- -->