diff options
| author | Eshel Yaron | 2024-04-12 23:19:13 +0200 |
|---|---|---|
| committer | Eshel Yaron | 2024-04-23 14:35:45 +0200 |
| commit | 2234fe929a4d397941b257941bfe2634b0cd7a10 (patch) | |
| tree | 04f54b5da92a9f81c6626df59fe14c3c52888c14 | |
| parent | 6b26644300a6bc7a24af883552b67112a5d41a03 (diff) | |
| download | emacs-2234fe929a4d397941b257941bfe2634b0cd7a10.tar.gz emacs-2234fe929a4d397941b257941bfe2634b0cd7a10.zip | |
(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.
| -rw-r--r-- | lisp/completion-preview.el | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el index a3443eae801..25c1cd4a22f 100644 --- a/lisp/completion-preview.el +++ b/lisp/completion-preview.el | |||
| @@ -489,16 +489,18 @@ completions list." | |||
| 489 | 'keymap completion-preview--mouse-map)) | 489 | 'keymap completion-preview--mouse-map)) |
| 490 | 'completion-preview-end pos)))))) | 490 | 'completion-preview-end pos)))))) |
| 491 | 491 | ||
| 492 | (defun completion-preview-prev-candidate () | 492 | (defun completion-preview-prev-candidate (n) |
| 493 | "Cycle the candidate that the preview is showing to the previous suggestion." | 493 | "Cycle the candidate the preview is showing N candidates backward. |
| 494 | (interactive) | 494 | |
| 495 | (completion-preview-next-candidate -1)) | 495 | If N is negative, cycle -N candidates forward. Interactively, N is the |
| 496 | prefix argument and defaults to 1." | ||
| 497 | (interactive "p") | ||
| 498 | (completion-preview-next-candidate (- n))) | ||
| 496 | 499 | ||
| 497 | (defun completion-preview-next-candidate (direction) | 500 | (defun completion-preview-next-candidate (n) |
| 498 | "Cycle the candidate that the preview is showing in direction DIRECTION. | 501 | "Cycle the candidate the preview is showing N candidates forward. |
| 499 | 502 | ||
| 500 | DIRECTION should be either 1 which means cycle forward, or -1 | 503 | If N is negative, cycle -N candidates backward. Interactively, N is the |
| 501 | which means cycle backward. Interactively, DIRECTION is the | ||
| 502 | prefix argument and defaults to 1." | 504 | prefix argument and defaults to 1." |
| 503 | (interactive "p") | 505 | (interactive "p") |
| 504 | (when completion-preview-active-mode | 506 | (when completion-preview-active-mode |
| @@ -508,7 +510,7 @@ prefix argument and defaults to 1." | |||
| 508 | (com (completion-preview--get 'completion-preview-common)) | 510 | (com (completion-preview--get 'completion-preview-common)) |
| 509 | (cur (completion-preview--get 'completion-preview-index)) | 511 | (cur (completion-preview--get 'completion-preview-index)) |
| 510 | (len (length all)) | 512 | (len (length all)) |
| 511 | (new (mod (+ cur direction) len)) | 513 | (new (mod (+ cur n) len)) |
| 512 | (suf (nth new all)) | 514 | (suf (nth new all)) |
| 513 | (lencom (length com))) | 515 | (lencom (length com))) |
| 514 | ;; Skip suffixes that are no longer applicable. This may happen | 516 | ;; Skip suffixes that are no longer applicable. This may happen |
| @@ -519,7 +521,7 @@ prefix argument and defaults to 1." | |||
| 519 | (while (or (<= (+ beg lencom (length suf)) end) | 521 | (while (or (<= (+ beg lencom (length suf)) end) |
| 520 | (not (string-prefix-p (buffer-substring beg end) | 522 | (not (string-prefix-p (buffer-substring beg end) |
| 521 | (concat com suf)))) | 523 | (concat com suf)))) |
| 522 | (setq new (mod (+ new direction) len) | 524 | (setq new (mod (+ new n) len) |
| 523 | suf (nth new all))) | 525 | suf (nth new all))) |
| 524 | (set-text-properties 0 (length suf) | 526 | (set-text-properties 0 (length suf) |
| 525 | (list 'face (if (cdr all) | 527 | (list 'face (if (cdr all) |