[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dict-tree 3a4d3f1 015/154: Added dictree-mapcar functio
From: |
Stefan Monnier |
Subject: |
[elpa] externals/dict-tree 3a4d3f1 015/154: Added dictree-mapcar function; code tidying. |
Date: |
Mon, 14 Dec 2020 12:21:35 -0500 (EST) |
branch: externals/dict-tree
commit 3a4d3f1311868df613f6964e758cea280adf2c25
Author: Toby Cubitt <toby-predictive@dr-qubit.org>
Commit: tsc25 <toby-predictive@dr-qubit.org>
Added dictree-mapcar function; code tidying.
---
dict-tree.el | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 57 insertions(+), 8 deletions(-)
diff --git a/dict-tree.el b/dict-tree.el
index cc6e741..ae6f5fb 100644
--- a/dict-tree.el
+++ b/dict-tree.el
@@ -170,7 +170,7 @@
;;; Code:
-(provide 'dict-tree)
+(eval-when-compile (require 'cl))
(require 'trie)
(require 'bytecomp)
@@ -755,7 +755,7 @@ should return a combined data.
The other arguments are as for `dictree-create'."
;; sadly, passing null values over-rides the defaults in the defstruct
- ;; dictree--create, so we have to explicitly set the defaults again here
+ ;; `dictree--create', so we have to explicitly set the defaults again here
(or name (setq name (and filename (file-name-sans-extension
(file-name-nondirectory filename)))))
(or combine-function (setq combine-function '+))
@@ -777,6 +777,13 @@ The other arguments are as for `dictree-create'."
(unless unlisted
(push dict dictree-loaded-list)
(provide name))
+ ;; update meta-dict-list cells of constituent dictionaries
+ (mapc
+ (lambda (dic)
+ (if (symbolp dic) (setq dic (eval dic)))
+ (setf (dictree--meta-dict-list dic)
+ (cons dict (dictree--meta-dict-list dic))))
+ dictionary-list)
dict))
@@ -1373,12 +1380,40 @@ descending order if REVERSE is non-nil."
+(defun dictree-mapcar (function dict &optional type reverse)
+ "Apply FUNCTION to all entries in dictionary DICT,
+and make a list of the results.
+
+FUNCTION should take two arguments: a key sequence from the
+dictionary and its associated data.
+
+Optional argument TYPE (one of the symbols vector, lisp or
+string; defaults to vector) sets the type of sequence passed to
+FUNCTION. If TYPE is 'string, it must be possible to apply the
+function `string' to the individual elements of key sequences
+stored in DICT.
+
+The FUNCTION will be applied and the results combined in
+asscending \"lexical\" order (i.e. the order defined by the
+dictionary's comparison function; cf. `dictree-create'), or
+descending order if REVERSE is non-nil.
+
+Note that if you don't care about the order in which FUNCTION is
+applied, just that the resulting list is in the correct order,
+then
+
+ (trie-mapf function 'cons trie type (not reverse))
+
+is more efficient."
+ (nreverse (dictree-mapf function 'cons dict type)))
+
+
+
(defun dictree-size (dict)
"Return the number of entries in dictionary DICT."
(interactive (list (read-dict "Dictionary: ")))
(let ((count 0))
- (dictree-mapc (lambda (&rest dummy) (incf count))
- (dictree--trie dict))
+ (dictree-mapc (lambda (&rest dummy) (incf count)) dict)
(when (interactive-p)
(message "Dictionary %s contains %d entries"
(dictree--name dict) count))
@@ -1979,6 +2014,15 @@ NOT be saved even if its autosave flag is set."
(dictree-save dict)
(setf (dictree-modified dict) nil))
+ ;; if unloading a meta-dict, remove reference to it from constituent
+ ;; dictionaries' meta-dict-list cell
+ (when (dictree--meta-dict-p dict)
+ (mapc
+ (lambda (dic)
+ (setf (dictree--meta-dict-list dic)
+ (delq dict (dictree--meta-dict-list dic))))
+ (dictree--meta-dict-dictlist dict)))
+
;; remove dictionary from list of loaded dictionaries and unload it
(setq dictree-loaded-list (delq dict dictree-loaded-list))
(unintern (dictree-name dict))
@@ -2309,7 +2353,7 @@ giving it the name DICTNAME."
(setf (dictree--meta-dict-list tmpdict) nil)
;; write lisp code that generates the dictionary object
- (insert "(provide '" dictname ")\n")
+ (insert "(eval-when-compile (require 'cl))\n")
(insert "(require 'dict-tree)\n")
(insert "(defvar " dictname " nil \"Dictionary " dictname ".\")\n")
(insert "(setq " dictname " '" (prin1-to-string tmpdict) ")\n")
@@ -2317,7 +2361,8 @@ giving it the name DICTNAME."
(insert "(setf (dictree-filename " dictname ")"
" (locate-library \"" dictname "\"))\n")
(insert "(unless (memq " dictname " dictree-loaded-list)"
- " (push " dictname " dictree-loaded-list))\n")))
+ " (push " dictname " dictree-loaded-list))\n")
+ (insert "(provide '" dictname ")\n")))
@@ -2412,7 +2457,7 @@ giving it the name DICTNAME."
(setf (dictree--meta-dict-meta-dict-list tmpdict) nil)
;; write lisp code that generates the dictionary object
- (insert "(provide '" dictname ")\n")
+ (insert "(eval-when-compile (require 'cl))\n")
(insert "(require 'dict-tree)\n")
(mapc (lambda (name) (insert "(require '" name ")\n"))
(dictree--meta-dict-dictlist tmpdict))
@@ -2426,7 +2471,8 @@ giving it the name DICTNAME."
(insert "(setf (dictree-filename " dictname ")"
" (locate-library \"" dictname "\"))\n")
(insert "(unless (memq " dictname " dictree-loaded-list)"
- " (push " dictname " dictree-loaded-list))\n")))
+ " (push " dictname " dictree-loaded-list))\n")
+ (insert "(provide '" dictname ")\n")))
@@ -2454,4 +2500,7 @@ supplied, only complete on dictionaries in that list."
nil t nil 'dictree-history default)))))
+
+(provide 'dict-tree)
+
;;; dict-tree.el ends here
- [elpa] externals/dict-tree 238fd6b 082/154: Fixed bug in dictree--merge that caused one too many completions to be cached., (continued)
- [elpa] externals/dict-tree 238fd6b 082/154: Fixed bug in dictree--merge that caused one too many completions to be cached., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree a256974 086/154: Minor typo-fixes in docstrings., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree d6ea2b5 088/154: Fixed interactive argument handling in predictive-fast-learn-from-buffer., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 39ace6f 094/154: Added autoload cookies., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree a1bff31 096/154: Trivial whitespace tidying., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree e752b53 101/154: Accept symbols for dictionary arguments., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 8aa6047 106/154: Suppress bogus unused lexical variable byte-compiler warnings., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 4b3cc3c 122/154: Do lexbind test at compile-time instead of load-time., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree a4b2a1b 126/154: Improve edebug pretty-printing., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree b7173e8 152/154: Fix lexical binding bugs., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 3a4d3f1 015/154: Added dictree-mapcar function; code tidying.,
Stefan Monnier <=
- [elpa] externals/dict-tree 1dde6e1 030/154: Define missing setf methods for data cells, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 3969702 125/154: Tidy up unnecessary macros by making them into defsubst or defun., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 74c792c 111/154: Add page breaks., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 5cf96da 123/154: Implement iterator generators on collection data structures., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 913c84b 129/154: Fix bug in dictree-unload., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 1e5b3f6 130/154: Fix bug in dictree--wrap-fuzzy-rankfun wrapping., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 6544152 139/154: Fix bug causing dictree--do-query to fail to use cached results., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 9242ff7 154/154: * dict-tree/dict-tree.el: Fix typo in Package-Requires., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 1d096b1 141/154: Myriad bug fixes and code refactoring in new fuzzy and ngram completion., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 572c746 149/154: Fix byte-compilation errors and warnings., Stefan Monnier, 2020/12/14