3

From https://www.gnu.org/software/emacs/manual/html_node/emacs/Mode-Line-Mouse.html :

mouse-3 on a mode line deletes the window it belongs to. If the frame has only one window, it does nothing.

I want to disable this behavior. How do I do it?

4

To unbind it:

(global-set-key [mode-line mouse-3] nil)

To bind it to a different command:

(global-set-key [mode-line mouse-3] 'my-favorite-command)

How did I find this?

C-h k, then right-click the mouse on the mode-line, somewhere where there is no text.

That tells you:

<mode-line> <mouse-3> (translated from <down-mouse-3> <mouse-3>) at that spot runs the command mouse-delete-window, which is an interactive compiled Lisp function in mouse.el.

It is bound to <mode-line> <mouse-3>.

(mouse-delete-window CLICK)

Delete the window you click on.

Do nothing if the frame has just one window.

This command must be bound to a mouse click.

If you then click the mouse.el link it takes you to the command definition. Searching for that command name in the same file, you come across this:

(global-set-key [mode-line mouse-3] 'mouse-delete-window)

You can copy that, changing the command name or replacing it by nil.


Update: I should have also mentioned what @Faried Nawaz mentions, which is a simpler way to unbind the key: use global-unset-key. (So please consider upvoting that answer too.) The result is the same as binding the command to nil. Here is the definition (from subr.el):

(defun global-unset-key (key)
  "Remove global binding of KEY.
KEY is a string or vector representing a sequence of keystrokes."
  (interactive "kUnset key globally: ")
  (global-set-key key nil))
  • Awesome, thanks so much! Unluckily, my own former attempt of M-x describe-key failed because, as you say, one has to click somewhere where there is no text. – vemv Jun 11 '17 at 21:13
3

Evaluate this:

(global-unset-key [mode-line mouse-3])

You might want to M-x customize-variable RET mode-line-default-help-echo RET as well, but that's optional.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.