feature/file-templates: new +file-templates/insert-license command

This commit is contained in:
Henrik Lissner 2018-02-17 18:41:21 -05:00
parent aa216af4d6
commit ef4962c702
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -5,3 +5,19 @@
"TODO"
(when (string-match "/modules/\\(.+\\)$" buffer-file-truename)
(match-string 1 buffer-file-truename)))
;;;###autoload
(defun +file-templates/insert-license ()
"Insert a license file template into the current file."
(interactive)
(require 'yasnippet)
(let* ((templates
(let ((yas-choose-tables-first nil) ; avoid prompts
(yas-choose-keys-first nil))
(cl-loop for tpl in (yas--all-templates (yas--get-snippet-tables 'text-mode))
for uuid = (yas--template-uuid tpl)
if (string-prefix-p "__license-" uuid)
collect (cons (string-remove-prefix "__license-" uuid) tpl))))
(uuid (yas-choose-value (mapcar #'car templates))))
(when uuid
(yas-expand-snippet (cdr (assoc uuid templates))))))