]> git.eshelyaron.com Git - emacs.git/commitdiff
Change icomplete-show-matches-on-no-input behaviour for Icomplete only
authorJoão Távora <joaotavora@gmail.com>
Sun, 6 Sep 2020 18:03:52 +0000 (19:03 +0100)
committerJoão Távora <joaotavora@gmail.com>
Tue, 8 Sep 2020 08:47:48 +0000 (09:47 +0100)
Fixes: bug#19032, bug#43120
Previous fixes to bug#19032 introduced bugs in Fido mode.  This fix
relies on a new command bound to RET.

* etc/NEWS (Miscellaneous): Mention icomplete-show-matches-on-no-input.

* lisp/icomplete.el (icomplete-show-matches-on-no-input): Add comment.
(icomplete-minibuffer-map): Rebind minibuffer-complete-and-exit to
icomplete-ret.
(icomplete-ret): New command.

etc/NEWS
lisp/icomplete.el

index ebae168842918d434208a7b92a43f0d1b388d557..09f7da49532157690b6f8c962007e80f3450f970 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -947,6 +947,12 @@ window after starting).  This variable defaults to nil.
 
 ** Miscellaneous
 
+---
+*** 'icomplete-show-matches-on-no-input' behavior change
+Previously, choosing a different completion with commands like 'C-.'
+and then hitting enter would choose the default completion.  Doing
+this will now choose the completion under point.
+
 +++
 *** The user can now customize how "default" values are prompted for.
 The new utility function 'format-prompt' has been added which uses the
index eea5580408b26b082773a24850f6803ac1268c3b..93514d2cc81680d2a212890a81736d532142dd3c 100644 (file)
@@ -75,7 +75,11 @@ everything preceding the ~/ is discarded so the interactive
 selection process starts again from the user's $HOME.")
 
 (defcustom icomplete-show-matches-on-no-input nil
-  "When non-nil, show completions when first prompting for input."
+  "When non-nil, show completions when first prompting for input.
+This also means that if you traverse the list of completions with
+commands like `C-.' and just hit RET without typing any
+characters, the match under point will be chosen instead of the
+default."
   :type 'boolean
   :version "24.4")
 
@@ -153,12 +157,22 @@ icompletion is occurring."
 (defvar icomplete-minibuffer-map
   (let ((map (make-sparse-keymap)))
     (define-key map [?\M-\t] 'icomplete-force-complete)
+    (define-key map [remap minibuffer-complete-and-exit] 'icomplete-ret)
     (define-key map [?\C-j]  'icomplete-force-complete-and-exit)
     (define-key map [?\C-.]  'icomplete-forward-completions)
     (define-key map [?\C-,]  'icomplete-backward-completions)
     map)
   "Keymap used by `icomplete-mode' in the minibuffer.")
 
+(defun icomplete-ret ()
+  "Exit minibuffer for icomplete."
+  (interactive)
+  (if (and icomplete-show-matches-on-no-input
+           (car completion-all-sorted-completions)
+           (eql (icomplete--field-end) (icomplete--field-beg)))
+      (icomplete-force-complete-and-exit)
+    (exit-minibuffer)))
+
 (defun icomplete-force-complete-and-exit ()
   "Complete the minibuffer with the longest possible match and exit.
 Use the first of the matches if there are any displayed, and use