diff --git a/Rakefile b/Rakefile index 54015a8..04cb216 100644 --- a/Rakefile +++ b/Rakefile @@ -3,7 +3,7 @@ require 'fileutils' def find_version - File.read("yasnippet.el") =~ /;; Version: *([0-9.]+) *$/ + File.read("yasnippet.el") =~ /;; Package-version: *([0-9.]+[a-z]?) *$/ $version = $1 end find_version @@ -19,7 +19,7 @@ desc "create a release package" task :package do release_dir = "pkg/yasnippet-#{$version}" FileUtils.mkdir_p(release_dir) - files = ['snippets', 'yasnippet.el'] + files = ['snippets', 'yasnippet.el', 'dropdown-list.el'] FileUtils.cp_r files, release_dir FileUtils.rm_r Dir[release_dir + "/**/.svn"] FileUtils.cd 'pkg' diff --git a/doc/changelog.html b/doc/changelog.html index ab1b98b..8dec07f 100644 --- a/doc/changelog.html +++ b/doc/changelog.html @@ -40,7 +40,30 @@
Contents
Finally, you can use yas/define to define a single snippet at your convenience. I ofthen use this to do some testing.
Here's the directory hierarchy of the snippets directory comes with YASnippet:
snippets
@@ -218,7 +224,7 @@ whose parent is perl-mode<
dot (.) are ignored.
A file defining a snippet may just contain the template for the snippet. Optionally it can also contains some meta data for the snippet as well as comments.
@@ -261,12 +267,55 @@ under the loops group group.From version 0.6 upwards there are two ways you can quickly find a +snippet file. Once you find this file it will be set to +snippet-mode (see ahead)
+M-x yas/find-snippets
+Lets you find the snippet file in the directory the snippet was +loaded from (if it exists) like find-file-other-window.
+M-x yas/visit-snippet-file
+Prompts you for possible snippet expansions like +yas/insert-snippet, but instead of expanding it, takes you +directly to the snippet definition's file, if it exists.
+From version 0.6 upwards there is a major mode snippet-mode to +edit snippets. You can set the buffer to this mode with M-x +snippet-mode. It provides reasonably useful syntax highlighting.
+Two commands are defined in this mode:
+M-x yas/load-snippet-buffer
+++When editing a snippet, this loads the snippet into the correct +mode and menu. Bound to C-c C-c by default while in +snippet-mode.
+
M-x yas/tryout-snippet
+++When editing a snippet, this opens a new empty buffer, sets it to +the appropriate major mode and inserts the snippet there, so you +can see what it looks like. This is bound to C-c C-t while in +snippet-mode.
+
There are also snippets for making snippets: vars, field and +mirror.
+As I mentioned above, you can define snippets directly by writing elisp code.
The basic syntax of yas/define-snippets is
(yas/define-snippets MODE SNIPPETS &optional PARENT)
The example above is auto-generated code by yas/compile-bundle.
yas/compile-bundle can be used to parse the snippets from a directory hierarchy and translate them into the elisp form. The translated code is faster to load. Further more, the generated bundle is a stand-alone file not depending on yasnippet.el. The released bundles of YASnippet are all generated this way.
The basic syntax of yas/compile-bundle is
-(yas/compile-bundle &optional yasnippet yasnippet-bundle snippet-roots code)
+(yas/compile-bundle &optional yasnippet yasnippet-bundle snippet-roots code dropdown)
As you can see, all the parameters are optional. The default values
for those parameters are convenient for me to produce the default
@@ -313,7 +362,8 @@ release bundle:
(yas/compile-bundle "yasnippet.el"
"./yasnippet-bundle.el"
'("snippets")
- "(yas/initialize)")
+ "(yas/initialize)"
+ "dropdown-list.el")
The snippet-roots can be a list of root directories. This is
useful when you have multiple snippet directories (maybe from other
@@ -321,9 +371,11 @@ users). The code para
customization code instead of the default (yas/initialize). For
example, you can set yas/trigger-key to (kbd "SPC") here if
you like.
+From release 0.6 you have to specify the dropdown-list.el file if
+you want it to be a part of the generated bundle.
The basic syntax for yas/define is
(yas/define mode key template &optional name condition group)
When user press the yas/trigger-key, YASnippet try to find a proper snippet to expand. The strategy to find such a snippet is explained here.
YASnippet search from current point backward trying to find the snippet to be expanded. The default searching strategy is quite powerful. For example, in c-mode, "bar", "foo_bar", @@ -362,7 +414,7 @@ following thing until found one:
Emacs's syntax rule mean.I write forked snippet.el to make the smart-snippet.el. I call it
smart-snippet because a condition can be attached to a snippet. This
is really a good idea. However, writing condition for a snippet
@@ -426,7 +478,7 @@ can be expanded as you expected, while other snippets like
-Multiple snippet with the same key
+Multiple snippet with the same key
There can be multiple snippet bind to the same key. If you define a
snippet with a key that is already used, you'll overwrite the original
snippet definition. However, you can add a different postfix to the
@@ -437,20 +489,21 @@ valid candidates when the key is
When there are multiple candidates, YASnippet will let you select
one. The UI for selecting multiple candidate can be
customized. There're two variable related: From version 0.6 of YASnippet this has changed significantly. A
+customization variable, called yas/prompt-functions defines your
+preferred method of being prompted for snippets. You can customize it with M-x customize-variable RET
+yas/prompt-functions RET. Alternatively you can put in your
+emacs-file: Currently there are some alternatives solution with YASnippet. The function yas/x-popup-menu-for-template can be used to show a
-popup menu for you to select. This menu will be part of you native
-window system widget, which means: The function yas/x-prompt can be used to show a popup menu for you
+to select. This menu will be part of you native window system widget,
+which means: This one is originally used in terminal mode. It doesn't let you to
-choose anything, it just select the first one on behalf of you. So I
-bet you never want to use this. :p You can use functions yas/completing-prompt for the classic emacs
+completion method or yas/ido-prompt for a much nicer looking
+method. The best way is to try it. This works in a terminal. The function yas/dropdown-prompt can also be placed in the
+yas/prompt-functions list. Originally, only the above two function is available in
YASnippet. They are difficult to use -- especially in a
@@ -482,7 +538,7 @@ candidate.
dropdown-list.el. And upload dropdown-list.el to YASnippet
hompage for an optional download (since Jaeyoun didn't provide a URL). Then finally, in 0.4.0, I included a copy of the content of
-dropdown-list.el [1] in yasnippet.el and made it the default
+dropdown-list.el [1] in yasnippet.el and made it the default
way for selecting multiple candidates. However, the original functions are still there, you can still use this YASnippet is implemented as a minor-mode (yas/minor-mode). The
trigger key yas/trigger-key is defined in yas/minor-mode-map
to call yas/expand to try to expand a snippet. When yas/minor-mode is enabled, the trigger key will take
effect. The default key is (kbd "TAB"), however, you can freely
-set it to some other key. By default, YASnippet add a hook to
-after-change-major-mode-hook to enable yas/minor-mode [2] in
+set it to some other key. In version 0.5, YASnippet add a hook to
+after-change-major-mode-hook to enable yas/minor-mode [2] in
every buffer. This works fine for most modes, however, some mode
doesn't follow the Emacs convention and doens't call this hook. You
can either explicitly hook for those mode or just add it to
@@ -515,9 +572,12 @@ can either explicitly hook for those mode or just add it to
Note that should be put after (require 'yasnippet) and before
(yas/initialize). Further more, you may report it to me, I'll add
that to the default value. In version 0.6, just use yas/global-mode to enable YASnippet in
+all major modes. Or put yas/minor-mode-on in that modes hook. See
+the FAQ. If yas/expand failed to find any suitable snippet to expand, it
will disable the minor mode temporarily and find if there's any other
command bind the yas/trigger-key. If found, the command will be
@@ -533,7 +593,7 @@ e.g. hippie-expand. I
with hippie-expand is already included in YASnippet. To integrate with hippie-expand, just put
yas/hippie-try-expand in
hippie-expand-try-functions-list. Personally I would like to put
@@ -541,13 +601,26 @@ in front of the list, but it can be put anywhere you prefer. When you use the trigger key (so yas/expand) to expand a snippet,
the key for the snippet is deleted before the template for the snippet
is inserted. However, there're other ways to insert a snippet. The command M-x yas/insert-snippet lets you insert snippets at
+point for you current major mode. It prompts you for the snippet
+key first, and then for a snippet template if more than one template
+exists for the same key. The list presented contains the snippets that can be inserted at
+point, according to the condition system. If you want to see all
+applicable snippets for the major mode, prefix this command with
+C-u. The prompting methods used are again controlled by
+yas/prompt-functions. YASnippet will setup a menu just after the Buffers Menu in the
menubar. The snippets for all real modes are listed there under the
menu. You can select a snippet from the menu to expand it. Since you
@@ -579,7 +652,7 @@ maintain a list of known modes (y
to that list if you need. Sometimes you might want to expand a snippet directly by calling a
functin from elisp code. You should call yas/expand-snippet
instead of yas/expand in this case. The syntax of the snippet template is simple but powerful, very
similar to TextMate's. Arbitrary text can be included as the content of a template. They are
usually interpreted as plain text, except $ and `. You need to
use \ to escape them: \$ and \`. The \ itself may also
needed to be escaped as \\ sometimes. Elisp code can be embedded inside the template. They are written
inside back-quotes (`): They are evaluated when the snippet is being expanded. The evaluation
@@ -624,11 +697,21 @@ $0
#endif /* $1 */
From version 0.6.0, snippets expansions are run with some special
+emacs-lisp variables bound. One of this is yas/selected-text. You
+can therefore define a snippet like: to "wrap" the selected region inside your recently inserted
+snippet. Alternatively, you can also customize the variable
+yas/wrap-around-region to t which will do this automatically. Tab stops are fields that you can navigate back and forth by TAB
-and S-TAB [3]. They are written by $ followed with a
+and S-TAB [3]. They are written by $ followed with a
number. $0 has the special meaning of the exit point of a
snippet. That is the last place to go when you've traveled all the
fields. Here's a typical example: Tab stops can have default values -- a.k.a placeholders. The syntax is
like this: We refer the tab stops with placeholders as a field. A field can have
mirrors. Its mirrors will get updated when you change the text of a
field. Here's an example: If the default value of a field starts with $, then it is interpreted
as the transformation code instead of default value. A transformation
is some arbitrary elisp code that will get evaluated in an environment
@@ -709,27 +792,81 @@ ${1:$(make-string (string-width text) ?\=)}
$0
From version 0.6 on, you can also have lisp transformation inside
+fields. These work mostly mirror transformations but are evaluated
+when you first enter the field, after each change you make to the
+field and also just before you exit the field. The syntax is also a tiny bit different, so that the parser can
+distinguish between fields and mirrors. In the following example mydefine gets automatically upcased to MYDEFINE once you enter
+the field. As you type text, it gets filtered through the
+transformation every time. Note that this is differentiated from a mirror with a transformation
+by the existance of extra text between the : and the
+transformation's $. If you don't want this extra-text, you can use
+two $'s instead. Please note that as soon as a transformation takes place, it changes
+the value of the field and sets it its internal modification state to
+true. As a consequence, the auto-deletion behaviour of normal
+fields does not take place. This is by design. As mentioned, the field transformation is invoked just after you enter
+the field, and with some useful variables bound, notably
+yas/field-modified-p and yas/moving-away-p. Because of this
+feature you can place a transformation in the primary field that lets
+you select default values for it. The yas/choose-value does this work for you. For example: See the definition of yas/choose-value to see how it was written
+using the two variables. Also check out yas/verify-value for
+another neat trick. From version 0.6 on, you can also have nested placeholders of the type: This allows you to choose if you want to give this div an id
+attribute. If you tab forward after expanding it will let you change
+"some_id" to whatever you like. Alternatively, you can just press
+C-d (which executes yas/skip-and-clear-or-delete-char) and go
+straight to the exit marker. By the way, C-d will only clear the field if you cursor is at the
+beginning of the field and it hasn't been changed yet. Otherwise, it
+performs the normal Emacs delete-char command. Many people miss the indenting feature of smart-snippet: when you
place a $> in your snippet, an (indent-according-to-mode) will
be executed there to indent the line. So you'll not need to hard-code
@@ -747,6 +884,9 @@ this to YASnippet. Here's an example of the usage: In 0.6.0 You should not need to use this feature although it's
+supported for backward compatibility. Just set yas/indent-line to
+'auto. where the-major-mode is the major mode in which yas/minor-mode
isn't enabled by default. From YASnippet 0.6 you can also use the command M-x
+yas/global-mode to turn on YASnippet automatically for all major
+modes. If yas/minor-mode is on but the snippet still not expanded. Then
try to see what command is bound to the TAB key: press C-h k
and then press TAB. Emacs will show you the result. Yasnippet is a template system for emacs. It allows you to type a
@@ -107,11 +108,24 @@ following in your .emacs
(yas/load-directory "~/.emacs.d/plugins/yasnippet/snippets")
- Please refer to the documentation for full customization. Please refer to the documentation for full customization, or use the
+customization group. From version 0.6 onwards, there is a customization group that you can
+access with: M-x customize-group RET yasnippet RET Each customization variable affects how some part of YASnippet works,
+for example automatic snippet indentation, what prompting method to
+use, whether to expand snippets inside snippets, etc... Inside the customization group, each variable is reasonably documented
+to explain what it does.
-
-
-Currently there're three solution come with YASnippet.
+(setq yas/prompt-functions '(yas/x-prompt yas/dropdown-prompt))
+
-
Popup Menu
-Use the X window system
+
Just select the first one
-Use built-in Emacs selection methods
+Use a dropdown-menu.el
+Use dropdown-menu.el
+
(setq yas/window-system-popup-function
@@ -492,17 +548,18 @@ way for selecting multiple candidates.
The Trigger Key
+The Trigger Key
The Minor Mode
+The Minor Mode
The Fallback
+The Fallback
Integration with hippie-expand
+Integration with hippie-expand
Other way to select a snippet
+Other way to select a snippet
yas/insert-snippet
+The Menu
+The Menu
Expanding From Elisp Code
+Expanding From Elisp Code
The Syntax of the Template
+The Syntax of the Template
Plain Text
+Plain Text
Embedded elisp code
+Embedded elisp code
for ($1;$2;$3) {
+ `yas/selected-text`$0
+}
+
Tab Stops
+Tab stop fields
Placeholders
+Placeholder fields
${N:default value}
@@ -649,7 +732,7 @@ typing. The number can be omitted if you don't want to create
mirrors or transformations for this field.
Mirrors
+Mirrors
Transformations
+Mirrors with transformations
+
-[1] With some minor change, mainly for fixing some trivial bugs.
+
-[2] This is done when you call yas/initialize.
+
+[3] Of course, this can be customized. Fields with transformations
+#define "${1:mydefine$(upcase yas/text)}"
+
#define "${1:$$(upcase yas/text)}"
+
Choosing fields value from a list
+<div align="${2:$$(yas/choose-value '("right" "center" "left"))}">
+ $0
+</div>
+
Nested placeholder fields
+<div${1: id="${2:some_id}"}>$0</div>
+
Indenting
+Indenting
(setq yas/extra-mode-hooks '(the-major-mode))
+
(add-hook 'the-major-mode-hook 'yas/minor-mode-on)
+
Customization group
+Bugs, Contribution and Support
+Bugs, Contribution and Support