emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 3129040 24/40: Load snippet after saving


From: Noam Postavsky
Subject: [elpa] master 3129040 24/40: Load snippet after saving
Date: Wed, 26 Oct 2016 23:06:33 +0000 (UTC)

branch: master
commit 3129040fe362a6896a3d4665778728e13cd8fbfd
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]