From acf04d695262e920d5aca9a6715959aeb3bc2963 Mon Sep 17 00:00:00 2001 From: Zhang Chiyuan Date: Fri, 12 Dec 2008 05:42:53 +0000 Subject: [PATCH] Added yas/substr for convenient mirror transformation --- snippets/text-mode/cc-mode/c++-mode/class | 4 ++-- yasnippet.el | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/snippets/text-mode/cc-mode/c++-mode/class b/snippets/text-mode/cc-mode/c++-mode/class index e4a7032..68377b5 100644 --- a/snippets/text-mode/cc-mode/c++-mode/class +++ b/snippets/text-mode/cc-mode/c++-mode/class @@ -3,6 +3,6 @@ class ${1:Name} { public: - $1($2); - virtual ~$1(); + ${1:$(yas/substr text "[^:]*")}($2); + virtual ~${1:$(yas/substr text "[^:]*")}(); }; \ No newline at end of file diff --git a/yasnippet.el b/yasnippet.el index 3214cb7..55a1fa2 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;