don't kill snippet buffer unless saved

Split the quit-window part of yas-load-snippet-buffer into
yas-load-snippet-buffer-and-close, and only quit if the snippet was
saved.

This resolves #417, where you could lose a snippet by giving the wrong
answer in a prompt.
This commit is contained in:
Noam Postavsky 2013-10-26 12:11:04 -04:00
parent 32ee5cbde5
commit ffd497d541

View File

@ -837,7 +837,8 @@ Honour `yas-dont-activate', which see."
(when (third ent) (when (third ent)
(define-key map (third ent) (second ent))) (define-key map (third ent) (second ent)))
(vector (first ent) (second ent) t)) (vector (first ent) (second ent) t))
'(("Load this snippet" yas-load-snippet-buffer "\C-c\C-c") '(("Load this snippet" yas-load-snippet-buffer "\C-c\C-l")
("Load and quit window" yas-load-snippet-buffer-and-close "\C-c\C-c")
("Try out this snippet" yas-tryout-snippet "\C-c\C-t"))))) ("Try out this snippet" yas-tryout-snippet "\C-c\C-t")))))
map) map)
"The keymap used when `snippet-mode' is active.") "The keymap used when `snippet-mode' is active.")
@ -2527,7 +2528,9 @@ neither do the elements of PARENTS."
TABLE is a symbol naming a passed to `yas--table-get-create'. TABLE is a symbol naming a passed to `yas--table-get-create'.
When called interactively, prompt for the table name and When called interactively, prompt for the table name and
whether (and where) to save the snippet, then quit the window." whether (and where) to save the snippet.
Returns the name of the file saved (if any)."
(interactive (list (yas--read-table) t)) (interactive (list (yas--read-table) t))
(cond (cond
;; We have `yas--editing-template', this buffer's content comes from a ;; We have `yas--editing-template', this buffer's content comes from a
@ -2547,6 +2550,7 @@ whether (and where) to save the snippet, then quit the window."
(yas--define-snippets-1 (yas--parse-template buffer-file-name) (yas--define-snippets-1 (yas--parse-template buffer-file-name)
table))))) table)))))
(prog1
(when (and interactive (when (and interactive
(or (or
;; Only offer to save this if it looks like a library or new ;; Only offer to save this if it looks like a library or new
@ -2574,8 +2578,14 @@ whether (and where) to save the snippet, then quit the window."
(when interactive (when interactive
(yas--message 3 "Snippet \"%s\" loaded for %s." (yas--message 3 "Snippet \"%s\" loaded for %s."
(yas--template-name yas--editing-template) (yas--template-name yas--editing-template)
(yas--table-name (yas--template-table yas--editing-template))) (yas--table-name (yas--template-table yas--editing-template))))))
(quit-window interactive)))
(defun yas-load-snippet-buffer-and-close (table &optional kill interactive)
"Call `yas-load-snippet-buffer' and then `quit-window', prefix
argument KILL passed to `quit-window'."
(interactive (list (yas--read-table) current-prefix-arg t))
(and (yas-load-snippet-buffer table interactive)
(quit-window kill)))
(defun yas-tryout-snippet (&optional debug) (defun yas-tryout-snippet (&optional debug)
"Test current buffer's snippet template in other buffer." "Test current buffer's snippet template in other buffer."