From 0dc0c1db8df7a246df868518d94a1cffa89f1c66 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 25 Nov 2015 06:01:19 -0500 Subject: [PATCH] Add defuns-auto-insert.el --- core/lib/defuns-auto-insert.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 core/lib/defuns-auto-insert.el diff --git a/core/lib/defuns-auto-insert.el b/core/lib/defuns-auto-insert.el new file mode 100644 index 000000000..4d05d2d09 --- /dev/null +++ b/core/lib/defuns-auto-insert.el @@ -0,0 +1,21 @@ +;;; defuns-auto-insert.el +;; for ../core-auto-insert.el + +;;;###autoload +(defun narf/auto-insert-snippet (key &optional mode project-only) + "Auto insert a snippet of yasnippet into new file." + (interactive) + (when (if project-only (narf/project-p) t) + (let ((is-yasnippet-on (not (cond ((functionp yas-dont-activate) + (funcall yas-dont-activate)) + ((consp yas-dont-activate) + (some #'funcall yas-dont-activate)) + (yas-dont-activate)))) + (snippet (let ((template (cdar (mapcan #'(lambda (table) (yas--fetch table key)) + (yas--get-snippet-tables mode))))) + (if template (yas--template-content template) nil)))) + (when (and is-yasnippet-on snippet) + (yas-expand-snippet snippet))))) + +(provide 'defuns-auto-insert) +;;; defuns-auto-insert.el ends here