开发者

"screen" somehow unmaps my arrow keys in emacs after a ^Z

开发者 https://www.devze.com 2023-02-02 01:02 出处:网络
Every time I use emacs, I can use the arrow keys just fine to move the cursor around.But when I\'m running emacs within screen, and开发者_如何学编程 I push emacs to the background (ctrl-Z) then return

Every time I use emacs, I can use the arrow keys just fine to move the cursor around. But when I'm running emacs within screen, and开发者_如何学编程 I push emacs to the background (ctrl-Z) then return it to the foreground, my arrow keys no longer work, e.g.

M-[ a is undefined

This behavior doesn't happen when I'm running emacs outside of screen.

Any ideas? Is this some screen setting?


For what it's worth, this just happened to me, and I was able to correct it by disconnecting from screen and then reconnecting:

Ctrl+A, d

screen -R


The vt100 terminal that Screen (and just about every other terminal emulator) emulates has two modes, normal mode and application mode. Normal mode is used for line-by-line applications and application mode for full-screen applications. Amongst the differences between the modes is that the arrow keys send different control sequences (I don't know why): e.g. ESC O A in full screen mode and ESC [ A in normal mode. It seems that when you press Ctrl+Z, Emacs switches the terminal back to normal mode, but when you return it to the foreground, it doesn't switch to full screen mode again, or Screen does not react to Emacs's commands properly.

One possible workaround is to bind the same character sequences in both modes in your .screenrc, e.g.

bindkey -k ku stuff ^[OA
bindkey -k kd stuff ^[OB
bindkey -k kr stuff ^[OC
bindkey -k kl stuff ^[OD

Another possible workaround is to tell Emacs to interpret both key sequences regardless of what the terminal says. Although this is in principle a bad idea since some terminals might use these key sequences for different keys, I've never encountered such an incompatible terminal, and I suspect none have been made in the last 20 years or more.

(define-key function-key-map "\eOA" [up])
(define-key function-key-map "\e[A" [up])
(define-key function-key-map "\eOB" [down])
(define-key function-key-map "\e[B" [down])
(define-key function-key-map "\eOC" [right])
(define-key function-key-map "\e[C" [right])
(define-key function-key-map "\eOD" [left])
(define-key function-key-map "\e[D" [left])

A true solution would involve finding what's causing the problem. It could be a bug in Screen, a bug in Emacs, a bug in the terminal (emulator) that Screen is running in, a bug or misconfiguration in your termcap or terminfo database. If you want to investigate this, start by mentioning your operating system, what terminal (emulator)(s) Screen is running in, where you obtained Screen (or how you compiled it, if that's what you did) and what version, ditto for Emacs, whether you've observed the same problem outside Screen, the output of echo $TERM and echo -E "$TERMCAP" inside Screen.


I had my xterm window full screen and was in screen and this happened. I double clicked the xterm border to go out of full screen. Ctrl-z to background emacs. Then fg to bring it back and then the arrow keys worked. I could go into full screen without any issues.

I should proly learn all the emacs navigation commands but my old habits of migrating to the arrow keys die hard :/


First, push emacs to background.

Ctrl+z 

and bring to forefront again.

fg


Not an answer, but worth noting that the described behaviour also occurs when running GNU emacs on tmux on Ubuntu's Terminal or xterm

Quick work around is to not run emacs in tmux.

Versions

Emacs: GNU Emacs 24.3.1 (x86_64-pc-linux-gnu) of 2014-06-06 on brownie, modified by Debian)

tmux: 1.9

Ubuntu: 14.10


We're having the same problem here, a workaround we found, (but we still need to find the origin of the problem) is to set the "application sequence" manually from within emacs:

  • Navigate to your *scratch* buffer
  • Paste: (send-string-to-terminal "\e[?1h")
  • M-x eval-buffer

and voilà.

Also, a simple C-z fg may be enough, and is faster to type þ


Here's a solution that worked for me to unbreak it once broken (ubuntu 14.04, emacs 24.1). Without detaching from the screen try the following:

1) Ctrl-z to stop emacs.

2) Start another emacs: emacs -nw

3) Ctrl-z in second emacs, and voila!, first emacs will work again. (I then reopen the second emacs and close it Ctrl-x Ctrl-c).

0

精彩评论

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

关注公众号