]> git.eshelyaron.com Git - emacs.git/commitdiff
(completion-preview-prev-candidate): add numeric prefix argument
authorEshel Yaron <me@eshelyaron.com>
Fri, 12 Apr 2024 21:19:13 +0000 (23:19 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sun, 14 Apr 2024 13:57:19 +0000 (15:57 +0200)
* lisp/completion-preview.el (completion-preview-prev-candidate):
Add numeric prefix argument N.
(completion-preview-next-candidate): Update documentation.

lisp/completion-preview.el

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