Added yas/substr for convenient mirror transformation

This commit is contained in:
Zhang Chiyuan 2008-12-12 05:42:53 +00:00
parent 1c0d664d65
commit acf04d6952
2 changed files with 16 additions and 2 deletions

View File

@ -3,6 +3,6 @@
class ${1:Name}
{
public:
$1($2);
virtual ~$1();
${1:$(yas/substr text "[^:]*")}($2);
virtual ~${1:$(yas/substr text "[^:]*")}();
};

View File

@ -185,6 +185,20 @@ to expand.
YASnippet and call other command bound to `yas/trigger-key'.
* 'return-nil means return nil.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Utility functions for transformations
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun yas/substr (str pattern &optional group)
"Search PATTERN in STR. If found, the content of group
GROUP (default 0) is returned, or else the original STR will be
returned."
(let ((grp (or group 0)))
(save-match-data
(if (string-match pattern str)
(match-string-no-properties grp str)
str))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Internal variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;