summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoão Távora <joaotavora@gmail.com>2021-08-17 12:48:37 +0100
committerJoão Távora <joaotavora@gmail.com>2021-08-17 12:56:38 +0100
commit96bbd6f0a7f20ae77bcd8a477b54b11ba5b42cc6 (patch)
tree519375d6fee4ad87c3f773bdc443b41593bd13d0
parentbf1ec4952e67b474bff813cd26e4d612a359baf1 (diff)
downloademacs-96bbd6f0a7f20ae77bcd8a477b54b11ba5b42cc6.tar.gz
Jump to first,last completion with M-<, M-> in icomplete-vertical-mode
Fixes: bug#49005 Co-authored-by: Simon Lang <simon.lang@outlook.com> * lisp/icomplete.el (icomplete-backward-completions): Return non-nil iff something was stepped. Ajust docstring. (icomplete-forward-completions): Adjust docstring. (icomplete-vertical-goto-first, icomplete-vertical-goto-last): New commands. (icomplete-vertical-mode-minibuffer-map): Bind new commands to M-< and M->.
-rw-r--r--lisp/icomplete.el41
1 files changed, 29 insertions, 12 deletions
diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index e06b33e43bb..96b7e0f2014 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -249,7 +249,8 @@ the default otherwise."
(defun icomplete-forward-completions ()
"Step forward completions by one entry.
Second entry becomes the first and can be selected with
-`icomplete-force-complete-and-exit'."
+`icomplete-force-complete-and-exit'.
+Return non-nil iff something was stepped."
(interactive)
(let* ((beg (icomplete--field-beg))
(end (icomplete--field-end))
@@ -266,21 +267,35 @@ Second entry becomes the first and can be selected with
(defun icomplete-backward-completions ()
"Step backward completions by one entry.
Last entry becomes the first and can be selected with
-`icomplete-force-complete-and-exit'."
+`icomplete-force-complete-and-exit'.
+Return non-nil iff something was stepped."
(interactive)
(let* ((beg (icomplete--field-beg))
(end (icomplete--field-end))
(comps (completion-all-sorted-completions beg end))
- last-but-one)
- (cond ((and icomplete-scroll icomplete--scrolled-past)
- (push (pop icomplete--scrolled-past) comps)
- (setq icomplete--scrolled-completions comps))
- ((and (not icomplete-scroll)
- (consp (cdr (setq last-but-one (last comps 2)))))
- ;; At least two elements in comps
- (push (car (cdr last-but-one)) comps)
- (setcdr last-but-one (cdr (cdr last-but-one)))))
- (completion--cache-all-sorted-completions beg end comps)))
+ last-but-one)
+ (prog1
+ (cond ((and icomplete-scroll icomplete--scrolled-past)
+ (push (pop icomplete--scrolled-past) comps)
+ (setq icomplete--scrolled-completions comps))
+ ((and (not icomplete-scroll)
+ (consp (cdr (setq last-but-one (last comps 2)))))
+ ;; At least two elements in comps
+ (push (car (cdr last-but-one)) comps)
+ (setcdr last-but-one (cdr (cdr last-but-one)))))
+ (completion--cache-all-sorted-completions beg end comps))))
+
+(defun icomplete-vertical-goto-first ()
+ "Go to first completions entry when `icomplete-scroll' is non-nil."
+ (interactive)
+ (unless icomplete-scroll (error "Only works with `icomplete-scroll'"))
+ (while (icomplete-backward-completions)))
+
+(defun icomplete-vertical-goto-last ()
+ "Go to last completions entry when `icomplete-scroll' is non-nil."
+ (interactive)
+ (unless icomplete-scroll (error "Only works with `icomplete-scroll'"))
+ (while (icomplete-forward-completions)))
;;;_* Helpers for `fido-mode' (or `ido-mode' emulation)
@@ -609,6 +624,8 @@ Usually run by inclusion in `minibuffer-setup-hook'."
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-n") 'icomplete-forward-completions)
(define-key map (kbd "C-p") 'icomplete-backward-completions)
+ (define-key map (kbd "M-<") 'icomplete-vertical-goto-first)
+ (define-key map (kbd "M->") 'icomplete-vertical-goto-last)
map)
"Keymap used by `icomplete-vertical-mode' in the minibuffer.")