I have the command
kill-this-buffer bound to
C-x C-x. yet it seems it doesn't work in all buffers (such as the calendar month view etc. yet the emacs menu
close always does work. whats the difference between the two (the menu
close doesn't seem to have a keybind) and how does one bind it to a key?
I have the command
In whatever buffer your keyboard shortcut does not work as expected, type
C-h k or
M-x describe-key and then your keyboard shortcut to see what function it is actually bound to -- major-modes and minor-modes can override global key bindings.
For example, in the
*Calendar* buffer type
C-h k C-x C-x and see that it is bound to
calendar-exchange-point-and-mark, which is defined in the
Some people like a global minor-mode for custom keybindings, whereas others may chose to unset / remove major-mode and minor-mode bindings that conflict with global-bindings. And others may choose to assign additional major-mode / minor-mode bindings for certain functions.
The menu bar's
kill-this-buffer. The problem, as @lawlist describes, is that your global
C-x C-x binding is being overwritten by
C-c <letter> key sequences are reserved for the user, so try a global binding such as
C-c k instead.
Also note that
kill-this-buffer is part of the
menu-bar package (written long before the convention that all symbols of a package need to be prefixed by the package name was strictly enforced). The code is as below:
(defun kill-this-buffer () ; for the menu bar "Kill the current buffer. When called in the minibuffer, get out of the minibuffer using `abort-recursive-edit'." (interactive) (cond ;; Don't do anything when `menu-frame' is not alive or visible ;; (Bug#8184). ((not (menu-bar-menu-frame-live-and-visible-p))) ((menu-bar-non-minibuffer-window-p) (kill-buffer (current-buffer))) (t (abort-recursive-edit))))
I've experienced issues with it not working sometimes (presumably when
(not (menu-bar-menu-frame-live-and-visible-p))), so I just bind
C-c k to
(lambda () (interactive) (kill-buffer (current-buffer))).