Why does the elisp function not work (as I expect it to)?
I was wanting to write something that would开发者_开发百科 move back one window in emacs, and bind to C-x S-o
(global-set-key [C-x S-o] '(other-window -1))
When I load a .emacs containg it, something breaks, all my scroll bars reappear (having previously been disabled), and C-x S-O
functions exactly as C-x o
.
A fix would be nice, but I'd also be grateful for an explanation of why it doesn't work.
You can't call functions with parameters directly like that in global-set-key
. It should be like this:
(global-set-key [C-x S-o] (lambda() (interactive) (other-window -1)))
which wraps the function you want in an anonymous interactive form.
You've messed up the key vector, and I believe you have to use a single function name, with no arguments, to make this work:
(global-set-key "\C-xO" 'my-other-window)
(defun my-other-window ()
(interactive)
(other-window -1)
)
See the manual for more details:
(info "(emacs)Init Rebinding")
There were two problems with your code:
- You need interactive in the form which you're binding to a key (it's also worth reading the wiki)
- It's a good idea to use
kbd
to read in the key binding you want,
e.g.(global-set-key (kbd "C-x O") '...)
精彩评论