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.
This commit is contained in:
parent
8c8fa18857
commit
d760772a9a
1 changed files with 10 additions and 4 deletions
|
@ -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))))
|
||||
|
|
Loading…
Reference in a new issue