[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 215ad9b 19/60: Fix #597; use SAVE-FILE to visit compiled s
From: |
João Távora |
Subject: |
[elpa] master 215ad9b 19/60: Fix #597; use SAVE-FILE to visit compiled snippets |
Date: |
Thu, 21 Jan 2016 22:35:54 +0000 |
branch: master
commit 215ad9bcf2e832be31778f026cb4f4469c7301e3
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
Fix #597; use SAVE-FILE to visit compiled snippets
Rename the existing FILE field to LOAD-FILE, and add a new SAVE-FILE to
yas--template struct. Normally they will be the same, but compiled
snippets have only SAVE-FILE because they are loaded by "compiled" code.
* yasnippet.el (yas--template): Remove field file, add load-file and
save-file.
(yas--parse-template): Update snippet-definition list in docstrings.
(yas-define-snippets): Move LOAD-FILE value to SAVE-FILE when compiling.
(yas--template-get-file): New function.
(yas--visit-snippet-file-1, yas-load-snippet-buffer,
yas-load-snippet-buffer-and-close): Use yas--template-load-file,
yas--template-save-file, or yas--template-get-file, as appropriate.
* doc/snippet-organization.org (The =.yas-compiled-snippet.el= file):
Remove caveat that is no longer relevant.
---
doc/snippet-organization.org | 8 ----
yasnippet.el | 77 ++++++++++++++++++++++++------------------
2 files changed, 44 insertions(+), 41 deletions(-)
diff --git a/doc/snippet-organization.org b/doc/snippet-organization.org
index 68ee059..04d01da 100644
--- a/doc/snippet-organization.org
+++ b/doc/snippet-organization.org
@@ -123,14 +123,6 @@
Alternatively, you may compile all directories in the list
=yas-snippet-dirs= with the =yas-recompile-all= function.
- *Caveat.* At the moment, when you try to use the
- =yas-visit-snippet-file= function to edit a compiled snippet loaded
- from a =.yas-compiled-snippets.el= file, the content of the snippet
- will be opened in a buffer, but it might not be a verbatim copy of
- your original snippet, and =yas-load-snippet-buffer-and-close=
- won't offer to save to the original snippet file. See
- [[https://github.com/capitaomorte/yasnippet/issues/597][#597]].
-
* TODO The =.yas-skip= file
** TODO
diff --git a/yasnippet.el b/yasnippet.el
index 93990ac..e580426 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -923,10 +923,11 @@ Honour `yas-dont-activate', which see."
(table
key content
&optional xname condition group
- expand-env file xkeybinding xuuid
+ expand-env load-file xkeybinding xuuid save-file
&aux
(name (or xname
- (and file (file-name-directory file))
+ (and load-file (file-name-directory load-file))
+ (and save-file (file-name-directory save-file))
key))
(keybinding (yas--read-keybinding xkeybinding))
(uuid (or xuuid name))
@@ -941,7 +942,8 @@ Honour `yas-dont-activate', which see."
name
condition
expand-env
- file
+ load-file
+ save-file
keybinding
uuid
menu-binding-pair
@@ -1406,7 +1408,7 @@ otherwise we attempt to calculate it from FILE.
Return a snippet-definition, i.e. a list
- (KEY TEMPLATE NAME CONDITION GROUP VARS FILE KEYBINDING UUID)
+ (KEY TEMPLATE NAME CONDITION GROUP VARS LOAD-FILE KEYBINDING UUID)
If the buffer contains a line of \"# --\" then the contents above
this line are ignored. Directives can set most of these with the syntax:
@@ -1633,7 +1635,7 @@ Optional PROMPT sets the prompt to use."
SNIPPETS is a list of snippet definitions, each taking the
following form
- (KEY TEMPLATE NAME CONDITION GROUP EXPAND-ENV FILE KEYBINDING UUID)
+ (KEY TEMPLATE NAME CONDITION GROUP EXPAND-ENV LOAD-FILE KEYBINDING UUID
SAVE-FILE)
Within these, only KEY and TEMPLATE are actually mandatory.
@@ -1658,10 +1660,11 @@ the current buffers contents."
(let ((print-length nil))
(insert ";;; Snippet definitions:\n;;;\n")
(dolist (snippet snippets)
- ;; We omit file because the snippet will be loaded from
- ;; the compiled file instead, so deleting or changing
- ;; the original won't have any effect.
- (setcar (nthcdr 6 snippet) nil))
+ ;; Move LOAD-FILE to SAVE-FILE because we will load from the
+ ;; compiled file, not LOAD-FILE.
+ (let ((load-file-cell (nthcdr 6 snippet)))
+ (setcdr (last snippet) (list (car load-file-cell)))
+ (setcar (nthcdr 6 snippet) nil)))
(insert (pp-to-string
`(yas-define-snippets ',mode ',snippets)))
(insert "\n\n"))
@@ -1676,6 +1679,15 @@ the current buffers contents."
;;; Loading snippets from files
+(defun yas--template-get-file (template)
+ "Return TEMPLATE's LOAD-FILE or SAVE-FILE."
+ (or (yas--template-load-file template)
+ (let ((file (yas--template-save-file template)))
+ (when file
+ (yas--message 2 "%s has no load file, use save file, %s, instead."
+ (yas--template-name template) file))
+ file)))
+
(defun yas--load-yas-setup-file (file)
(if (not yas--creating-compiled-snippets)
;; Normal case.
@@ -2346,7 +2358,7 @@ visited file in `snippet-mode'."
(defun yas--visit-snippet-file-1 (template)
"Helper for `yas-visit-snippet-file'."
- (let ((file (yas--template-file template)))
+ (let ((file (yas--template-get-file template)))
(cond ((and file (file-readable-p file))
(find-file-other-window file)
(snippet-mode)
@@ -2520,7 +2532,7 @@ When called interactively, prompt for the table name."
;; template which is already loaded and neatly positioned,...
;;
(yas--editing-template
- (yas--define-snippets-1 (yas--parse-template (yas--template-file
yas--editing-template))
+ (yas--define-snippets-1 (yas--parse-template (yas--template-load-file
yas--editing-template))
(yas--template-table yas--editing-template)))
;; Try to use `yas--guessed-modes'. If we don't have that use the
;; value from `yas--compute-major-mode-and-parents'
@@ -2550,28 +2562,27 @@ 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 (cdr-safe yas-snippet-dirs)
- (not (string-prefix-p (expand-file-name (car
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)))))
+ (let ((file (yas--template-get-file yas--editing-template)))
+ (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 file)
+ (not (file-writable-p file))
+ (and (cdr-safe yas-snippet-dirs)
+ (not (string-prefix-p (expand-file-name (car
yas-snippet-dirs)) file))))
+ (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 file (file-name-nondirectory file))
+ (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-load-file yas--editing-template)
buffer-file-name))))))
(when buffer-file-name
(save-buffer)
(quit-window kill)))
- [elpa] master 4bd3d98 16/60: Merge pull request #599 from zmwangx/snippet-compilation-doc, (continued)
- [elpa] master 4bd3d98 16/60: Merge pull request #599 from zmwangx/snippet-compilation-doc, João Távora, 2016/01/21
- [elpa] master 2f6cfef 17/60: Closes #601: updated snippets submodule, João Távora, 2016/01/21
- [elpa] master 68b0ab6 20/60: Accept documented snippet list formats, João Távora, 2016/01/21
- [elpa] master cc1c758 18/60: Reorganize snippet construction from list code, João Távora, 2016/01/21
- [elpa] master 01139a2 23/60: * yasnippet.el (yas--define-snippets-2): Use file-name-NONdirectory., João Távora, 2016/01/21
- [elpa] master 8df6a6e 25/60: Fix invalid yas-key-syntaxes element warning, João Távora, 2016/01/21
- [elpa] master 7703a55 24/60: * doc/snippet-organization.org (.yas-skip): Add info., João Távora, 2016/01/21
- [elpa] master 041821a 22/60: * yasnippet-tests.el (string-suffix-p): Define for older Emacsen., João Távora, 2016/01/21
- [elpa] master fb6ec67 29/60: Fix #619; find parents for extra-modes too, João Távora, 2016/01/21
- [elpa] master 710ea4d 26/60: Update snippets module, João Távora, 2016/01/21
- [elpa] master 215ad9b 19/60: Fix #597; use SAVE-FILE to visit compiled snippets,
João Távora <=
- [elpa] master e3f03ca 21/60: Test visiting compiled snippets, João Távora, 2016/01/21
- [elpa] master e56aa6f 28/60: Build a single `explored' list., João Távora, 2016/01/21
- [elpa] master b6d924c 31/60: * yasnippet.el (yas--scan-sexps): Use ignore-errors., João Távora, 2016/01/21
- [elpa] master 00b84ce 27/60: Add (failing) yas--modes-to-activate test, João Távora, 2016/01/21
- [elpa] master 72c6c4c 32/60: Fix #618; save match data in yas--scan-sexps, João Távora, 2016/01/21
- [elpa] master ac3fe83 30/60: Merge pull request #621 from npostavs/dfs-extra-modes2, João Távora, 2016/01/21
- [elpa] master b8687bb 35/60: Avoid double snippet loading messages, João Távora, 2016/01/21
- [elpa] master 35642ac 33/60: Simplify string matching., João Távora, 2016/01/21
- [elpa] master b055f13 34/60: Fix #617; ensure point is visible before x prompt, João Távora, 2016/01/21
- [elpa] master f121645 38/60: Fix #607; avoid Emacs bug #21824, João Távora, 2016/01/21