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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/vertico 34e8897652: vertico-indexed-mode: Do not use ad


From: ELPA Syncer
Subject: [elpa] externals/vertico 34e8897652: vertico-indexed-mode: Do not use advices
Date: Thu, 2 Feb 2023 16:58:19 -0500 (EST)

branch: externals/vertico
commit 34e8897652cbbee686a9ace4cdb32782eaea223c
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    vertico-indexed-mode: Do not use advices
---
 extensions/vertico-indexed.el | 32 ++++++++++++--------------------
 vertico.el                    | 10 +++++-----
 2 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/extensions/vertico-indexed.el b/extensions/vertico-indexed.el
index 61e406bb31..747ebab1a5 100644
--- a/extensions/vertico-indexed.el
+++ b/extensions/vertico-indexed.el
@@ -50,18 +50,17 @@
 (defvar-local vertico-indexed--min 0)
 (defvar-local vertico-indexed--max 0)
 
-(defun vertico-indexed--handle-prefix (orig &rest args)
-  "Handle prefix argument before calling ORIG function with ARGS."
-  (if (and current-prefix-arg (called-interactively-p t))
-      (let ((vertico--index (+ vertico-indexed--min
-                               (- (prefix-numeric-value current-prefix-arg)
-                                  vertico-indexed-start))))
-        (if (or (< vertico--index vertico-indexed--min)
-                (> vertico--index vertico-indexed--max)
-                (= vertico--total 0))
-            (minibuffer-message "Out of range")
-          (funcall orig)))
-    (apply orig args)))
+(cl-defmethod vertico--prepare :before (&context (vertico-indexed-mode (eql 
t)))
+  (when (and prefix-arg (memq this-command vertico-indexed--commands))
+    (let ((index (+ vertico-indexed--min
+                    (- (prefix-numeric-value prefix-arg)
+                       vertico-indexed-start))))
+        (if (and (>= index vertico-indexed--min)
+                 (< index vertico-indexed--max)
+                 (/= vertico--total 0))
+            (setq vertico--index index)
+          (minibuffer-message "Out of range")
+          (setq this-command #'ignore)))))
 
 (cl-defmethod vertico--format-candidate :around
   (cand prefix suffix index start &context (vertico-indexed-mode (eql t)))
@@ -79,14 +78,7 @@
 ;;;###autoload
 (define-minor-mode vertico-indexed-mode
   "Prefix candidates with indices."
-  :global t :group 'vertico
-  ;; TODO I had forgotten that `vertico-indexed-mode' is double evil, since it
-  ;; uses advices and the forbidden function `called-interactively-p'. Find a
-  ;; better implementation which avoids these kludges.
-  (dolist (cmd vertico-indexed--commands)
-    (if vertico-indexed-mode
-        (advice-add cmd :around #'vertico-indexed--handle-prefix)
-      (advice-remove cmd #'vertico-indexed--handle-prefix))))
+  :global t :group 'vertico)
 
 (provide 'vertico-indexed)
 ;;; vertico-indexed.el ends here
diff --git a/vertico.el b/vertico.el
index f41b0710ff..460fc94428 100644
--- a/vertico.el
+++ b/vertico.el
@@ -415,11 +415,6 @@ The function is configured by BY, BSIZE, BINDEX, BPRED and 
PRED."
   "Return t if PATH is a remote path."
   (string-match-p "\\`/[^/|:]+:" (substitute-in-file-name path)))
 
-(defun vertico--prepare ()
-  "Ensure that the state is prepared before running the next command."
-  (when (and (symbolp this-command) (string-prefix-p "vertico-" (symbol-name 
this-command)))
-    (vertico--update)))
-
 (defun vertico--update (&optional interruptible)
   "Update state, optionally INTERRUPTIBLE."
   (let* ((pt (max 0 (- (point) (minibuffer-prompt-end))))
@@ -634,6 +629,11 @@ The function is configured by BY, BSIZE, BINDEX, BPRED and 
PRED."
                 (and (< dp 0) (eq vertico-resize t)))
         (window-resize nil dp nil nil 'pixelwise)))))
 
+(cl-defgeneric vertico--prepare ()
+  "Ensure that the state is prepared before running the next command."
+  (when (and (symbolp this-command) (string-prefix-p "vertico-" (symbol-name 
this-command)))
+    (vertico--update)))
+
 (cl-defgeneric vertico--setup ()
   "Setup completion UI."
   (setq vertico--input t



reply via email to

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