branch: externals/tempel commit 662b99d33d0990eb1bf6541ecd1f7329c5575ca5 Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
tempel-path: Use wildcards instead of directories (Fix #51) --- README.org | 12 ++++++------ tempel.el | 32 +++++++++++++------------------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/README.org b/README.org index bbb1783e45..16dc5f11f2 100644 --- a/README.org +++ b/README.org @@ -102,12 +102,12 @@ on =use-package=. * Template file format The templates are defined in a Lisp file configured by ~tempel-path~. By default -the file or directory =~/.config/emacs/templates= is used. The templates are -grouped by major mode with an optional ~:condition~. Each template is a list in -the concise form of the Emacs Tempo syntax. The first element of each list is -the name of the template. Behind the name, the Tempo syntax elements follow. -Pre- and post-expansion operations can be specified per template by the optional -keys =:pre= and =:post=. +the file =~/.config/emacs/templates= is used. The templates are grouped by major +mode with an optional ~:condition~. Each template is a list in the concise form of +the Emacs Tempo syntax. The first element of each list is the name of the +template. Behind the name, the Tempo syntax elements follow. Pre- and +post-expansion operations can be specified per template by the optional keys +=:pre= and =:post=. #+begin_src emacs-lisp ;; -*- mode: lisp-data -*- diff --git a/tempel.el b/tempel.el index 8135d6730b..a1b9bc53c8 100644 --- a/tempel.el +++ b/tempel.el @@ -49,7 +49,8 @@ :prefix "tempel-") (defcustom tempel-path (expand-file-name "templates" user-emacs-directory) - "A file or a list of files and/or directories, containing templates." + "A file or a list of files containing templates. +The file paths can contain wildcards." :type '(choice string (repeat string))) (defcustom tempel-trigger-prefix nil @@ -160,16 +161,6 @@ may be named with `tempel--name' or carry an evaluatable Lisp expression ((or 'n 'n> '> '& '% 'o) " ") (_ "_"))) -(defun tempel--expand-path () - "Return the list of files specified by `tempel-path'." - (let (files) - (dolist (path (if (listp tempel-path) tempel-path (list tempel-path))) - (when (file-exists-p path) - (if (file-directory-p path) - (setq files (nconc files (directory-files-recursively path ""))) - (push path files)))) - files)) - (defun tempel--annotate (templates width ellipsis sep name) "Annotate template NAME given the list of TEMPLATES. WIDTH, SEP and ELLIPSIS configure the formatting." @@ -439,14 +430,17 @@ PROMPT is the optional prompt/default value." Additionally, save any files in `tempel-template-sources' that have been modified since the last time this function was called. This is meant to be a source in `tempel-template-sources'." - (when tempel-auto-reload - (let* ((files (tempel--expand-path)) - (timestamps (cl-loop - for f in files collect - (cons f (time-convert - (file-attribute-modification-time - (file-attributes f)) - 'integer))))) + (when (or (not tempel--path-templates) tempel-auto-reload) + (let* ((files + (cl-loop for path in (if (listp tempel-path) tempel-path (list tempel-path)) + nconc (file-expand-wildcards path t))) + (timestamps + (cl-loop + for f in files collect + (cons f (time-convert + (file-attribute-modification-time + (file-attributes f)) + 'integer))))) (unless (equal tempel--path-timestamps timestamps) (setq tempel--path-timestamps timestamps tempel--path-templates (mapcan #'tempel--file-read files)))))