问题
I am trying to bind M-<up>
and M-<down>
to scroll-down-line
and scroll-up-line
respectively as indicated here: https://stackoverflow.com/a/16229080/562139.
This is what I have in my .emacs
:
;; Key bindings
(global-set-key (kbd "M-g") 'goto-line)
;; Scroll line by line
(global-set-key (kbd "M-<down>") 'scroll-up-line)
(global-set-key (kbd "M-<up>") 'scroll-down-line)
Problem:
The scroll key bindings are not taking effect, while the one for goto-line
does.
When I run M-x scroll-down-line
however, emacs prompts me and says
"you can run the command with <M-down>"
Note:
When I run global-set-key (kbd "M-<down>") 'scroll-up-line)
or (global-set-key (kbd "M-<up>") 'scroll-down-line)
directly in the mini-buffer, the bindings take effect! However, I seem to have noticed through the corner of my eye when I do the latter, that pressing M-<up>
actually sends something like ESC ESC-<up>
.
I'm foxed. What gives?
Note: I am running emacs 24.3 in a terminal (via iTerm on OSX with Option key mapped to ESC+) over SSH to a RHEL5 virtual machine.)
Update
I followed the suggestion in this answer and found that pressing M-<up> results in something completely different:
ESC <up> (translated from ESC M-[ A) runs the command
scroll-down-line, which is an interactive compiled Lisp function.
It is bound to <M-up>, ESC <up>.
(scroll-down-line &optional ARG)
I'm going to try binding that key sequence to the function and check the result.
回答1:
Try starting Emacs without your init file:
emacs -Q
, and see if you can reproduce the problem. I do not see the problem, with Emacs 24.3 in terminal mode.What you saw briefly was probably
ESC <up>
, which is equivalent toM-<up>
.Did you perhaps mean to type "When I run
M-x scroll-up-line
(instead ofdown
)?I suspect that you are in some mode that gives a local binding or a minor-mode binding to these keys, which overrides the global binding. To test that, try in a buffer that is in fundamental mode. If that is the case, then to override that overriding you will need to also bind the keys in that mode's keymap.
If you cannot repro the problem starting from
emacs -Q
then bisect your init file (~/.emacs
) recursively until you find the culprit code.
回答2:
Seems key got lost in translation.
Planted a forward-paragraph
at openSuse that way:
(global-set-key [(meta down)] 'forward-paragraph)
来源:https://stackoverflow.com/questions/19256551/emacs-elisp-global-set-key-bindings-not-taking-effect-for-meta-down-or-up