Why does Ctrl+. not work when I bind it to a command in Emacs?

送分小仙女□ 提交于 2019-12-17 04:02:02

问题


C-. doesn't work in the terminal when I bind it to a command in Emacs. I tried this procedure on gnome-terminal and real terminal tty1. I start Emacs with the -nw flag, then press C-h k (the command for describe-key), then press C-.. Emacs only receives the ., without the Ctrl. How do I get this working in Emacs?

I'm binding keys with this process:

(define-key c-mode-base-map (kbd "C-.") 'semantic-ia-fast-jump)

or

(define-key c-mode-base-map [(control .)] 'semantic-ia-fast-jump)

回答1:


In short, most terminal emulators are limited in the control characters they can produce (for the simple reason that the original terminals that they are emulating were likewise limited).

So your terminal is very likely not producing anything other than . when you press C-. (and if that's the case, that's basically your answer, unless there is some way to configure the terminal to do otherwise).

(Any time you think Emacs is not acting on some input when running in a terminal, you should attempt to verify that Emacs is actually receiving the input you think it is.)

If your terminal is producing something other than ., then refer to the following Q&As for details on how to get Emacs to recognise the sequence:

  • Binding M-<up> / M-<down> in Emacs 23.1.1
  • Shift-Tab produces cryptic error in Emacs
  • http://www.gnu.org/savannah-checkouts/gnu/emacs/manual/html_node/elisp/Translation-Keymaps.html

If you can run an xterm instead then you are probably in luck, due to some xterm-specific enhancements. Take a look at the following:

  • Send "C-(" to Emacs in VT100/xterm terminal (Mac OS X's Terminal)?
  • http://www.dur.ac.uk/p.j.heslin/Software/Emacs/Download/xterm-extras.el
    (I'm not sure that second link is relevant in this specific instance, but it seems worth including).

Some other related Q&As:

  • How does one send S-RET to Emacs in a terminal?
  • Why emacs confuse PageDown (<next>) key with M-[?


来源:https://stackoverflow.com/questions/11110801/why-does-ctrl-not-work-when-i-bind-it-to-a-command-in-emacs

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