Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to empty or clear the emacs minibuffer?

Tags:

emacs

Sometime the content of the minibuffer shows the output of a command (emacs 24). This is not too much of an inconvenience when the output is just one line. It's more annoying when the command is multiple lines long and the minibuffer uses many lines of display that could be used for something else.

Is there a way to clear the content of the minibuffer ?

Note: When I M-! echo usage: foo ; echo the minibuffer content changes to usage: foo.

Note: I'm not in recursive edit, the minibuffer is not active, using C-g, M-x C-g , (message nil), M-x delete-minibuffer-contents, M-: (kill-buffer " Echo Area 0") does not clear the minibuffer

like image 691
Loic Dachary Avatar asked Mar 03 '15 11:03

Loic Dachary


4 Answers

Normally, C-g works just fine in those cases. It'll print "Quit" in the minibufer, which is just one line and unobtrusive enough.

If you need to clear the minibuffer programmatically, call (message nil).

If, for some reason, C-g does not work for you, make a new command and a keybinding for clearing the minibuffer

(defun my-clear-message ()
  (interactive)
  (message nil))

(global-set-key (kbd "C-c c") 'my-clear-message)
like image 127
shakurov Avatar answered Oct 15 '22 12:10

shakurov


My guess, from your description ("the minibuffer is not active") and your replies to other answers, is that it is not the minibuffer that needs clearing - it is the echo area.

This is the same physical space, but the echo area is for output (e.g. message), whereas the minibuffer is primarily for input.

To clear the echo area, use (message nil), as suggested. Or use the minibuffer, followed by C-g - e.g., M-x C-g. That usually takes care of the job (but see below, about killing the echo-area buffer, if you really need to clear it).

If it really is the minibuffer input that you want to clear, then:

  • C-g (repeated, if necessary) quits the minibuffer.
  • You can use any text-clearing keys to clear the input without exiting. E.g., C-x DEL will clear quite a bit (it is backward-kill-sentence). I bind M-k (normally kill-sentence) to a command that deletes all of the minibuffer input (this is the case in Icicles, for instance). Command delete-minibuffer-contents wipes it all out.

(You can also kill the echo-area buffer, if it should ever get polluted with some text you want to get rid of. The buffer will be re-created automatically. With vanilla Emacs it is a bit problematic to do this interactively, but you can at least do it using M-: (kill-buffer " *Echo Area 0*") (note the SPC char prefix).)

like image 45
Drew Avatar answered Oct 15 '22 12:10

Drew


This output is normally cleared as soon as you do anything else in Emacs. But sometimes Emacs gets confused and the message keeps reappearing in the echo area.

Deleting the buffer named *Shell Command Output* would solve the problem, but when this happens to me Emacs refuses to delete this buffer. Deleting the contents of this buffer solves the problem, but output reappears in the buffer the next time you do a shell command.

You can prevent that problem by renaming the buffer. One way to do that is to make that buffer current (e.g., with C-x b or M-x switch-to-buffer) and do M-x rename-uniquely. If you do that and delete the contents of the buffer, the problem is avoided.

I have no idea why sometimes Emacs refuses to kill this buffer, but fortunately it allows renaming it so it will no longer be reused for command output.

like image 43
Larry Engholm Avatar answered Oct 15 '22 12:10

Larry Engholm


Although I do not understand why following clears the minibuffer: M-! echo ; echo

like image 37
Loic Dachary Avatar answered Oct 15 '22 11:10

Loic Dachary