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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 47417 in the body.
You can then email your comments to 47417 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#47417; Package emacs. (Fri, 26 Mar 2021 19:19:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to rswgnu <at> gmail.com:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 26 Mar 2021 19:19:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Robert Weiner <rsw <at> gnu.org>
To: bug-gnu-emacs <at> gnu.org
Subject: Expand/fix use of completion-no-auto-exit flag
Date: Fri, 26 Mar 2021 15:18:26 -0400
[Message part 1 (text/plain, inline)]
It seems to me a high-level view of completion-no-auto-exit is to allow
code outside of choose-completion and choose-completion-string to finish
the completion selection process.  Presently, this flag does inhibit
closure of the minibuffer when choosing a completion but it does not
inhibit closure of the list of completions if '?' has been used.  I think
the two are connected and that whatever external code is used to utilize
the finalized completion should also handle the closure of the completion
window.

This can be accomplished by simply wrapping the call to 'quit-window'
within 'choose-completion' with an '(unless completion-no-auto-exit...)'
like so:
         (unless completion-no-auto-exit (quit-window nil (posn-window
(event-start event))))

Please consider adding this as a quick fix.  Then packages like Hyperbole
which requires 2 clicks/presses to finalize a completion selection could
use choose-completion without having to replace the whole function.

Thanks,

Bob
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#47417; Package emacs. (Tue, 13 Apr 2021 19:46:02 GMT) Full text and rfc822 format available.

Message #8 received at 47417 <at> debbugs.gnu.org (full text, mbox):

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: Re: bug#47417: Expand/fix use of completion-no-auto-exit flag
Date: Tue, 13 Apr 2021 22:30:35 +0300
[Message part 1 (text/plain, inline)]
> It seems to me a high-level view of completion-no-auto-exit is to allow
> code outside of choose-completion and choose-completion-string to finish
> the completion selection process.  Presently, this flag does inhibit
> closure of the minibuffer when choosing a completion but it does not
> inhibit closure of the list of completions if '?' has been used.  I think
> the two are connected and that whatever external code is used to utilize
> the finalized completion should also handle the closure of the completion
> window.

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.

So to keep backward-compatibility of completion-no-auto-exit,
its behavior should not be changed.

Then there are two options: create a new variable, e.g.
completion-no-auto-quit - to not quit the completion window.

Or better to support a new value of the existing variable
completion-no-auto-exit, e.g. 'no-quit-window'.

> This can be accomplished by simply wrapping the call to 'quit-window'
> within 'choose-completion' with an '(unless completion-no-auto-exit...)'
> like so:
>          (unless completion-no-auto-exit (quit-window nil (posn-window
> (event-start event))))
>
> Please consider adding this as a quick fix.  Then packages like Hyperbole
> which requires 2 clicks/presses to finalize a completion selection could
> use choose-completion without having to replace the whole function.

Please describe the use cases in more details.  When I tried to use
the aforementioned condition, then after selecting a completion,
the selected window is not switched to the minibuffer window.
The completion window says selected.  I'm not sure if this is what is needed.
It seems after selecting a completion without quitting the completion window,
it's expected that the minibuffer window should be selected.

[completion-no-auto-exit.patch (text/x-diff, inline)]
diff --git a/lisp/simple.el b/lisp/simple.el
index 12435a0680..fd17749451 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -8850,10 +8850,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.
+When the prefix ARG is 0, 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)
@@ -8861,6 +8863,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 (eq arg 0) t completion-no-auto-exit))
           (choice
            (save-excursion
              (goto-char (posn-point (event-start event)))

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#47417; Package emacs. (Wed, 15 Dec 2021 17:45:02 GMT) Full text and rfc822 format available.

Message #11 received at 47417 <at> debbugs.gnu.org (full text, mbox):

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: Re: 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)

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#47417; Package emacs. (Sat, 12 Mar 2022 19:14:02 GMT) Full text and rfc822 format available.

Message #14 received at 47417 <at> debbugs.gnu.org (full text, mbox):

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: Re: bug#47417: Expand/fix use of completion-no-auto-exit flag
Date: Sat, 12 Mar 2022 20:40:18 +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.

This is a copy of the patch from emacs-devel.
It adds two new arguments to 'choose-completion':
'no-exit' that doesn't exit the minibuffer and
'no-quit' that doesn't quit the completions window.

[choose-completion-no-auto-exit.patch (text/x-diff, inline)]
diff --git a/lisp/simple.el b/lisp/simple.el
index accc119e2b..72521b13dc 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9039,6 +9039,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 [remap keyboard-quit] #'delete-completion-window)
     (define-key map [left] 'previous-completion)
@@ -9151,10 +9159,16 @@ next-completion
     (when (/= 0 n)
       (switch-to-minibuffer))))
 
-(defun choose-completion (&optional event)
+(defun choose-completion (&optional event no-exit no-quit)
   "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 prefix argument NO-EXIT, insert the completion at point to the
+minibuffer, but don't exit the minibuffer.  When the prefix argument
+is not provided, then whether to exit the minibuffer depends on the value
+of `completion-no-auto-exit'.
+If NO-QUIT is non-nil, insert the completion at point to the
+minibuffer, but don't quit the completions window."
+  (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)
@@ -9162,6 +9176,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 no-exit t completion-no-auto-exit))
           (choice
            (save-excursion
              (goto-char (posn-point (event-start event)))
@@ -9179,7 +9195,8 @@ choose-completion
 
       (unless (buffer-live-p buffer)
         (error "Destination buffer is dead"))
-      (quit-window nil (posn-window (event-start event)))
+      (unless no-quit
+        (quit-window nil (posn-window (event-start event))))
 
       (with-current-buffer buffer
         (choose-completion-string
@@ -9189,6 +9206,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)

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#47417; Package emacs. (Tue, 05 Apr 2022 18:24:02 GMT) Full text and rfc822 format available.

Message #17 received at 47417 <at> debbugs.gnu.org (full text, mbox):

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: Re: bug#47417: Expand/fix use of completion-no-auto-exit flag
Date: Tue, 05 Apr 2022 21:22:25 +0300
close 47417 29.0.50
thanks

> It adds two new arguments to 'choose-completion':
> 'no-exit' that doesn't exit the minibuffer and
> 'no-quit' that doesn't quit the completions window.

Now pushed to master.  I guess this implements the request,
so closing now.




bug marked as fixed in version 29.0.50, send any further explanations to 47417 <at> debbugs.gnu.org and rswgnu <at> gmail.com Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Tue, 05 Apr 2022 18:24:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 04 May 2022 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 357 days ago.

Previous Next


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