[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dict-tree 673fd2a 029/154: Abstract away the setcar use
From: |
Stefan Monnier |
Subject: |
[elpa] externals/dict-tree 673fd2a 029/154: Abstract away the setcar used to set the data component of a cell |
Date: |
Mon, 14 Dec 2020 12:21:38 -0500 (EST) |
branch: externals/dict-tree
commit 673fd2a11416c5a77e64db9ff3113f2c5d2ea6b6
Author: Toby Cubitt <toby-predictive@dr-qubit.org>
Commit: tsc25 <toby-predictive@dr-qubit.org>
Abstract away the setcar used to set the data component of a cell
in dictree--wrap-insfun into a defalias'ed accessor function; this seems the
best compromise until a solution to the setf expansion problem can be found
(see previous commit comments).
---
dict-tree.el | 69 +++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 40 insertions(+), 29 deletions(-)
diff --git a/dict-tree.el b/dict-tree.el
index 63c5eb6..bb0eca1 100644
--- a/dict-tree.el
+++ b/dict-tree.el
@@ -232,6 +232,29 @@ If START or END is negative, it counts from the end."
"Stores list of loaded dictionaries.")
+;; Note: It would be more elegant to use a defstruct for the data cells, but
+;; the problem is that the resulting setf in `dictree--wrap-insfun'
+;; won't get expanded into the cell-data accessor function at
+;; compile-time because it's burried inside a backquote construct. Not
+;; only is it inelegant to have to expand macros at run-time whenever
+;; `dictree--wrap-insfun' is called, but it also requires the 'cl-macs
+;; package to be loaded at run-time rather than just at compile-time.
+
+;; wrap data in a cons cell
+(defalias 'dictree--cell-create 'cons) ; INTERNAL USE ONLY
+
+;; get data component from data cons cell
+(defalias 'dictree--cell-data 'car) ; INTERNAL USE ONLY
+
+;; get property list component from data cons cell
+(defalias 'dictree--cell-plist 'cdr) ; INTERNAL USE ONLY
+
+;; set data component of data cons cell
+(defalias 'dictree--cell-set-data 'setcar) ; INTERNAL USE ONLY
+
+;; set property list component of data cons cell
+(defalias 'dictree--cell-set-plist 'setcdr) ; INTERNAL USE ONLY
+
;; (defstruct
;; (dictree--cell
;; :named
@@ -240,19 +263,11 @@ If START or END is negative, it counts from the end."
;; (data &optional plist)))
;; data plist)
-(defmacro dictree--cell-create (data &optional plist)
- ;; INTERNAL USE ONLY
- ;; wrap the data in a cons cell
- `(cons ,data ,plist))
-
-;; get data component from data cons cell
-(defmacro dictree--cell-data (cell) ; INTERNAL USE ONLY
- `(car ,cell))
-;; get meta-data component of data cons cell
-(defmacro dictree--cell-plist (cell) ; INTERNAL USE ONLY
- `(cdr ,cell))
+;; Note: We *could* us a defstruct for the cache entries, but for something
+;; this simple it doesn't seem worth it, especially given that we're
+;; using the defalias approach anyway for the data cells (above).
;; Construct and return a completion cache entry
(defalias 'dictree--cache-create 'cons) ; INTERNAL USE ONLY
@@ -264,11 +279,20 @@ If START or END is negative, it counts from the end."
(defalias 'dictree--cache-maxnum 'cdr) ; INTERNAL USE ONLY
;; Set the completions list for cache entry CACHE
-(defalias 'dictree--set-cache-completions 'setcar) ; INTERNAL USE ONLY
+(defalias 'dictree--cache-set-completions 'setcar) ; INTERNAL USE ONLY
;; Set the completions list for cache entry CACHE
-(defalias 'dictree--set-cache-maxnum 'setcdr) ; INTERNAL USE ONLY
+(defalias 'dictree--cache-set-maxnum 'setcdr) ; INTERNAL USE ONLY
+
+
+(defun dictree--wrap-insfun (insfun) ; INTERNAL USE ONLY
+ ;; return wrapped insfun to deal with data wrapping
+ (byte-compile
+ `(lambda (new old)
+ (dictree--cell-set-data old (,insfun (dictree--cell-data new)
+ (dictree--cell-data old)))
+ old)))
;; (defmacro dictree--wrap-insfun-2 (f-2)
;; ;; construct body of `dictree--wrap-insfun'
@@ -305,19 +329,6 @@ If START or END is negative, it counts from the end."
;; -- Toby Cubitt\n")
;; (setq buffer-read-only t)))))
-(defun dictree--wrap-insfun (insfun) ; INTERNAL USE ONLY
- ;; return wrapped insfun to deal with data wrapping
- (byte-compile
- `(lambda (new old)
- ;; FIXME: should use (setf (dictree--cell-data old) ...) here, but can't
- ;; figure out how to get that to be expanded at compile-time, to
- ;; avoid run-time dependency on 'cl package!!?!??!!!??!?!!??!!!
- ;; (The `dictree--cell-data' aren't expanded at compile-time
- ;; either, for the same reason.)
- (setcar old (,insfun (dictree--cell-data new)
- (dictree--cell-data old)))
- old)))
-
(defun dictree--wrap-rankfun (rankfun) ; INTERNAL USE ONLY
;; return wrapped rankfun to deal with data wrapping
@@ -1142,7 +1153,7 @@ TEST returns non-nil."
;; if key was modified and was not in cached result, merge it
;; into the completion list, retaining only the first maxnum
((and (not deleted) (not cmpl))
- (dictree--set-cache-completions
+ (dictree--cache-set-completions
cache
(dictree--merge
(list (cons key newdata)) completions
@@ -1194,7 +1205,7 @@ TEST returns non-nil."
;; if key was modified and was not in cached result, merge it
;; into the completion list, retaining only the first maxnum
((and (not deleted) (not cmpl))
- (dictree--set-cache-completions
+ (dictree--cache-set-completions
cache
(dictree--merge
(list (cons key newdata)) completions
@@ -1208,7 +1219,7 @@ TEST returns non-nil."
;; at end of list re-run the same query to update the cache
((and (not deleted) cmpl)
(when (dictree--meta-dict-p dict) (setcdr cmpl newdata))
- (dictree--set-cache-completions
+ (dictree--cache-set-completions
cache (sort completions (dictree-rankfun dict)))
(when (equal key (car (last completions)))
(remhash (cons prefix reverse)
- [elpa] externals/dict-tree 7b52ebd 005/154: Version 0.13.1 of the predictive completion package., (continued)
- [elpa] externals/dict-tree 7b52ebd 005/154: Version 0.13.1 of the predictive completion package., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree ac40f3c 004/154: Version 0.12.2 of the predictive completion package., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 2bca928 003/154: Version 0.12 of the predictive completion package., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 3ecd763 006/154: Added minor miscellaneous new features, mostly to predictive.el., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 26f5dd3 011/154: Work around byte-compilation and goto-line bugs., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 7562023 012/154: Make use of :family attribute of completion-tooltip-face., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree f9bf379 013/154: Complete re-write of dict-tree.el, based on new trie.el., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 329110b 018/154: Fixed bug in unranked dictree-complete., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree baa4931 028/154: Doesn't quite work - revert to breaking setf abstraction, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 5834dac 036/154: Replaced bare avl-trees, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 673fd2a 029/154: Abstract away the setcar used to set the data component of a cell,
Stefan Monnier <=
- [elpa] externals/dict-tree 2700e21 035/154: Don't compile wrapped functions explicitly, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 70f99ee 037/154: Make certain dictionary commands (mostly saving and loading) interactive again., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 35346a4 041/154: Bug-fix in dictree--write-dict-code, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 608fcd4 049/154: Bug-fix to dictree--write-dict-code, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 179c0b5 045/154: Bug-fix to messages displayed by dictree-populate-from-file, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 6b24547 052/154: Allow "]" to be included in a negated character alternatives, by placing immediately after the "[^"., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree a61f90e 053/154: Bug-fix in dictree-wildcard-search, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree b33203a 060/154: Manage loading and unloading of dictionaries automatically in predictive-mode, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 920d959 077/154: Replaced advice with cedet-edebug.el for pretty-printing, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 9946a1d 075/154: Dictionary now defaults to current dict in in most dictionary-related commands., Stefan Monnier, 2020/12/14