branch: master commit 3129040fe362a6896a3d4665778728e13cd8fbfd Author: Noam Postavsky <npost...@users.sourceforge.net> Commit: Noam Postavsky <npost...@users.sourceforge.net>
Load snippet after saving * yasnippet.el (yas-maybe-load-snippet-buffer): New function. (snippet-mode): Add it to `after-save-hook'. --- yasnippet.el | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/yasnippet.el b/yasnippet.el index 33a635b..d7e780b 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -929,7 +929,8 @@ Honour `yas-dont-activate-functions', which see." (setq font-lock-defaults '(yas--font-lock-keywords)) (set (make-local-variable 'require-final-newline) nil) (set (make-local-variable 'comment-start) "#") - (set (make-local-variable 'comment-start-skip) "#+[\t ]*")) + (set (make-local-variable 'comment-start-skip) "#+[\t ]*") + (add-hook 'after-save-hook #'yas-maybe-load-snippet-buffer nil t)) @@ -2576,6 +2577,21 @@ Return the `yas--template' object created" (yas--table-name (yas--template-table yas--editing-template)))) yas--editing-template) +(defun yas-maybe-load-snippet-buffer () + "Added to `after-save-hook' in `snippet-mode'." + (let* ((mode (intern (file-name-sans-extension + (file-name-nondirectory + (directory-file-name default-directory))))) + (current-snippet + (apply #'yas--define-snippets-2 (yas--table-get-create mode) + (yas--parse-template buffer-file-name))) + (uuid (yas--template-uuid current-snippet))) + (unless (equal current-snippet + (if uuid (yas--get-template-by-uuid mode uuid) + (yas--lookup-snippet-1 + (yas--template-name current-snippet) mode))) + (yas-load-snippet-buffer mode t)))) + (defun yas-load-snippet-buffer-and-close (table &optional kill) "Load and save the snippet, then `quit-window' if saved. Loading is performed by `yas-load-snippet-buffer'. If the