From: João Távora Date: Sun, 6 Sep 2020 18:03:52 +0000 (+0100) Subject: Change icomplete-show-matches-on-no-input behaviour for Icomplete only X-Git-Tag: emacs-28.0.90~6189 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0fb54254423cd62aea12ab3c76c1da6912e988e1;p=emacs.git 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. --- diff --git a/etc/NEWS b/etc/NEWS index ebae1688429..09f7da49532 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 eea5580408b..93514d2cc81 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