GNU bug report logs - #47417
Expand/fix use of completion-no-auto-exit flag

Previous Next

Package: emacs;

Reported by: rswgnu <at> gmail.com

Date: Fri, 26 Mar 2021 19:19:01 UTC

Severity: normal

Fixed in version 29.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Juri Linkov <juri <at> linkov.net>
To: Robert Weiner <rsw <at> gnu.org>
Cc: 47417 <at> debbugs.gnu.org, rswgnu <at> gmail.com
Subject: bug#47417: Expand/fix use of completion-no-auto-exit flag
Date: Wed, 15 Dec 2021 19:43:29 +0200
[Message part 1 (text/plain, inline)]
> Currently I'm developing a patch (attached below) that allows to type
> ‘M-0 RET’ on a completion to insert it to the minibuffer, and quit the window
> without exiting the minibuffer.

Below is a better patch.  It binds C-RET to insert the completion to the minibuffer.

Regarding whether to quit the window or not, this question is currently
discussed on emacs-devel.

[choose-completion-no-auto-exit.patch (text/x-diff, inline)]
diff --git a/lisp/simple.el b/lisp/simple.el
index 84928caa31..73c5840e02 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -8979,6 +8992,7 @@ completion-list-mode-map
     (define-key map [follow-link] 'mouse-face)
     (define-key map [down-mouse-2] nil)
     (define-key map "\C-m" 'choose-completion)
+    (define-key map [C-return] 'choose-completion-no-auto-exit)
     (define-key map "\e\e\e" 'delete-completion-window)
     (define-key map [left] 'previous-completion)
     (define-key map [right] 'next-completion)
@@ -9060,10 +9074,12 @@ next-completion
 		    (point) 'mouse-face nil beg))
 	(setq n (1+ n))))))
 
-(defun choose-completion (&optional event)
+(defun choose-completion (&optional event arg)
   "Choose the completion at point.
-If EVENT, use EVENT's position to determine the starting position."
-  (interactive (list last-nonmenu-event))
+If EVENT, use EVENT's position to determine the starting position.
+With the prefix ARG, insert the completion at point to the minibuffer
+and quit the completion window without exiting the minibuffer."
+  (interactive (list last-nonmenu-event current-prefix-arg))
   ;; In case this is run via the mouse, give temporary modes such as
   ;; isearch a chance to turn off.
   (run-hooks 'mouse-leave-buffer-hook)
@@ -9071,6 +9087,7 @@ choose-completion
     (let ((buffer completion-reference-buffer)
           (base-position completion-base-position)
           (insert-function completion-list-insert-choice-function)
+          (completion-no-auto-exit (if arg t completion-no-auto-exit))
           (choice
            (save-excursion
              (goto-char (posn-point (event-start event)))
@@ -9098,6 +9116,14 @@ choose-completion
              (list (choose-completion-guess-base-position choice)))
          insert-function)))))
 
+(defun choose-completion-no-auto-exit (&optional event)
+  "Insert the completion at point to the minibuffer without exiting it.
+Like `choose-completion', it chooses the completion at point,
+inserts it to the minibuffer, but doesn't exit the minibuffer."
+  (interactive (list last-nonmenu-event))
+  (let ((completion-no-auto-exit t))
+    (choose-completion event)))
+
 ;; Delete the longest partial match for STRING
 ;; that can be found before POINT.
 (defun choose-completion-guess-base-position (string)

This bug report was last modified 3 years and 98 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.