emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 0fb5425 2/2: Change icomplete-show-matches-on-no-input behaviour


From: João Távora
Subject: master 0fb5425 2/2: Change icomplete-show-matches-on-no-input behaviour for Icomplete only
Date: Tue, 8 Sep 2020 04:49:05 -0400 (EDT)

branch: master
commit 0fb54254423cd62aea12ab3c76c1da6912e988e1
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>

    Change icomplete-show-matches-on-no-input behaviour for Icomplete only
    
    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          |  6 ++++++
 lisp/icomplete.el | 16 +++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index ebae168..09f7da4 100644
--- 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
diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index eea5580..93514d2 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]