Emacs/elisp: global-set-key bindings not taking effect for Meta-<down> or -<up>?

匆匆过客 提交于 2019-12-24 07:00:31

问题


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:


  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.

  2. What you saw briefly was probably ESC <up>, which is equivalent to M-<up>.

  3. Did you perhaps mean to type "When I run M-x scroll-up-line (instead of down)?

  4. 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.

  5. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!