I updated smart-snippet.el today. There're main two changes:
- The code is merged with
snippet.el. - Now you can use \ to escape and protect a character that might else be recognized as a snippet identifier.
Originally smart-snippet.el is based on snippet.el as a simple wrap. Bug I need to do some modification to the code frequently for enhancement or bug fix. So I decide to include the code of snippet.el in smart-snippet.el. Now I'll call smart-snippet.el a fork of snippet.el. Now you need only one single file -- the smart-snippet.el.
The escape character enhancement is from the need of a perl user. Perl uses a lot of punctuations, including the default snippet identifier $. The $ from Perl code and $ to build snippet may confuse Emacs. For example, suppose you are defining a snippet which will expand into:
foreach my $key (keys %HASH) {
$value = $HASH{$key};
# do something
}
You may want to define it like this:
(require 'cperl-mode)
(smart-snippet-with-abbrev-tables
(cperl-mode-abbrev-table)
("fh" "foreach my $key (keys %$${HASH}) {
$>$value = $$${HASH}{$key};
$>$. # do something
}$>"
'bol?))
The $$${HASH} in line 5 should be parsed as $ and $${HASH}, but in fact it is parsed as $$ and ${HASH} which is not what we want. How to protect the first $ ? Now with the new version of smart-snippet.el you can use \ to protect the following character:
(cperl-mode-abbrev-table)
("fh" "foreach my $key (keys %$${HASH}) {
$>$value = \\$$${HASH}{$key};
$>$. # do something
}$>"
'bol?))
Note the \ itself need to be escaped in a string, so we should write \\ in fact. Wish you enjoy it!
No comments.