emacs-elpa-diffs
[Top][All Lists]
Advanced

[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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]