[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vertico 2346498e6a: Use cl-defgeneric instead of advice
From: |
ELPA Syncer |
Subject: |
[elpa] externals/vertico 2346498e6a: Use cl-defgeneric instead of advices |
Date: |
Thu, 2 Feb 2023 12:58:27 -0500 (EST) |
branch: externals/vertico
commit 2346498e6ae9e00947ac3ca6cad5def61df0ea24
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Use cl-defgeneric instead of advices
The recent discussion on emacs-devel made me reconsider advices again.
It is better to be more disciplined in avoiding them in particular if
we have better facilities at our disposal. The great thing is, we even
save some code on the way!
---
extensions/vertico-buffer.el | 14 +--
extensions/vertico-flat.el | 18 +---
extensions/vertico-grid.el | 13 +--
extensions/vertico-indexed.el | 41 ++++----
extensions/vertico-mouse.el | 18 +---
extensions/vertico-multiform.el | 9 +-
extensions/vertico-reverse.el | 13 +--
extensions/vertico-unobtrusive.el | 13 ++-
vertico.el | 192 +++++++++++++++++++-------------------
9 files changed, 146 insertions(+), 185 deletions(-)
diff --git a/extensions/vertico-buffer.el b/extensions/vertico-buffer.el
index fedc2c08bb..3d0bfde32c 100644
--- a/extensions/vertico-buffer.el
+++ b/extensions/vertico-buffer.el
@@ -88,8 +88,9 @@
(setq-local cursor-in-non-selected-windows new)
(force-mode-line-update t))))))
-(defun vertico-buffer--setup ()
- "Setup buffer display."
+(cl-defmethod vertico--resize-window (_height &context (vertico-buffer-mode
(eql t))))
+
+(cl-defmethod vertico--setup :after (&context (vertico-buffer-mode (eql t)))
(add-hook 'pre-redisplay-functions 'vertico-buffer--redisplay nil 'local)
(let* ((action vertico-buffer-display-action) tmp win old-buf
(_ (unwind-protect
@@ -150,14 +151,7 @@
;;;###autoload
(define-minor-mode vertico-buffer-mode
"Display Vertico in a buffer instead of the minibuffer."
- :global t :group 'vertico
- (cond
- (vertico-buffer-mode
- (advice-add #'vertico--setup :after #'vertico-buffer--setup)
- (advice-add #'vertico--resize-window :override #'ignore))
- (t
- (advice-remove #'vertico--setup #'vertico-buffer--setup)
- (advice-remove #'vertico--resize-window #'ignore))))
+ :global t :group 'vertico)
(provide 'vertico-buffer)
;;; vertico-buffer.el ends here
diff --git a/extensions/vertico-flat.el b/extensions/vertico-flat.el
index 105ff26f05..4d94c73a47 100644
--- a/extensions/vertico-flat.el
+++ b/extensions/vertico-flat.el
@@ -66,8 +66,7 @@
"<remap> <left-char>" #'vertico-previous
"<remap> <right-char>" #'vertico-next)
-(defun vertico-flat--display-candidates (candidates)
- "Display CANDIDATES horizontally."
+(cl-defmethod vertico--display-candidates (candidates &context
(vertico-flat-mode (eql t)))
(setq-local truncate-lines nil
resize-mini-windows t)
(move-overlay vertico--candidates-ov (point-max) (point-max))
@@ -82,8 +81,7 @@
(t (format (plist-get vertico-flat-format (if (< vertico--index 0)
:prompt :multiple))
(string-join candidates (plist-get vertico-flat-format
:separator))))))))
-(defun vertico-flat--arrange-candidates ()
- "Arrange candidates."
+(cl-defmethod vertico--arrange-candidates (&context (vertico-flat-mode (eql
t)))
(let* ((index (max 0 vertico--index)) (count vertico-count)
(candidates (nthcdr vertico--index vertico--candidates))
(width (- (* vertico-flat-max-lines (- (vertico--window-width) 4))
@@ -127,15 +125,9 @@
(when-let (win (active-minibuffer-window))
(unless (frame-root-window-p win)
(window-resize win (- (window-pixel-height win)) nil nil 'pixelwise)))
- (cond
- (vertico-flat-mode
- (add-to-list 'minor-mode-map-alist `(vertico--input . ,vertico-flat-map))
- (advice-add #'vertico--arrange-candidates :override
#'vertico-flat--arrange-candidates)
- (advice-add #'vertico--display-candidates :override
#'vertico-flat--display-candidates))
- (t
- (setq minor-mode-map-alist (delete `(vertico--input . ,vertico-flat-map)
minor-mode-map-alist))
- (advice-remove #'vertico--arrange-candidates
#'vertico-flat--arrange-candidates)
- (advice-remove #'vertico--display-candidates
#'vertico-flat--display-candidates))))
+ (if vertico-flat-mode
+ (add-to-list 'minor-mode-map-alist `(vertico--input . ,vertico-flat-map))
+ (setq minor-mode-map-alist (delete `(vertico--input . ,vertico-flat-map)
minor-mode-map-alist))))
(provide 'vertico-flat)
;;; vertico-flat.el ends here
diff --git a/extensions/vertico-grid.el b/extensions/vertico-grid.el
index 0947ecc467..c98f2250c9 100644
--- a/extensions/vertico-grid.el
+++ b/extensions/vertico-grid.el
@@ -76,8 +76,7 @@ When scrolling beyond this limit, candidates may be
truncated."
(defvar-local vertico-grid--columns vertico-grid-min-columns
"Current number of grid columns.")
-(defun vertico-grid--arrange-candidates ()
- "Arrange candidates."
+(cl-defmethod vertico--arrange-candidates (&context (vertico-grid-mode (eql
t)))
(when (<= vertico--index 0)
(let ((cand vertico--candidates) (w 1) (n 0))
(while (and cand (< n vertico-grid-lookahead))
@@ -161,13 +160,9 @@ When scrolling beyond this limit, candidates may be
truncated."
(when-let (win (active-minibuffer-window))
(unless (frame-root-window-p win)
(window-resize win (- (window-pixel-height win)) nil nil 'pixelwise)))
- (cond
- (vertico-grid-mode
- (add-to-list 'minor-mode-map-alist `(vertico--input . ,vertico-grid-map))
- (advice-add #'vertico--arrange-candidates :override
#'vertico-grid--arrange-candidates))
- (t
- (setq minor-mode-map-alist (delete `(vertico--input . ,vertico-grid-map)
minor-mode-map-alist))
- (advice-remove #'vertico--arrange-candidates
#'vertico-grid--arrange-candidates))))
+ (if vertico-grid-mode
+ (add-to-list 'minor-mode-map-alist `(vertico--input . ,vertico-grid-map))
+ (setq minor-mode-map-alist (delete `(vertico--input . ,vertico-grid-map)
minor-mode-map-alist))))
;; Emacs 28: Do not show Vertico commands in M-X
(dolist (sym '(vertico-grid-left vertico-grid-right
diff --git a/extensions/vertico-indexed.el b/extensions/vertico-indexed.el
index 37cbe307aa..61e406bb31 100644
--- a/extensions/vertico-indexed.el
+++ b/extensions/vertico-indexed.el
@@ -50,18 +50,6 @@
(defvar-local vertico-indexed--min 0)
(defvar-local vertico-indexed--max 0)
-(defun vertico-indexed--format-candidate (orig cand prefix suffix index start)
- "Format candidate, see `vertico--format-candidate' for arguments."
- (setq vertico-indexed--min start vertico-indexed--max index)
- (funcall orig cand
- (concat (propertize (format
- (if (> (+ vertico-indexed-start vertico-count)
10)
- "%2d " "%1d ")
- (+ (- index start) vertico-indexed-start))
- 'face 'vertico-indexed)
- prefix)
- suffix index start))
-
(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))
@@ -75,19 +63,30 @@
(funcall orig)))
(apply orig args)))
+(cl-defmethod vertico--format-candidate :around
+ (cand prefix suffix index start &context (vertico-indexed-mode (eql t)))
+ (setq vertico-indexed--min start vertico-indexed--max index)
+ (cl-call-next-method
+ cand
+ (concat (propertize (format
+ (if (> (+ vertico-indexed-start vertico-count) 10)
+ "%2d " "%1d ")
+ (+ (- index start) vertico-indexed-start))
+ 'face 'vertico-indexed)
+ prefix)
+ suffix index start))
+
;;;###autoload
(define-minor-mode vertico-indexed-mode
"Prefix candidates with indices."
:global t :group 'vertico
- (cond
- (vertico-indexed-mode
- (advice-add #'vertico--format-candidate :around
#'vertico-indexed--format-candidate)
- (dolist (cmd vertico-indexed--commands)
- (advice-add cmd :around #'vertico-indexed--handle-prefix)))
- (t
- (advice-remove #'vertico--format-candidate
#'vertico-indexed--format-candidate)
- (dolist (cmd vertico-indexed--commands)
- (advice-remove cmd #'vertico-indexed--handle-prefix)))))
+ ;; 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))))
(provide 'vertico-indexed)
;;; vertico-indexed.el ends here
diff --git a/extensions/vertico-mouse.el b/extensions/vertico-mouse.el
index ffcc9bc73c..f2f065f0ff 100644
--- a/extensions/vertico-mouse.el
+++ b/extensions/vertico-mouse.el
@@ -51,9 +51,9 @@
(let ((vertico--index index))
(vertico-insert))))))
-(defun vertico-mouse--format-candidate (orig cand prefix suffix index start)
- "Format candidate, see `vertico--format-candidate' for arguments."
- (setq cand (funcall orig cand prefix suffix index start))
+(cl-defmethod vertico--format-candidate
+ :around (cand prefix suffix index start &context (vertico-mouse-mode (eql
t)))
+ (setq cand (cl-call-next-method cand prefix suffix index start))
(when (equal suffix "")
(setq cand (concat (substring cand 0 -1)
(propertize " " 'display '(space :align-to right))
@@ -73,22 +73,14 @@
"Scroll down by N lines."
(vertico-mouse--scroll-up (- n)))
-(defun vertico-mouse--setup ()
- "Setup mouse scrolling."
+(cl-defmethod vertico--setup :after (&context (vertico-mouse-mode (eql t)))
(setq-local mwheel-scroll-up-function #'vertico-mouse--scroll-up
mwheel-scroll-down-function #'vertico-mouse--scroll-down))
;;;###autoload
(define-minor-mode vertico-mouse-mode
"Mouse support for Vertico."
- :global t :group 'vertico
- (cond
- (vertico-mouse-mode
- (advice-add #'vertico--format-candidate :around
#'vertico-mouse--format-candidate)
- (advice-add #'vertico--setup :after #'vertico-mouse--setup))
- (t
- (advice-remove #'vertico--format-candidate
#'vertico-mouse--format-candidate)
- (advice-remove #'vertico--setup #'vertico-mouse--setup))))
+ :global t :group 'vertico)
(provide 'vertico-mouse)
;;; vertico-mouse.el ends here
diff --git a/extensions/vertico-multiform.el b/extensions/vertico-multiform.el
index c7f0a1d26d..a5ba77ac38 100644
--- a/extensions/vertico-multiform.el
+++ b/extensions/vertico-multiform.el
@@ -135,9 +135,7 @@ The keys in LIST can be symbols or regexps."
(vertico-multiform--toggle 1)
(vertico--setup)))
-(defun vertico-multiform--advice (&rest app)
- "Override advice for `vertico--advice' switching modes on and off.
-APP is the original function call."
+(cl-defmethod vertico--advice (&context (vertico-multiform-mode (eql t)) &rest
app)
(unwind-protect
(progn
(vertico-multiform--toggle -1)
@@ -153,10 +151,7 @@ APP is the original function call."
(warn "vertico-multiform must not be toggled from recursive minibuffers"))
(when vertico-multiform--stack
(warn "vertico-multiform state is inconsistent")
- (setq vertico-multiform--stack nil))
- (if vertico-multiform-mode
- (advice-add #'vertico--advice :override #'vertico-multiform--advice)
- (advice-remove #'vertico--advice #'vertico-multiform--advice)))
+ (setq vertico-multiform--stack nil)))
(defun vertico-multiform--ensure ()
"Ensure that multiform mode is enabled."
diff --git a/extensions/vertico-reverse.el b/extensions/vertico-reverse.el
index 832200e827..5c955270b4 100644
--- a/extensions/vertico-reverse.el
+++ b/extensions/vertico-reverse.el
@@ -52,8 +52,7 @@
"<remap> <backward-paragraph>" #'vertico-next-group
"<remap> <forward-paragraph>" #'vertico-previous-group)
-(defun vertico-reverse--display-candidates (lines)
- "Display LINES in reverse."
+(cl-defmethod vertico--display-candidates (lines &context
(vertico-reverse-mode (eql t)))
(move-overlay vertico--candidates-ov (point-min) (point-min))
(setq lines (nreverse lines))
(unless (eq vertico-resize t)
@@ -72,13 +71,9 @@
(dolist (buf (buffer-list))
(when-let (ov (buffer-local-value 'vertico--candidates-ov buf))
(overlay-put ov 'before-string nil)))
- (cond
- (vertico-reverse-mode
- (add-to-list 'minor-mode-map-alist `(vertico--input .
,vertico-reverse-map))
- (advice-add #'vertico--display-candidates :override
#'vertico-reverse--display-candidates))
- (t
- (setq minor-mode-map-alist (delete `(vertico--input .
,vertico-reverse-map) minor-mode-map-alist))
- (advice-remove #'vertico--display-candidates
#'vertico-reverse--display-candidates))))
+ (if vertico-reverse-mode
+ (add-to-list 'minor-mode-map-alist `(vertico--input .
,vertico-reverse-map))
+ (setq minor-mode-map-alist (delete `(vertico--input .
,vertico-reverse-map) minor-mode-map-alist))))
(provide 'vertico-reverse)
;;; vertico-reverse.el ends here
diff --git a/extensions/vertico-unobtrusive.el
b/extensions/vertico-unobtrusive.el
index 1069d9a576..c8e0bc991f 100644
--- a/extensions/vertico-unobtrusive.el
+++ b/extensions/vertico-unobtrusive.el
@@ -43,6 +43,9 @@
(defvar vertico-unobtrusive--orig-count nil)
(defvar vertico-unobtrusive--orig-count-format nil)
+(cl-defmethod vertico--setup :before (&context (vertico-unobtrusive-mode (eql
t)))
+ (redisplay))
+
;;;###autoload
(define-minor-mode vertico-unobtrusive-mode
"Unobtrusive display for Vertico."
@@ -55,9 +58,7 @@
vertico-unobtrusive--orig-count-format vertico-count-format
vertico-count 1
vertico-count-format nil
- vertico-flat-format `(:separator nil :ellipsis nil
,@vertico-flat-format)))
- (advice-add #'vertico--setup :before #'redisplay)
- (vertico-flat-mode 1))
+ vertico-flat-format `(:separator nil :ellipsis nil
,@vertico-flat-format))))
(t
(when vertico-unobtrusive--orig-count
(setq-default face-remapping-alist
@@ -66,10 +67,8 @@
(setq vertico-count vertico-unobtrusive--orig-count
vertico-count-format vertico-unobtrusive--orig-count-format
vertico-flat-format (nthcdr 4 vertico-flat-format)
- vertico-unobtrusive--orig-count nil))
- (advice-remove #'vertico--setup #'redisplay)
- (vertico-flat-mode -1)))
- (setq vertico-flat-mode nil))
+ vertico-unobtrusive--orig-count nil))))
+ (vertico-flat-mode (if vertico-unobtrusive-mode 1 -1)))
(provide 'vertico-unobtrusive)
;;; vertico-unobtrusive.el ends here
diff --git a/vertico.el b/vertico.el
index f676925d1a..f41b0710ff 100644
--- a/vertico.el
+++ b/vertico.el
@@ -476,13 +476,6 @@ The function is configured by BY, BSIZE, BINDEX, BPRED and
PRED."
(replace-regexp-in-string "\\`[\t\n ]+\\|[\t\n ]+\\'" ""))
max-width 0 nil (cdr vertico-multiline)))
-(defun vertico--format-candidate (cand prefix suffix index _start)
- "Format CAND given PREFIX, SUFFIX and INDEX."
- (setq cand (vertico--display-string (concat prefix cand suffix "\n")))
- (when (= index vertico--index)
- (add-face-text-property 0 (length cand) 'vertico-current 'append cand))
- cand)
-
(defun vertico--compute-scroll ()
"Compute new scroll position."
(let ((off (max (min vertico-scroll-margin (/ vertico-count 2)) 0))
@@ -501,7 +494,85 @@ The function is configured by BY, BSIZE, BINDEX, BPRED and
PRED."
(vertico--remove-face 0 (length title) 'completions-first-difference
title))
(format (concat vertico-group-format "\n") title))
-(defun vertico--arrange-candidates ()
+(defun vertico--format-count ()
+ "Format the count string."
+ (format (car vertico-count-format)
+ (format (cdr vertico-count-format)
+ (cond ((>= vertico--index 0) (1+ vertico--index))
+ (vertico--allow-prompt "*")
+ (t "!"))
+ vertico--total)))
+
+(defun vertico--display-count ()
+ "Update count overlay `vertico--count-ov'."
+ (move-overlay vertico--count-ov (point-min) (point-min))
+ (overlay-put vertico--count-ov 'before-string
+ (if vertico-count-format (vertico--format-count) "")))
+
+(defun vertico--prompt-selection ()
+ "Highlight the prompt if selected."
+ (let ((inhibit-modification-hooks t))
+ (if (and (< vertico--index 0) vertico--allow-prompt)
+ (add-face-text-property (minibuffer-prompt-end) (point-max)
'vertico-current 'append)
+ (vertico--remove-face (minibuffer-prompt-end) (point-max)
'vertico-current))))
+
+(defun vertico--remove-face (beg end face &optional obj)
+ "Remove FACE between BEG and END from OBJ."
+ (while (< beg end)
+ (let ((next (next-single-property-change beg 'face obj end)))
+ (when-let (val (get-text-property beg 'face obj))
+ (put-text-property beg next 'face (remq face (ensure-list val)) obj))
+ (setq beg next))))
+
+(defun vertico--exhibit ()
+ "Exhibit completion UI."
+ (let ((buffer-undo-list t)) ;; Overlays affect point position and undo list!
+ (vertico--update 'interruptible)
+ (vertico--prompt-selection)
+ (vertico--display-count)
+ (vertico--display-candidates (vertico--arrange-candidates))))
+
+(defun vertico--goto (index)
+ "Go to candidate with INDEX."
+ (setq vertico--index
+ (max (if (or vertico--allow-prompt (= 0 vertico--total)) -1 0)
+ (min index (1- vertico--total)))
+ vertico--lock-candidate (or (>= vertico--index 0)
vertico--allow-prompt)))
+
+(defun vertico--candidate (&optional hl)
+ "Return current candidate string with optional highlighting if HL is
non-nil."
+ (let ((content (substring (or (car-safe vertico--input)
(minibuffer-contents-no-properties)))))
+ (cond
+ ((>= vertico--index 0)
+ (let ((cand (substring (nth vertico--index vertico--candidates))))
+ ;; XXX Drop the completions-common-part face which is added by
`completion--twq-all'.
+ ;; This is a hack in Emacs and should better be fixed in Emacs itself,
the corresponding
+ ;; code is already marked with a FIXME. Should this be reported as a
bug?
+ (vertico--remove-face 0 (length cand) 'completions-common-part cand)
+ (concat vertico--base
+ (if hl (car (funcall vertico--highlight (list cand))) cand))))
+ ((and (equal content "") (or (car-safe minibuffer-default)
minibuffer-default)))
+ (t content))))
+
+(defun vertico--match-p (input)
+ "Return t if INPUT is a valid match."
+ (or (memq minibuffer--require-match '(nil confirm-after-completion))
+ (equal "" input) ;; Null completion, returns default value
+ (and (functionp minibuffer--require-match) ;; Emacs 29 require-match
function
+ (funcall minibuffer--require-match input))
+ (test-completion input minibuffer-completion-table
minibuffer-completion-predicate)
+ (if (eq minibuffer--require-match 'confirm)
+ (eq (ignore-errors (read-char "Confirm")) 13)
+ (and (minibuffer-message "Match required") nil))))
+
+(cl-defgeneric vertico--format-candidate (cand prefix suffix index _start)
+ "Format CAND given PREFIX, SUFFIX and INDEX."
+ (setq cand (vertico--display-string (concat prefix cand suffix "\n")))
+ (when (= index vertico--index)
+ (add-face-text-property 0 (length cand) 'vertico-current 'append cand))
+ cand)
+
+(cl-defgeneric vertico--arrange-candidates ()
"Arrange candidates."
(vertico--compute-scroll)
(let ((curr-line 0) lines)
@@ -540,14 +611,14 @@ The function is configured by BY, BSIZE, BINDEX, BPRED
and PRED."
(setcar line (vertico--format-candidate cand prefix suffix
index start))))))
lines))
-(defun vertico--display-candidates (lines)
+(cl-defgeneric vertico--display-candidates (lines)
"Update candidates overlay `vertico--candidates-ov' with LINES."
(move-overlay vertico--candidates-ov (point-max) (point-max))
(overlay-put vertico--candidates-ov 'after-string
(apply #'concat #(" " 0 1 (cursor t)) (and lines "\n") lines))
(vertico--resize-window (length lines)))
-(defun vertico--resize-window (height)
+(cl-defgeneric vertico--resize-window (height)
"Resize active minibuffer window to HEIGHT."
(setq-local truncate-lines (< (point) (* 0.8 (vertico--window-width)))
resize-mini-windows 'grow-only
@@ -563,50 +634,22 @@ 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)))))
-(defun vertico--format-count ()
- "Format the count string."
- (format (car vertico-count-format)
- (format (cdr vertico-count-format)
- (cond ((>= vertico--index 0) (1+ vertico--index))
- (vertico--allow-prompt "*")
- (t "!"))
- vertico--total)))
-
-(defun vertico--display-count ()
- "Update count overlay `vertico--count-ov'."
- (move-overlay vertico--count-ov (point-min) (point-min))
- (overlay-put vertico--count-ov 'before-string
- (if vertico-count-format (vertico--format-count) "")))
-
-(defun vertico--prompt-selection ()
- "Highlight the prompt if selected."
- (let ((inhibit-modification-hooks t))
- (if (and (< vertico--index 0) vertico--allow-prompt)
- (add-face-text-property (minibuffer-prompt-end) (point-max)
'vertico-current 'append)
- (vertico--remove-face (minibuffer-prompt-end) (point-max)
'vertico-current))))
-
-(defun vertico--remove-face (beg end face &optional obj)
- "Remove FACE between BEG and END from OBJ."
- (while (< beg end)
- (let ((next (next-single-property-change beg 'face obj end)))
- (when-let (val (get-text-property beg 'face obj))
- (put-text-property beg next 'face (remq face (ensure-list val)) obj))
- (setq beg next))))
-
-(defun vertico--exhibit ()
- "Exhibit completion UI."
- (let ((buffer-undo-list t)) ;; Overlays affect point position and undo list!
- (vertico--update 'interruptible)
- (vertico--prompt-selection)
- (vertico--display-count)
- (vertico--display-candidates (vertico--arrange-candidates))))
+(cl-defgeneric vertico--setup ()
+ "Setup completion UI."
+ (setq vertico--input t
+ vertico--candidates-ov (make-overlay (point-max) (point-max) nil t t)
+ vertico--count-ov (make-overlay (point-min) (point-min) nil t t))
+ ;; Set priority for compatibility with `minibuffer-depth-indicate-mode'
+ (overlay-put vertico--count-ov 'priority 1)
+ (setq-local completion-auto-help nil
+ completion-show-inline-help nil)
+ (use-local-map vertico-map)
+ (add-hook 'pre-command-hook #'vertico--prepare nil 'local)
+ (add-hook 'post-command-hook #'vertico--exhibit nil 'local))
-(defun vertico--goto (index)
- "Go to candidate with INDEX."
- (setq vertico--index
- (max (if (or vertico--allow-prompt (= 0 vertico--total)) -1 0)
- (min index (1- vertico--total)))
- vertico--lock-candidate (or (>= vertico--index 0)
vertico--allow-prompt)))
+(cl-defgeneric vertico--advice (&rest app)
+ "Advice for completion function, apply APP."
+ (minibuffer-with-setup-hook #'vertico--setup (apply app)))
(defun vertico-first ()
"Go to first candidate, or to the prompt when the first candidate is
selected."
@@ -644,17 +687,6 @@ The function is configured by BY, BSIZE, BINDEX, BPRED and
PRED."
(interactive "p")
(vertico-next (- (or n 1))))
-(defun vertico--match-p (input)
- "Return t if INPUT is a valid match."
- (or (memq minibuffer--require-match '(nil confirm-after-completion))
- (equal "" input) ;; Null completion, returns default value
- (and (functionp minibuffer--require-match) ;; Emacs 29 require-match
function
- (funcall minibuffer--require-match input))
- (test-completion input minibuffer-completion-table
minibuffer-completion-predicate)
- (if (eq minibuffer--require-match 'confirm)
- (eq (ignore-errors (read-char "Confirm")) 13)
- (and (minibuffer-message "Match required") nil))))
-
(defun vertico-exit (&optional arg)
"Exit minibuffer with current candidate or input if prefix ARG is given."
(interactive "P")
@@ -710,38 +742,6 @@ When the prefix argument is 0, the group order is reset."
(let ((vertico--index (max 0 vertico--index)))
(insert (prog1 (vertico--candidate) (delete-minibuffer-contents))))))
-(defun vertico--candidate (&optional hl)
- "Return current candidate string with optional highlighting if HL is
non-nil."
- (let ((content (substring (or (car-safe vertico--input)
(minibuffer-contents-no-properties)))))
- (cond
- ((>= vertico--index 0)
- (let ((cand (substring (nth vertico--index vertico--candidates))))
- ;; XXX Drop the completions-common-part face which is added by
`completion--twq-all'.
- ;; This is a hack in Emacs and should better be fixed in Emacs itself,
the corresponding
- ;; code is already marked with a FIXME. Should this be reported as a
bug?
- (vertico--remove-face 0 (length cand) 'completions-common-part cand)
- (concat vertico--base
- (if hl (car (funcall vertico--highlight (list cand))) cand))))
- ((and (equal content "") (or (car-safe minibuffer-default)
minibuffer-default)))
- (t content))))
-
-(defun vertico--setup ()
- "Setup completion UI."
- (setq vertico--input t
- vertico--candidates-ov (make-overlay (point-max) (point-max) nil t t)
- vertico--count-ov (make-overlay (point-min) (point-min) nil t t))
- ;; Set priority for compatibility with `minibuffer-depth-indicate-mode'
- (overlay-put vertico--count-ov 'priority 1)
- (setq-local completion-auto-help nil
- completion-show-inline-help nil)
- (use-local-map vertico-map)
- (add-hook 'pre-command-hook #'vertico--prepare nil 'local)
- (add-hook 'post-command-hook #'vertico--exhibit nil 'local))
-
-(defun vertico--advice (&rest args)
- "Advice for completion function, receiving ARGS."
- (minibuffer-with-setup-hook #'vertico--setup (apply args)))
-
;;;###autoload
(define-minor-mode vertico-mode
"VERTical Interactive COmpletion."
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/vertico 2346498e6a: Use cl-defgeneric instead of advices,
ELPA Syncer <=