:version "29.1"
:group 'completion)
+(defun first-completion ()
+ "Move to the first item in the completion list."
+ (interactive)
+ (goto-char (point-min))
+ (unless (get-text-property (point) 'mouse-face)
+ (when-let ((pos (next-single-property-change (point) 'mouse-face)))
+ (goto-char pos))))
+
+(defun last-completion ()
+ "Move to the last item in the completion list."
+ (interactive)
+ (goto-char (previous-single-property-change
+ (point-max) 'mouse-face nil (point-min)))
+ ;; Move to the start of last one.
+ (unless (get-text-property (point) 'mouse-face)
+ (when-let ((pos (previous-single-property-change (point) 'mouse-face)))
+ (goto-char pos))))
+
(defun previous-completion (n)
"Move to the previous item in the completion list.
With prefix argument N, move back N items (negative N means move
Also see the `completion-wrap-movement' variable."
(interactive "p")
- (let ((prev (previous-single-property-change (point) 'mouse-face)))
- (goto-char (cond
- ((not prev)
- (1- (next-single-property-change (point) 'mouse-face)))
- ((/= prev (point))
- (point))
- (t prev))))
-
- (let ((beg (point-min))
- (end (point-max))
- (tabcommand (member (this-command-keys) '("\t" [backtab])))
- prop)
+ (let ((tabcommand (member (this-command-keys) '("\t" [backtab])))
+ pos)
(catch 'bound
(while (> n 0)
+ (setq pos (point))
;; 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)))
- ;; If at the last completion option, wrap or skip to the
- ;; minibuffer, if requested. We can't use (eobp) because some
- ;; extra text may be after the last candidate: ex: when
- ;; completion-detailed
- (setq prop (next-single-property-change (point) 'mouse-face nil end))
- (when (and completion-wrap-movement (eq end prop))
- (if (and completion-auto-select tabcommand)
- (throw 'bound nil)
- (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)))
+ (when (get-text-property pos 'mouse-face)
+ (setq pos (next-single-property-change pos 'mouse-face)))
+ (when pos (setq pos (next-single-property-change pos 'mouse-face)))
+ (if pos
+ ;; Move to the start of next one.
+ (goto-char pos)
+ ;; If at the last completion option, wrap or skip
+ ;; to the minibuffer, if requested.
+ (when completion-wrap-movement
+ (if (and (eq completion-auto-select t) tabcommand)
+ (throw 'bound nil)
+ (first-completion))))
(setq n (1- n)))
- (while (and (< n 0) (not (bobp)))
- (setq prop (get-text-property (1- (point)) 'mouse-face))
+ (while (< n 0)
+ (setq pos (point))
;; If in a completion, move to the start of it.
- (when (and prop (eq prop (get-text-property (point) 'mouse-face)))
- (goto-char (previous-single-property-change
- (point) 'mouse-face nil beg)))
- ;; Move to end of the previous completion.
- (unless (or (bobp) (get-text-property (1- (point)) 'mouse-face))
- (goto-char (previous-single-property-change
- (point) 'mouse-face nil beg)))
- ;; If at the first completion option, wrap or skip to the
- ;; minibuffer, if requested.
- (setq prop (previous-single-property-change (point) 'mouse-face nil beg))
- (when (and completion-wrap-movement (eq beg prop))
- (if (and completion-auto-select tabcommand)
- (progn
- (goto-char (next-single-property-change (point) 'mouse-face nil end))
- (throw 'bound nil))
- (goto-char (point-max))))
- ;; Move to the start of that one.
- (goto-char (previous-single-property-change
- (point) 'mouse-face nil beg))
+ (when (and (get-text-property pos 'mouse-face)
+ (not (bobp))
+ (get-text-property (1- pos) 'mouse-face))
+ (setq pos (previous-single-property-change pos 'mouse-face)))
+ (when pos (setq pos (previous-single-property-change pos 'mouse-face)))
+ (if pos
+ (progn
+ (goto-char pos)
+ ;; Move to the start of that one.
+ (unless (get-text-property (point) 'mouse-face)
+ (goto-char (previous-single-property-change
+ (point) 'mouse-face nil (point-min)))))
+ ;; If at the first completion option, wrap or skip
+ ;; to the minibuffer, if requested.
+ (when completion-wrap-movement
+ (if (and (eq completion-auto-select t) tabcommand)
+ (progn
+ ;; (goto-char (next-single-property-change (point) 'mouse-face))
+ (throw 'bound nil))
+ (last-completion))))
(setq n (1+ n))))
+
(when (/= 0 n)
(switch-to-minibuffer))))
(goto-char (posn-point (event-start event)))
(let (beg)
(cond
- ((and (not (eobp)) (get-text-property (point) 'mouse-face))
+ ((and (not (eobp))
+ (get-text-property (point) 'completion--string))
(setq beg (1+ (point))))
((and (not (bobp))
- (get-text-property (1- (point)) 'mouse-face))
+ (get-text-property (1- (point)) 'completion--string))
(setq beg (point)))
(t (error "No completion here")))
- (setq beg (previous-single-property-change beg 'mouse-face))
+ (setq beg (or (previous-single-property-change
+ beg 'completion--string)
+ beg))
(substring-no-properties
(get-text-property beg 'completion--string))))))
((and (memq this-command '(completion-at-point minibuffer-complete))
(equal (this-command-keys) [backtab]))
(goto-char (point-max))
- (previous-completion 1))
- (t (next-completion 1))))))
+ (last-completion))
+ (t (first-completion))))))
(defun read-expression-switch-to-completions ()
"Select the completion list window while reading an expression."
(completing-read-with-minibuffer-setup
'("aa" "ab" "ac")
(execute-kbd-macro (kbd "a TAB"))
+ (should (and (get-buffer-window "*Completions*" 0)
+ (eq (current-buffer) (get-buffer "*Completions*"))))
+ (execute-kbd-macro (kbd "TAB TAB TAB"))
+ (should (and (get-buffer-window "*Completions*" 0)
+ (eq (current-buffer) (get-buffer " *Minibuf-1*"))))
+ (execute-kbd-macro (kbd "S-TAB"))
(should (and (get-buffer-window "*Completions*" 0)
(eq (current-buffer) (get-buffer "*Completions*"))))))
(let ((completion-auto-select 'second-tab))
(should (equal "aa" (get-text-property (point) 'completion--string)))
(next-completion 2)
(should (equal "ac" (get-text-property (point) 'completion--string)))
- ;; FIXME: bug#54374
- ;; (next-completion 1)
- ;; (should (equal "ac" (get-text-property (point) 'completion--string)))
- (previous-completion 1)
- (should (equal "ab" (get-text-property (point) 'completion--string)))))
+ ;; Fixed in bug#54374
+ (next-completion 5)
+ (should (equal "ac" (get-text-property (point) 'completion--string)))
+ (previous-completion 5)
+ (should (equal "aa" (get-text-property (point) 'completion--string)))))
(let ((completion-wrap-movement t))
(completing-read-with-minibuffer-setup
'("aa" "ab" "ac")
(should (equal "ac" (get-text-property (point) 'completion--string))))))
(ert-deftest completions-header-format-test ()
- (let ((completions-header-format nil)
- (completion-show-help nil))
+ (let ((completion-show-help nil)
+ (completions-header-format nil))
(completing-read-with-minibuffer-setup
'("aa" "ab" "ac")
(insert "a")
(minibuffer-completion-help)
(switch-to-completions)
- ;; FIXME: bug#55430
- ;; (should (equal "aa" (get-text-property (point) 'completion--string)))
- ;; FIXME: bug#54374
- ;; (previous-completion 1)
- ;; (should (equal "ac" (get-text-property (point) 'completion--string)))
- ;; (next-completion 1)
- ;; (should (equal "aa" (get-text-property (point) 'completion--string)))
- ;; FIXME: bug#55430
- ;; (choose-completion nil t)
- ;; (should (equal (minibuffer-contents) "aa"))
- )
+ ;; Fixed in bug#55430
+ (should (equal "aa" (get-text-property (point) 'completion--string)))
+ (next-completion 2)
+ (should (equal "ac" (get-text-property (point) 'completion--string)))
+ (previous-completion 2)
+ (should (equal "aa" (get-text-property (point) 'completion--string)))
+ ;; Fixed in bug#54374
+ (previous-completion 1)
+ (should (equal "ac" (get-text-property (point) 'completion--string)))
+ (next-completion 1)
+ (should (equal "aa" (get-text-property (point) 'completion--string)))
+ ;; Fixed in bug#55430
+ (execute-kbd-macro (kbd "C-u RET"))
+ (should (equal (minibuffer-contents) "aa")))
(completing-read-with-minibuffer-setup
'("aa" "ab" "ac")
- ;; FIXME: bug#55289
- ;; (execute-kbd-macro (kbd "a M-<up> M-<down>"))
- ;; (should (equal (minibuffer-contents) "aa"))
- )))
+ ;; Fixed in bug#55289
+ (execute-kbd-macro (kbd "a M-<up> M-<down>"))
+ (should (equal (minibuffer-contents) "aa")))))
(ert-deftest completions-affixation-navigation-test ()
(let ((completion-extra-properties
(switch-to-completions)
(should (equal 'highlight (get-text-property (point) 'mouse-face)))
(should (equal "aa" (get-text-property (point) 'completion--string)))
- (next-completion 1)
+ (let ((completion-wrap-movement t))
+ (next-completion 3))
+ (should (equal 'highlight (get-text-property (point) 'mouse-face)))
+ (should (equal "aa" (get-text-property (point) 'completion--string)))
+ (let ((completion-wrap-movement nil))
+ (next-completion 3))
(should (equal 'highlight (get-text-property (point) 'mouse-face)))
- (should (equal "ab" (get-text-property (point) 'completion--string)))
+ (should (equal "ac" (get-text-property (point) 'completion--string)))
+ ;; Fixed in bug#54374
(goto-char (1- (point-max)))
- ;; FIXME: bug#54374
- ;; (choose-completion nil t)
- ;; (should (equal (minibuffer-contents) "ac"))
- )))
+ (should-not (equal 'highlight (get-text-property (point) 'mouse-face)))
+ (execute-kbd-macro (kbd "C-u RET"))
+ (should (equal (minibuffer-contents) "ac")))))
(provide 'minibuffer-tests)
;;; minibuffer-tests.el ends here