[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dict-tree 8e99e74 145/154: Allow dictree-write to write
From: |
Stefan Monnier |
Subject: |
[elpa] externals/dict-tree 8e99e74 145/154: Allow dictree-write to write dictionary under new name. |
Date: |
Mon, 14 Dec 2020 12:22:03 -0500 (EST) |
branch: externals/dict-tree
commit 8e99e745c49349575f5f026a9894f9886f9dbf00
Author: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Commit: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Allow dictree-write to write dictionary under new name.
---
dict-tree.el | 72 +++++++++++++++++++++++++++++++++---------------------------
1 file changed, 40 insertions(+), 32 deletions(-)
diff --git a/dict-tree.el b/dict-tree.el
index 25f2639..24fce6f 100644
--- a/dict-tree.el
+++ b/dict-tree.el
@@ -3199,8 +3199,8 @@ the compiled version will be created, whereas if it is
the symbol
Interactively, DICT and DIRECTORY are read from the mini-buffer,
and OVERWRITE is the prefix argument."
(interactive (list (read-dict "Dictionary: ")
- (read-directory-name
- "Write dictionary to directory: " nil "" t)
+ (read-file-name
+ "Write dictionary to file/directory: " nil "")
current-prefix-arg))
(when (symbolp dict) (setq dict (symbol-value dict)))
;; default to filename DICT was loaded from, if any
@@ -3210,41 +3210,51 @@ and OVERWRITE is the prefix argument."
(dictree-filename dict))
(setq filename (dictree-filename dict)))
((file-directory-p filename)
- (setq filename (concat filename (dictree-name dict)))))
+ (setq filename (concat filename (dictree-name dict))))
+ ((string= (substring filename -3) ".el")
+ (setq filename (substring filename 0 -3)))
+ ((string= (substring filename -4) ".elc")
+ (setq filename (substring filename 0 -4))))
(if (null filename)
(progn
(message "Dictionary %s NOT written" (dictree-name dict))
nil) ; return nil to indicate failure
- (let ((dictname (dictree-name dict))
+ (let ((dictname (file-name-sans-extension (file-name-nondirectory
filename)))
buff tmpfile)
- (save-excursion
- ;; create a temporary file
- (setq buff
- (find-file-noselect
- (setq tmpfile (make-temp-file (dictree-name dict)))))
- (set-buffer buff)
- ;; byte-compiler seems to b0rk on dos line-endings in some Emacsen
- (set-buffer-file-coding-system 'utf-8-unix)
- ;; call the appropriate write function to write the dictionary code
- (if (dictree--meta-dict-p dict)
- (dictree--write-meta-dict-code dict)
- (dictree--write-dict-code dict))
- (save-buffer)
- (kill-buffer buff))
-
- ;; prompt to overwrite if necessary
- (when (or overwrite
- (string= filename (dictree-filename dict))
+
+ ;; prompt for confirmation if necessary
+ (when (or (string= dictname (dictree-name dict))
(and
- (or (eq compilation 'compiled)
- (not (file-exists-p (concat filename ".el"))))
- (or (eq compilation 'uncompiled)
- (not (file-exists-p (concat filename ".elc")))))
- (y-or-n-p
- (format "File %s already exists. Overwrite? "
- (concat filename ".el(c)"))))
+ (y-or-n-p (format "Change dictionary name? "))
+ (or overwrite
+ (and
+ (or (eq compilation 'compiled)
+ (not (file-exists-p (concat filename ".el"))))
+ (or (eq compilation 'uncompiled)
+ (not (file-exists-p (concat filename ".elc")))))
+ (y-or-n-p
+ (format "File %s already exists. Overwrite? "
+ (concat filename ".el(c)"))))))
+ (setf (dictree-name dict) dictname)
+ (setf (dictree-filename dict) filename)
+
+ (save-excursion
+ ;; create a temporary file
+ (setq buff
+ (find-file-noselect
+ (setq tmpfile (make-temp-file dictname))))
+ (set-buffer buff)
+ ;; byte-compiler seems to b0rk on dos line-endings in some Emacsen
+ (set-buffer-file-coding-system 'utf-8-unix)
+ ;; call the appropriate write function to write the dictionary code
+ (if (dictree--meta-dict-p dict)
+ (dictree--write-meta-dict-code dict)
+ (dictree--write-dict-code dict))
+ (save-buffer)
+ (kill-buffer buff))
+
(condition-case nil
(progn
;; move the uncompiled version to its final destination
@@ -3263,9 +3273,7 @@ and OVERWRITE is the prefix argument."
(error "Error writing dictionary. Dictionary %s NOT saved"
dictname))
- (setf (dictree-modified dict) nil)
- (setf (dictree-filename dict) filename))
-
+ (setf (dictree-modified dict) nil))
(delete-file tmpfile)
(message "Dictionary %s saved to %s" dictname filename)
t) ; return t to indicate dictionary was successfully saved
- [elpa] externals/dict-tree 45270bc 144/154: Cache all queries, not just those with named function arguments., (continued)
- [elpa] externals/dict-tree 45270bc 144/154: Cache all queries, not just those with named function arguments., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 1db3424 128/154: Fix quoting of ' in one docstring., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 77f7b3a 133/154: Minor code refactoring., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 63b59a2 135/154: Implement fuzzy-completion with fixed initial prefix segment., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 4381f72 114/154: Generate caches as needed instead of at dict-tree creation., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree ad600f8 116/154: Fix data wrapping handling in fuzzy query functions., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 8d134c2 110/154: Fix bug in dictree-create with empty NAME argument., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 3c4b666 142/154: Refactored and rationalised dict saving/loading code., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree f232541 121/154: Merge updates to pretty-printy and docstring fixes from ELPA., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 97aba17 138/154: Fix bug introduced in dictree-member-p., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 8e99e74 145/154: Allow dictree-write to write dictionary under new name.,
Stefan Monnier <=
- [elpa] externals/dict-tree f572523 146/154: Refactor dictree-populate-from-file., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 3a99d02 118/154: Cache all queries, even with custom rankfun or filter., Stefan Monnier, 2020/12/14