[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dict-tree 5e2ffac 136/154: Test for lexical binding mus
From: |
Stefan Monnier |
Subject: |
[elpa] externals/dict-tree 5e2ffac 136/154: Test for lexical binding must be within same file to work reliably. |
Date: |
Mon, 14 Dec 2020 12:22:01 -0500 (EST) |
branch: externals/dict-tree
commit 5e2ffac89b97066464c880e77e54c8c95d09efbc
Author: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Commit: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Test for lexical binding must be within same file to work reliably.
---
dict-tree.el | 48 ++++++++++++++++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 14 deletions(-)
diff --git a/dict-tree.el b/dict-tree.el
index 4fc9912..bb745db 100644
--- a/dict-tree.el
+++ b/dict-tree.el
@@ -135,6 +135,16 @@ If START or END is negative, it counts from the end."
(forward-line (1- line))))
+(defmacro dictree--if-lexical-binding (then else)
+ "If lexical binding is in effect, evaluate THEN, otherwise ELSE."
+ (declare (indent 1) (debug t))
+ (if (let ((tempvar nil)
+ (f (let ((tempvar t)) (lambda () tempvar))))
+ tempvar ;; shut up "unused lexical variable" byte-compiler warning
+ (funcall f))
+ then else))
+
+
;;; ====================================================================
@@ -210,7 +220,7 @@ If START or END is negative, it counts from the end."
;; Wrapping functions
;; return wrapped insfun to deal with data wrapping
-(trie--if-lexical-binding
+(dictree--if-lexical-binding
(defun dictree--wrap-insfun (insfun) ; INTERNAL USE ONLY
(lambda (new old)
(dictree--cell-set-data old (funcall insfun
@@ -225,7 +235,7 @@ If START or END is negative, it counts from the end."
;; return wrapped rankfun to deal with data wrapping
-(trie--if-lexical-binding
+(dictree--if-lexical-binding
(defun dictree--wrap-rankfun (rankfun) ; INTERNAL USE ONLY
(lambda (a b)
(funcall rankfun
@@ -238,7 +248,7 @@ If START or END is negative, it counts from the end."
;; return wrapped rankfun to ignore regexp grouping data
-(trie--if-lexical-binding
+(dictree--if-lexical-binding
(defun dictree--wrap-regexp-rankfun (rankfun)
(lambda (a b)
;; if car of argument contains a key+group list rather than a straight
@@ -273,7 +283,7 @@ If START or END is negative, it counts from the end."
(,rankfun a b))))
;; return wrapped sortfun to ignore regexp grouping data
-(trie--if-lexical-binding
+(dictree--if-lexical-binding
(defun dictree--wrap-regexp-sortfun (cmpfun &optional reverse)
(let ((sortfun (trie-construct-sortfun cmpfun reverse)))
(lambda (a b)
@@ -311,7 +321,7 @@ If START or END is negative, it counts from the end."
;; return wrapped rankfun to ignore fuzzy query distance data
-(trie--if-lexical-binding
+(dictree--if-lexical-binding
(defun dictree--wrap-fuzzy-rankfun (rankfun) ; INTERNAL USE ONLY
(lambda (a b)
(funcall rankfun
@@ -323,7 +333,7 @@ If START or END is negative, it counts from the end."
(cons (car b) (dictree--cell-data (cdr b)))))))
;; return wrapped sortfun to ignore fuzzy query distance data
-(trie--if-lexical-binding
+(dictree--if-lexical-binding
(defun dictree--wrap-fuzzy-sortfun (cmpfun &optional reverse)
(let ((sortfun (trie-construct-sortfun cmpfun reverse)))
(lambda (a b) (funcall sortfun (car a) (car b)))))
@@ -333,7 +343,7 @@ If START or END is negative, it counts from the end."
;; return wrapped combfun to deal with data wrapping
-(trie--if-lexical-binding
+(dictree--if-lexical-binding
(defun dictree--wrap-combfun (combfun) ; INTERNAL USE ONLY
(lambda (cell1 cell2)
(dictree--cell-create
@@ -352,7 +362,7 @@ If START or END is negative, it counts from the end."
;; return wrapped filter function to deal with data wrapping
-(trie--if-lexical-binding
+(dictree--if-lexical-binding
(defun dictree--wrap-filter (filter) ; INTERNAL USE ONLY
(lambda (key data) (funcall filter key (dictree--cell-data data))))
(defun dictree--wrap-filter (filter) ; INTERNAL USE ONLY
@@ -360,7 +370,7 @@ If START or END is negative, it counts from the end."
;; return wrapped result function to deal with data wrapping
-(trie--if-lexical-binding
+(dictree--if-lexical-binding
(defun dictree--wrap-resultfun (resultfun) ; INTERNAL USE ONLY
(lambda (res)
(funcall resultfun (car res) (dictree--cell-data (cdr res)))))
@@ -369,7 +379,7 @@ If START or END is negative, it counts from the end."
;; construct lexicographic sort function from DICT's comparison function
-(trie--if-lexical-binding
+(dictree--if-lexical-binding
(defun dictree--construct-sortfun (dict) ; INTERNAL USE ONLY
(let ((sortfun (trie-construct-sortfun
(dictree-comparison-function dict))))
@@ -2059,7 +2069,7 @@ Interactively, DICT is read from the mini-buffer."
;; Wrap SORTFUN, which sorts keys, so it can act on dictree--meta-stack
;; elements.
-(trie--if-lexical-binding
+(dictree--if-lexical-binding
(defun dictree--construct-meta-stack-heapfun (sortfun &optional reverse)
(if reverse
(lambda (b a) (funcall sortfun (car (dictree-stack-first a))
@@ -2547,7 +2557,12 @@ to its constituent dicts."
(cond
;; if there's a cache entry with enough results, use it
- ((and (symbolp rank-function) (symbolp filter)
+ ((and (or (symbolp rank-function)
+ ;; can be '(t . rankfun) for `dictree-fuzzy-complete'
+ (and (consp rank-function)
+ (symbolp (car rank-function))
+ (symbolp (cdr rank-function))))
+ (symbolp filter)
(setq cache-entry
(when cache
(gethash (list arg auxargs rank-function reverse filter)
@@ -2563,8 +2578,7 @@ to its constituent dicts."
(setcdr (nthcdr (1- maxnum) results) nil)))
(t ;; if there was nothing useful in the cache, do query and time it
- (let (time)
- (setq time (float-time))
+ (let ((time (float-time)))
(setq res
(dictree--do-query
dic triefun stackfun arg auxargs rankfun maxnum reverse
@@ -2572,6 +2586,12 @@ to its constituent dicts."
(setq time (- (float-time) time))
;; if we're above the dictionary's cache threshold, cache the result
(when (and cachefun (not no-cache)
+ (or (symbolp rank-function)
+ ;; can be '(t . rankfun) for `dictree-fuzzy-complete'
+ (and (consp rank-function)
+ (symbolp (car rank-function))
+ (symbolp (cdr rank-function))))
+ (symbolp filter)
(dictree--above-cache-threshold-p
time (length arg) (dictree-cache-policy dic)
(dictree-cache-threshold dic) cache-long))
- [elpa] externals/dict-tree 5321c25 113/154: Implement fuzzy match and completion on dict-trees., (continued)
- [elpa] externals/dict-tree 5321c25 113/154: Implement fuzzy match and completion on dict-trees., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree d0e339d 117/154: Don't wrap rank and filter functions for regexp and fuzzy queries., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree a11f2a5 115/154: Update predictive mode to new dictree-create function interface., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 217c9d2 119/154: Updated Commentary., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 95d6a5a 127/154: Mention iterator generators in Commentary., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree d84725e 124/154: Bump version numbers since we've added iterator generators., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree f47d49c 137/154: Bug fixes to meta-dict fuzzy-matching/completing., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 65b94b4 131/154: Bump version numbers., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree c737d3a 134/154: Make use of new trie-fuzzy-complete facilities., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree eec26c3 132/154: Fix trie--construct-Lewenstein-rankfun to new versions., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 5e2ffac 136/154: Test for lexical binding must be within same file to work reliably.,
Stefan Monnier <=
- [elpa] externals/dict-tree 22d0e13 140/154: Sort completions by fuzzy dist before ngram length., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 67afade 151/154: Document PFXFILTER argument to query functions., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 4299171 150/154: Work around Emacs bug preventing dict-tree caching., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 22d569e 153/154: Improve error reporting when reading dictionary data from dumped file., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree f0af36e 148/154: Fix byte-compilation of functions embedded in dict-trees., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree dd695da 147/154: Display more informative message during writing dict to file., Stefan Monnier, 2020/12/14
- [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