shift up-arrow doesn't highlight text emacs iterm2

梦想的初衷 提交于 2019-12-21 04:42:49

问题


I recently had help fixing M-left and so forth here: emacs in terminal meta arrow keybindings, but am unable to fix Shift-up using a similar solution. When I try shift-up I get an error <select> is undefined. I've tried re-mapping it using:

(add-hook 'term-setup-hook                                                                                                                                                                         
'(lambda ()                                                                                                                                                                                      
 (define-key function-key-map "\e[1;9A" [M-up])                                                                                                                                                
 (define-key function-key-map "\e[1;9B" [M-down])                                                                                                                                              
 (define-key function-key-map "\e[1;9C" [M-right])                                                                                                                                             
 (define-key function-key-map "\e[1;2A" [S-up])                                                                                                                                                
 (define-key function-key-map "\e[1;9D" [M-left])))  

But shift remains undefined. I also tried rebinding the key by setting it using the escape sequence returned from cat which is ^[[1;2A. Oddly enough shift down does work. shift-select-mode is marked at t as well.


回答1:


This sounds like a trouble I had accessing a Ubuntu 12.04 machine via Putty, when END caused Emacs 23.3.1 to say <select> is undefined. That turned out to be an issue with the terminfo that lets programs use terminals in a device independent way.

Based on this 2008 bug report discussion, I solved my problem by adding the following to the top of my ~/.bashrc:

#so the END key will work correctly in Emacs over PuTTY
TERM=xterm-vt220

N.B., with either xterm-vt220 or the default xterm, emacs -Q -nw is getting ESC [ 4 ~ when I press END, ESC O A for Up, and ESC [ A for Shift-Up. (To see what keycodes Emacs is getting, press some buttons and then C-h,l.) For the same keys in the same order, cat says [4~, [A, and [OA...so Up and Shift-Up are oddly reversed.


If you don't want to change your terminfo, see this discussion for a workaround http://lists.gnu.org/archive/html/help-gnu-emacs/2011-05/msg00211.html

You should be able to work around the issue with something like:

(define-key input-decode-map "\e[1;2A" [S-up])

And for this to take effect at the right time, you will have to use in your .emacs something like:

(if (equal "xterm" (tty-type)) (define-key input-decode-map "\e[1;2A" [S-up]))




回答2:


Just to add more information about the solution: https://github.com/arthurnn/dotfiles/blob/8d56f2419da9a4cb654d8941f379d6d5783bdb90/.emacs.d/init.d/setup-bindings.el#L3-L10 this should fix all the cases including emacsclient. The last line is responsible for fixing the Shift-up when using emacsclient.



来源:https://stackoverflow.com/questions/10871745/shift-up-arrow-doesnt-highlight-text-emacs-iterm2

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