all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#17545: 24.4.50; icomplete conflicts with minibuffer default
@ 2014-05-21 15:40 Dan McKinley
  2014-05-21 17:52 ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Dan McKinley @ 2014-05-21 15:40 UTC (permalink / raw)
  To: 17545

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

When completing in the minibuffer using icomplete-mode, an invisible
completion can circumvent the minibuffer's default selection.

For example, say you have icomplete enabled, and you try to kill the
current buffer. The minibuffer will show a confirmation message like,
"Kill buffer (default: foo)". If you type C-j to trigger icomplete
without having actually typed any characters, icomplete will terminate
an unrelated buffer and won't even tell you which it was. It will
terminate whatever buffer it decides is the completion of nothing at
that time.

This is confusing because the minibuffer prompt suggests a completely
different default. Here's a function that fixes the behavior:

(defun icomplete-complete-or-default ()
  (interactive)
  (let* ((start (minibuffer-prompt-end))
         (end (point-max))
         (phrase (buffer-substring start end)))

    (if (zerop (length phrase))
        ; Select the minibuffer's default if there's no text after
        ; the prompt.
        (minibuffer-complete-and-exit)

      ; Select icomplete's default completion if the user has typed
      ; something.
      (minibuffer-force-complete-and-exit))
  ))

Then remapping C-j to call that in the icomplete keymap fixes the bug:

 (defvar icomplete-minibuffer-map
   (let ((map (make-sparse-keymap)))
     (define-key map [?\M-\t] 'minibuffer-force-complete)
-    (define-key map [?\C-j]  'minibuffer-force-complete-and-exit)
+    (define-key map [?\C-j]  'icomplete-complete-or-default)
     (define-key map [?\C-.]  'icomplete-forward-completions)
     (define-key map [?\C-,]  'icomplete-backward-completions)
     map)
   "Keymap used by `icomplete-mode' in the minibuffer.")

I came across this trying to remap icomplete to <return> instead of C-j
so that the keys are more like the (apparently dead) iswitchb. That
doesn't seem like an unreasonable thing to do, although I don't know how
many people used iswitchb.

[-- Attachment #2: Type: text/html, Size: 2635 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-05-19 13:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-21 15:40 bug#17545: 24.4.50; icomplete conflicts with minibuffer default Dan McKinley
2014-05-21 17:52 ` Stefan Monnier
2014-06-01  2:25   ` Stefan Monnier
     [not found]   ` <86zj5439za.fsf@yandex.ru>
     [not found]     ` <jwv4mncr48h.fsf-monnier+emacsbugs@gnu.org>
2015-05-17  1:07       ` Dmitry Gutov
2015-05-18  8:51         ` Slawomir Nowaczyk
2015-05-18 19:41           ` Stephen Leake
2015-05-18 23:30             ` Dmitry Gutov
2015-05-18 16:45         ` Stefan Monnier
2015-05-18 23:20           ` Dmitry Gutov
2015-05-19  1:38             ` Stefan Monnier
2015-05-19 13:06               ` Dmitry Gutov

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.