[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 205b0e6 023/177: move snippet saving from loading to closi
From: |
João Távora |
Subject: |
[elpa] master 205b0e6 023/177: move snippet saving from loading to closing |
Date: |
Sat, 28 Mar 2015 15:40:33 +0000 |
branch: master
commit 205b0e697055d8dd92366da8ba0963e350ad7817
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
move snippet saving from loading to closing
yas-load-snippet-buffer now just loads the snippet,
yas-load-snippet-buffer-and-close also saves it.
---
yasnippet.el | 81 ++++++++++++++++++++++++++++-----------------------------
1 files changed, 40 insertions(+), 41 deletions(-)
diff --git a/yasnippet.el b/yasnippet.el
index 5d0d90a..19c6a5a 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -2527,10 +2527,7 @@ neither do the elements of PARENTS."
TABLE is a symbol naming a passed to `yas--table-get-create'.
-When called interactively, prompt for the table name and
-whether (and where) to save the snippet.
-
-Returns the name of the file saved (if any)."
+When called interactively, prompt for the table name."
(interactive (list (yas--read-table) t))
(cond
;; We have `yas--editing-template', this buffer's content comes from a
@@ -2549,43 +2546,45 @@ Returns the name of the file saved (if any)."
(set (make-local-variable 'yas--editing-template)
(yas--define-snippets-1 (yas--parse-template buffer-file-name)
table)))))
-
- (prog1
- (when (and interactive
- (or
- ;; Only offer to save this if it looks like a library or new
- ;; snippet (loaded from elisp, from a dir in
`yas-snippet-dirs'
- ;; which is not the first, or from an unwritable file)
- ;;
- (not (yas--template-file yas--editing-template))
- (not (file-writable-p (yas--template-file
yas--editing-template)))
- (and (listp yas-snippet-dirs)
- (second yas-snippet-dirs)
- (not (string-match (expand-file-name (first
yas-snippet-dirs))
- (yas--template-file
yas--editing-template)))))
- (y-or-n-p (yas--format "Looks like a library or new snippet.
Save to new file? ")))
- (let* ((option (first (yas--guess-snippet-directories
(yas--template-table yas--editing-template))))
- (chosen (and option
- (yas--make-directory-maybe option))))
- (when chosen
- (let ((default-file-name (or (and (yas--template-file
yas--editing-template)
- (file-name-nondirectory
(yas--template-file yas--editing-template)))
- (yas--template-name
yas--editing-template))))
- (write-file (concat chosen "/"
- (read-from-minibuffer (format "File name to
create in %s? " chosen)
- default-file-name)))
- (setf (yas--template-file yas--editing-template)
buffer-file-name)))))
- (when interactive
- (yas--message 3 "Snippet \"%s\" loaded for %s."
- (yas--template-name yas--editing-template)
- (yas--table-name (yas--template-table
yas--editing-template))))))
-
-(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)))
+ (when interactive
+ (yas--message 3 "Snippet \"%s\" loaded for %s."
+ (yas--template-name yas--editing-template)
+ (yas--table-name (yas--template-table
yas--editing-template)))))
+
+(defun yas-load-snippet-buffer-and-close (table &optional kill)
+ "Load the snippet with `yas-load-snippet-buffer', offer to
+ save, then `quit-window' if saved.
+
+The prefix argument KILL is passed to `quit-window'.
+
+Don't use this from a Lisp program, call `yas-load-snippet-buffer'
+and `kill-buffer' instead."
+ (interactive (list (yas--read-table) current-prefix-arg))
+ (yas-load-snippet-buffer table t)
+ (when (and (or
+ ;; Only offer to save this if it looks like a library or new
+ ;; snippet (loaded from elisp, from a dir in `yas-snippet-dirs'
+ ;; which is not the first, or from an unwritable file)
+ ;;
+ (not (yas--template-file yas--editing-template))
+ (not (file-writable-p (yas--template-file
yas--editing-template)))
+ (and (listp yas-snippet-dirs)
+ (second yas-snippet-dirs)
+ (not (string-match (expand-file-name (first
yas-snippet-dirs))
+ (yas--template-file
yas--editing-template)))))
+ (y-or-n-p (yas--format "Looks like a library or new snippet. Save
to new file? ")))
+ (let* ((option (first (yas--guess-snippet-directories (yas--template-table
yas--editing-template))))
+ (chosen (and option
+ (yas--make-directory-maybe option))))
+ (when chosen
+ (let ((default-file-name (or (and (yas--template-file
yas--editing-template)
+ (file-name-nondirectory
(yas--template-file yas--editing-template)))
+ (yas--template-name
yas--editing-template))))
+ (write-file (concat chosen "/"
+ (read-from-minibuffer (format "File name to
create in %s? " chosen)
+ default-file-name)))
+ (setf (yas--template-file yas--editing-template) buffer-file-name)
+ (quit-window kill))))))
(defun yas-tryout-snippet (&optional debug)
"Test current buffer's snippet template in other buffer."
- [elpa] master 90d4cae 013/177: inhibit change hooks during (insert content), (continued)
- [elpa] master 90d4cae 013/177: inhibit change hooks during (insert content), João Távora, 2015/03/28
- [elpa] master 7849ffc 015/177: fix: don't use universal-argument-num-events, João Távora, 2015/03/28
- [elpa] master 6997922 016/177: Revert "inhibit change hooks during (insert content)", João Távora, 2015/03/28
- [elpa] master 6268cc2 014/177: add: test for issue #404, João Távora, 2015/03/28
- [elpa] master 5c76a0f 019/177: test middle-of-buffer snippet insertion, João Távora, 2015/03/28
- [elpa] master 51e9e8e 017/177: wait till after content insertion to narrow, João Távora, 2015/03/28
- [elpa] master 3bb1515 018/177: Merge pull request #409 from npostavs/font-lock, João Távora, 2015/03/28
- [elpa] master 6c3e029 020/177: Merge pull request #412 from npostavs/less-narrow, João Távora, 2015/03/28
- [elpa] master 32ee5cb 021/177: Closes #415: remove c-specific hacks, harmful on emacs 24.3, João Távora, 2015/03/28
- [elpa] master ffd497d 022/177: don't kill snippet buffer unless saved, João Távora, 2015/03/28
- [elpa] master 205b0e6 023/177: move snippet saving from loading to closing,
João Távora <=
- [elpa] master 33dff9a 024/177: let C-c C-c save existing snippets too, João Távora, 2015/03/28
- [elpa] master d7b2b89 027/177: widen before deleting regions, João Távora, 2015/03/28
- [elpa] master 84b7e69 025/177: Merge pull request #423 from npostavs/load-snippet-ui, João Távora, 2015/03/28
- [elpa] master 43a484e 028/177: add: external test for issue #404, João Távora, 2015/03/28
- [elpa] master d5d6e45 026/177: Feature: de/activate-extra-mode, João Távora, 2015/03/28
- [elpa] master 6ee3d2e 029/177: Closes #404: merge remote-tracking branch 'npostavs/widen', João Távora, 2015/03/28
- [elpa] master a4a7e5e 032/177: fix typo: .yas.parents -> .yas-parents, João Távora, 2015/03/28
- [elpa] master fdd550a 035/177: Fix screencast link., João Távora, 2015/03/28
- [elpa] master bc4cfbb 033/177: yas/ -> yas-, João Távora, 2015/03/28
- [elpa] master b20f0a4 034/177: fix exporting of doc strings for org manual, João Távora, 2015/03/28