>From 250d743cf53002b4c696ad33eb76a4454c4d254c Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Thu, 9 Dec 2021 17:26:14 +0100 Subject: [PATCH 1/4] Allow for next-completion to wrap around the completion buffer * lisp/simple.el (completion-wrap-movement): Add new option. (previous-completion): Update docstring. (next-completion): Respect completion-wrap-movement. --- lisp/simple.el | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lisp/simple.el b/lisp/simple.el index 94a459b779..5183a7e053 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -9013,25 +9013,38 @@ delete-completion-window (if (get-buffer-window buf) (select-window (get-buffer-window buf)))))) +(defcustom completion-wrap-movement t + "Non-nil means to wrap around when selecting completion options. +This affects the commands `next-completion' and +`previous-completion'." + :type 'boolean + :version "29.1" + :group 'completion) + (defun previous-completion (n) - "Move to the previous item in the completion list." + "Move to the previous item in the completion list. +With prefix argument N, move back N items (negative N means move +forward)." (interactive "p") (next-completion (- n))) (defun next-completion (n) "Move to the next item in the completion list. -With prefix argument N, move N items (negative N means move backward)." +With prefix argument N, move N items (negative N means move +backward)." (interactive "p") (let ((beg (point-min)) (end (point-max))) - (while (and (> n 0) (not (eobp))) + (while (> n 0) ;; If in a completion, move to the end of it. (when (get-text-property (point) 'mouse-face) (goto-char (next-single-property-change (point) 'mouse-face nil end))) + (when (and (eobp) completion-wrap-movement) + (goto-char (point-min))) ;; Move to start of next one. (unless (get-text-property (point) 'mouse-face) (goto-char (next-single-property-change (point) 'mouse-face nil end))) (setq n (1- n))) - (while (and (< n 0) (not (bobp))) + (while (< n 0) (let ((prop (get-text-property (1- (point)) 'mouse-face))) ;; If in a completion, move to the start of it. (when (and prop (eq prop (get-text-property (point) 'mouse-face))) @@ -9041,6 +9054,8 @@ next-completion (unless (or (bobp) (get-text-property (1- (point)) 'mouse-face)) (goto-char (previous-single-property-change (point) 'mouse-face nil beg))) + (when (and (bobp) completion-wrap-movement) + (goto-char (point-max))) ;; Move to the start of that one. (goto-char (previous-single-property-change (point) 'mouse-face nil beg)) -- 2.34.0