From 96bbd6f0a7f20ae77bcd8a477b54b11ba5b42cc6 Mon Sep 17 00:00:00 2001 From: João Távora Date: Tue, 17 Aug 2021 12:48:37 +0100 Subject: Jump to first,last completion with M-<, M-> in icomplete-vertical-mode Fixes: bug#49005 Co-authored-by: Simon Lang * 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->. --- lisp/icomplete.el | 41 +++++++++++++++++++++++++++++------------ 1 file 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.") -- cgit v1.2.3