开发者

Why emacs confuse PageDown (<next>) key with M-[?

I found big distinction in standard emacs-nox and emacs-gtk. I know that emacs console version (emacs-nox)开发者_如何学运维 has problem with some keys (eg Shift-Tab - ), but not with PageDown.

When I have empty .emacs file, and try to recognize command name run by PageDown key (by C-h c), emacs-nox emacs-gtk works normally - pushing PageDown makes scroll-up, and C-h c PageDown print scroll-up in minibuffer.

The problem arise when i try to bind "M-[" key. In .emacs i has only one statement:

(global-set-key (kbd "M-[") 'hippie-expand)

emacs-nox does not recognize command name run by key - it does'nt print in minibuffer anything when C-h c PageDown, insted wriets to buffer "~6". When I try C-h k PageDown I get: M-[ runs the command hippie-expand

emacs-gtk works normally - pushing PageDown makes scroll-up, and C-h c PageDown print scroll-up in minibuffer.

So I guess emacs nox treats PageDown as M-[ and add something extra.

Any idea how to fix this in emacs-nox?

I use emacs v23.2

EDIT:

I tested other case: In .emacs I have only: (global-set-key (kbd "") 'hippie-expand) and both C-h c PageDown and C-h k PageDown works properly (prints hippie-expand), and when in buffer I push PageDown also works good.


The problem has to do with the escape sequence the terminal sends to Emacs. You can check the escape sequence by typing C-v in a terminal window, followed by the key combination. So, for instance, if you type

C-v M-[

you should see something like this in the terminal window:

^[[

If you type

C-v PageDown

you should see

^[[6~

And that explains the problem: the key sequence generated by M-[ is a prefix of the key sequence generated by PageDown. Thus when you bind that prefix to a function (e.g., by globally setting M-[ to 'hippie-expand), you get the following effect when hitting PageDown:

The first two characters (^[[) of PageDown's escape sequence are interpreted as the prefix and thus 'hippie-expand is called. Then the remaining two characters are interpreters like ordinary key strokes, and are thus inserted into the buffer. That's why you see "6~" when you press PageDown.

I think the only way to change this is to convince the terminal to send different sequences for those keys. But the more painless way is just to use a different shortcut than M-[. (I would suggest M-/.)


This has to do with the terminal emulation and how Emacs-nox interprets the escape sequences sent to it by the terminal whenever you hit a key.

It thus depends on your terminal, but you could try to put the following lines in your .emacs file:

(unless window-system
  (define-key input-decode-map "" [next])
  (define-key input-decode-map "" [prior]))

Then move the cursor between the first two "" characters and type C-q PageDown, then move it between the "" in the row underneath and type C-q PageUp. The result should look like this:

(unless window-system
  (define-key input-decode-map "^[[6~" [next])
  (define-key input-decode-map "^[[5~" [prior]))

but note that the ^[ is only a single character (escape) - that's why you cannot simply copy & paste it from this answer.

Do the keys work after restarting emacs-nox?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜