1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

(completion-preview-prev-candidate): add numeric prefix argument

* lisp/completion-preview.el (completion-preview-prev-candidate):
Add numeric prefix argument N.
(completion-preview-next-candidate): Update documentation.
This commit is contained in:
Eshel Yaron 2024-04-12 23:19:13 +02:00
parent 6b26644300
commit 2234fe929a
No known key found for this signature in database
GPG key ID: EF3EE9CA35D78618

View file

@ -489,16 +489,18 @@ completions list."
'keymap completion-preview--mouse-map)) 'keymap completion-preview--mouse-map))
'completion-preview-end pos)))))) 'completion-preview-end pos))))))
(defun completion-preview-prev-candidate () (defun completion-preview-prev-candidate (n)
"Cycle the candidate that the preview is showing to the previous suggestion." "Cycle the candidate the preview is showing N candidates backward.
(interactive)
(completion-preview-next-candidate -1))
(defun completion-preview-next-candidate (direction) If N is negative, cycle -N candidates forward. Interactively, N is the
"Cycle the candidate that the preview is showing in direction DIRECTION. prefix argument and defaults to 1."
(interactive "p")
(completion-preview-next-candidate (- n)))
DIRECTION should be either 1 which means cycle forward, or -1 (defun completion-preview-next-candidate (n)
which means cycle backward. Interactively, DIRECTION is the "Cycle the candidate the preview is showing N candidates forward.
If N is negative, cycle -N candidates backward. Interactively, N is the
prefix argument and defaults to 1." prefix argument and defaults to 1."
(interactive "p") (interactive "p")
(when completion-preview-active-mode (when completion-preview-active-mode
@ -508,7 +510,7 @@ prefix argument and defaults to 1."
(com (completion-preview--get 'completion-preview-common)) (com (completion-preview--get 'completion-preview-common))
(cur (completion-preview--get 'completion-preview-index)) (cur (completion-preview--get 'completion-preview-index))
(len (length all)) (len (length all))
(new (mod (+ cur direction) len)) (new (mod (+ cur n) len))
(suf (nth new all)) (suf (nth new all))
(lencom (length com))) (lencom (length com)))
;; Skip suffixes that are no longer applicable. This may happen ;; Skip suffixes that are no longer applicable. This may happen
@ -519,7 +521,7 @@ prefix argument and defaults to 1."
(while (or (<= (+ beg lencom (length suf)) end) (while (or (<= (+ beg lencom (length suf)) end)
(not (string-prefix-p (buffer-substring beg end) (not (string-prefix-p (buffer-substring beg end)
(concat com suf)))) (concat com suf))))
(setq new (mod (+ new direction) len) (setq new (mod (+ new n) len)
suf (nth new all))) suf (nth new all)))
(set-text-properties 0 (length suf) (set-text-properties 0 (length suf)
(list 'face (if (cdr all) (list 'face (if (cdr all)