all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Robert Weiner <rsw@gnu.org>
Cc: 47417@debbugs.gnu.org, rswgnu@gmail.com
Subject: bug#47417: Expand/fix use of completion-no-auto-exit flag
Date: Sat, 12 Mar 2022 20:40:18 +0200	[thread overview]
Message-ID: <86tuc36mvp.fsf@mail.linkov.net> (raw)
In-Reply-To: <86sfutzrum.fsf@mail.linkov.net> (Juri Linkov's message of "Wed,  15 Dec 2021 19:43:29 +0200")

[-- Attachment #1: Type: text/plain, Size: 583 bytes --]

>> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: choose-completion-no-auto-exit.patch --]
[-- Type: text/x-diff, Size: 2922 bytes --]

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)

  reply	other threads:[~2022-03-12 18:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-26 19:18 bug#47417: Expand/fix use of completion-no-auto-exit flag Robert Weiner
2021-04-13 19:30 ` Juri Linkov
2021-12-15 17:43   ` Juri Linkov
2022-03-12 18:40     ` Juri Linkov [this message]
2022-04-05 18:22       ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86tuc36mvp.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=47417@debbugs.gnu.org \
    --cc=rsw@gnu.org \
    --cc=rswgnu@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.