diff options
author | Tom Willemse | 2013-05-20 01:02:38 +0200 |
---|---|---|
committer | Tom Willemse | 2013-05-20 01:02:38 +0200 |
commit | d760772a9a3fc977c4c3e9a931d2398f600382fd (patch) | |
tree | fa44b38ba1bae4f24df09f50b2e5471567a477ca | |
parent | 8c8fa188571bba37109e3ae7664d312abcee4c77 (diff) | |
download | kaarvok-d760772a9a3fc977c4c3e9a931d2398f600382fd.tar.gz kaarvok-d760772a9a3fc977c4c3e9a931d2398f600382fd.zip |
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.
-rw-r--r-- | project-template.el | 14 |
1 files 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)))) |