From d760772a9a3fc977c4c3e9a931d2398f600382fd Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Mon, 20 May 2013 01:02:38 +0200 Subject: [PATCH] Change variable delimiter Since the `__' is used quite a lot in, for example, Python code and files it proved to be a sub-optimal as a delimiter. Now, by default, `$!' is used, which should appear somewhat less (I hope) and it has been made customizable. Look out when customizing, it is placed in a regular expression without any escaping. --- project-template.el | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/project-template.el b/project-template.el index 889c5cd..ba4c4b8 100644 --- a/project-template.el +++ b/project-template.el @@ -1,8 +1,14 @@ (defvar pt-templates-directory "~/.emacs.d/templates" "Where templates are stored.") -(defvar pt-template-var-regexp "__\\([^_ \t\n]+\\)__" - "Regexp which identifies a variable in a template.") +(defvar pt-template-var-delimiter "$!" + "Strings used to delimit variable names.") + +(defun pt-template-var-regexp () + "Create the regexp which identifies a variable in a template." + (concat pt-template-var-delimiter + "\\([^" pt-template-var-delimiter " \t\n]+\\)" + pt-template-var-delimiter)) (defvar pt-value-alist nil "A placeholder where replacement values will be kept. This is @@ -27,7 +33,7 @@ (defun pt-parse-file-name (filename) "Parse FILENAME and replace all __variables__ with values provided by the user." - (while (string-match pt-template-var-regexp filename) + (while (string-match (pt-template-var-regexp) filename) (let* ((tpl-var (match-string 1 filename)) (replacement-value (pt-get-replacement tpl-var))) (set 'filename (replace-match (cdr replacement-value) t t @@ -43,7 +49,7 @@ provided by the user." the user." (insert-file-contents file) - (while (re-search-forward pt-template-var-regexp nil t) + (while (re-search-forward (pt-template-var-regexp) nil t) (let* ((tpl-var (match-string 1)) (replacement-value (pt-get-replacement tpl-var))) (replace-match (cdr replacement-value) t t))))