emacs: Can't Kill Minibuffer
Asked Answered
M

3

5

I am fairly new to emacs, and I'm having a problem with the minibuffer remaining active when I don't think it should be. I have the following mapping for 'other-window:

 (global-set-key (kbd "M-s M-s") 'other-window)

I know that this will cycle through the minibuffer if it is active, and I like that behavior. The problem is that my minibuffer keeps getting stuck in the following state:

Next element matching (regexp):

It gets in there sometimes when I am not even trying to do a regex search or even a search at all. When I hit C-g to kill it, I get the Quit message, but the minibuffer stays active and goes right back to

Next element matching (regexp): 

Also, when it is in this state, I cannot use M-s M-s to get to the next window in my frame. C-x o still seems to work though.

I also seem to be able to run other minibuffer commnands (such as file search) just fine, even when I'm stuck like this.

Is there a way that I can do one of the following:

  1. Kill the minibuffer when in that mode.
  2. Set my custom 'other-window M-s M-s function to get out of the minibuffer and on to the next window?

Either solution would be fine, though the 1st might be better since getting the minibuffer stuck may have other unexpected consequences.

Mapes answered 9/5, 2014 at 16:18 Comment(0)
A
5

Just do this:

(define-key minibuffer-local-map "\M-s" nil)

The problem is that M-s is locally bound in the minibuffer (in minibuffer-local-must-match-map and other minibuffer keymaps) to next-matching-history-element, which gives you that prompt and lets you search the history.

What you need to do is unbind M-s in each of the minibuffer keymaps: i.e., bind it to nil. Some of those maps inherit from others; minibuffer-local-map should take care of it, but you might want to do the same thing for minibuffer-local-ns-map. M-x apropos-variable minibuffer map tells you about all of the maps.

[You can use C-h M-k to see the bindings of any keymap, e.g., minibuffer-local-must-match-map -- it is available in library help-fns+.el.]

Adria answered 9/5, 2014 at 17:2 Comment(3)
This looks to be what's causing my problem. The bit of code you supplied doesn't remove the local map of M-s though. Any suggestions or places I can look to find how to fix it?Mapes
I doubt there is a local map for M-s. Isearch uses M-s as a prefix, but that should not interfere, and you probably want to be able to use Isearch in the minibuffer. Did you try what I suggested? Works for me. If it doesn't work for you, try starting Emacs with emacs -Q. If it works then (without your init file), find what part of your init file conflicts. Perhaps something you load makes another use of M-s.Adria
Actually, it did work. Required a restart of emacs. Simply running M-x eval-buffer wasn't enough. The help-fns+.el library is also quite helpful. Thanks!Mapes
A
2

Likely what is happening is that you're doing a search (thus the prompt Next element matching (regexp):), and using your M-s M-s to stop the search.

What this actually does is just switch to a different buffer, but leaves the search active.

One change you could do is change your behavior, and use C-g to quit out of the search, and return you to the buffer you were searching. This is good to know in case you're in an Emacs that doesn't have your customization. You can also use the M-s M-s to switch back into the minibuffer, and then quit out with C-g.

But, I think your binding could be updated by doing:

(global-set-key (kbd "M-s M-s") 'my-other-window)

(defun my-other-window (count)
  (interactive "p")
  (if (and (>= (recursion-depth) 1) (active-minibuffer-window))
      (abort-recursive-edit)
    (other-window count)))

Which will automatically quit the minibuffer if it is active (and implicitly switch back to the original buffer), otherwise it'll just switch windows as requested.

Alienation answered 9/5, 2014 at 16:34 Comment(0)
H
1

You've now heard where the problem is coming from. As for how to get out of it, use C-].

Hermetic answered 9/5, 2014 at 18:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.