aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2021-08-17 12:48:37 +0100
committerJoão Távora2021-08-17 12:56:38 +0100
commit96bbd6f0a7f20ae77bcd8a477b54b11ba5b42cc6 (patch)
tree519375d6fee4ad87c3f773bdc443b41593bd13d0
parentbf1ec4952e67b474bff813cd26e4d612a359baf1 (diff)
downloademacs-96bbd6f0a7f20ae77bcd8a477b54b11ba5b42cc6.tar.gz
emacs-96bbd6f0a7f20ae77bcd8a477b54b11ba5b42cc6.zip
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."
249(defun icomplete-forward-completions () 249(defun icomplete-forward-completions ()
250 "Step forward completions by one entry. 250 "Step forward completions by one entry.
251Second entry becomes the first and can be selected with 251Second entry becomes the first and can be selected with
252`icomplete-force-complete-and-exit'." 252`icomplete-force-complete-and-exit'.
253Return non-nil iff something was stepped."
253 (interactive) 254 (interactive)
254 (let* ((beg (icomplete--field-beg)) 255 (let* ((beg (icomplete--field-beg))
255 (end (icomplete--field-end)) 256 (end (icomplete--field-end))
@@ -266,21 +267,35 @@ Second entry becomes the first and can be selected with
266(defun icomplete-backward-completions () 267(defun icomplete-backward-completions ()
267 "Step backward completions by one entry. 268 "Step backward completions by one entry.
268Last entry becomes the first and can be selected with 269Last entry becomes the first and can be selected with
269`icomplete-force-complete-and-exit'." 270`icomplete-force-complete-and-exit'.
271Return non-nil iff something was stepped."
270 (interactive) 272 (interactive)
271 (let* ((beg (icomplete--field-beg)) 273 (let* ((beg (icomplete--field-beg))
272 (end (icomplete--field-end)) 274 (end (icomplete--field-end))
273 (comps (completion-all-sorted-completions beg end)) 275 (comps (completion-all-sorted-completions beg end))
274 last-but-one) 276 last-but-one)
275 (cond ((and icomplete-scroll icomplete--scrolled-past) 277 (prog1
276 (push (pop icomplete--scrolled-past) comps) 278 (cond ((and icomplete-scroll icomplete--scrolled-past)
277 (setq icomplete--scrolled-completions comps)) 279 (push (pop icomplete--scrolled-past) comps)
278 ((and (not icomplete-scroll) 280 (setq icomplete--scrolled-completions comps))
279 (consp (cdr (setq last-but-one (last comps 2))))) 281 ((and (not icomplete-scroll)
280 ;; At least two elements in comps 282 (consp (cdr (setq last-but-one (last comps 2)))))
281 (push (car (cdr last-but-one)) comps) 283 ;; At least two elements in comps
282 (setcdr last-but-one (cdr (cdr last-but-one))))) 284 (push (car (cdr last-but-one)) comps)
283 (completion--cache-all-sorted-completions beg end comps))) 285 (setcdr last-but-one (cdr (cdr last-but-one)))))
286 (completion--cache-all-sorted-completions beg end comps))))
287
288(defun icomplete-vertical-goto-first ()
289 "Go to first completions entry when `icomplete-scroll' is non-nil."
290 (interactive)
291 (unless icomplete-scroll (error "Only works with `icomplete-scroll'"))
292 (while (icomplete-backward-completions)))
293
294(defun icomplete-vertical-goto-last ()
295 "Go to last completions entry when `icomplete-scroll' is non-nil."
296 (interactive)
297 (unless icomplete-scroll (error "Only works with `icomplete-scroll'"))
298 (while (icomplete-forward-completions)))
284 299
285;;;_* Helpers for `fido-mode' (or `ido-mode' emulation) 300;;;_* Helpers for `fido-mode' (or `ido-mode' emulation)
286 301
@@ -609,6 +624,8 @@ Usually run by inclusion in `minibuffer-setup-hook'."
609 (let ((map (make-sparse-keymap))) 624 (let ((map (make-sparse-keymap)))
610 (define-key map (kbd "C-n") 'icomplete-forward-completions) 625 (define-key map (kbd "C-n") 'icomplete-forward-completions)
611 (define-key map (kbd "C-p") 'icomplete-backward-completions) 626 (define-key map (kbd "C-p") 'icomplete-backward-completions)
627 (define-key map (kbd "M-<") 'icomplete-vertical-goto-first)
628 (define-key map (kbd "M->") 'icomplete-vertical-goto-last)
612 map) 629 map)
613 "Keymap used by `icomplete-vertical-mode' in the minibuffer.") 630 "Keymap used by `icomplete-vertical-mode' in the minibuffer.")
614 631