Emacs, unicode, xterm mouse escape sequences, and wide terminals

牧云@^-^@ 提交于 2019-11-30 05:00:49
Egmont Koblinger

xterm-262 adds the patch inlined above, however, this patch quite is broken by design. Rxvt-unicode's developers realized it and added yet another, much better extension to report mouse coordinates.

Right now I'm working on getting widespread support for this. Rxvt-unicode and iTerm2 already support both extensions. I created patches for xterm (to support the urxvt extension), and for gnome-terminal, konsole and putty to support both new extension. As for the applications, I've added support for the urxvt extension to Midnight Commander.

Please join me in my effort and try to convince more terminal developers and applications to implement these extensions (at least the urxvt one, because the other one can't be properly automatically recognized by applications).

See http://www.midnight-commander.org/ticket/2662 for technical details and further pointers.

OK, figured it out. There are actually two issues.

First, some source diving shows that xterm clips the mouse-enabled region of the window to 223x223 chars, and sends 0x0 for all other positions.

Second, emacs-23 is UTF-8 aware and gets confused by mouse events having x>160 and y>94; in those cases xterm's encoding for x and y looks like a two-byte UTF-8 character (e.g. 0xC2 0x80) and as a result the mouse sequence seems one character short.

I'm working on a patch for xterm to make mouse events emit UTF-8 (which would both unconfuse emacs-23 and allow terminals up to 2047x2047), but I'm not sure yet how it will turn out.

I think the problem that caused your workaround (and the upstream fix that was included in one of the v22 releases) to stop working in 23.2 is within Emacs itself. 23.1 can handle mouse clicks after column 95 using urxvt, gnu screen, putty or iTerm, but 23.2 can't. Setting everything set to latin-1 makes no difference. 23.1 has the same code in xt-mouse.el. src/lread.c and src/character.h changed, however, and at a glance I'd guess the bug is in there somewhere. As to what happens after column 223, I've got no clue.

For the benefit of anyone else who's annoyed by the xt-mouse regression in 23.2 here's a modified version of xterm-mouse-event-read that works with mouse clicks up to col 222 (credit to Ryan for the >222 overflow handling which my original fix lacked). This probably won't work in 23.1 or before.

(defun xterm-mouse-event-read ()
  (let ((c (read-char)))
    (cond ((= c 0) #x100)  
       ; for positions past col 222 emacs just delivers
       ; 0x0, best we can do is stay at eol 
      ((= 0 (logand c (- #x100))) c) 
      ((logand c #xff))))) 

... Edit: Here's the version from Emacs 24 (bzr head). It works again in 23.2 up to col 222, but lacks the >222 overflow eol handling Ryan suggested:

(defun xterm-mouse-event-read ()
  (let ((c (read-char)))
    (if (> c #x3FFF80)
        (+ 128 (- c #x3FFF80))
      c)))

While xterm now works in utf-8 mode with a patch, this utf-8 hack will break in the worst possible way in any other locale, as the unicode characters will just be dropped unless representable.

rxvt-unicode has (in releases after 9.09) a 1015 mode that sends replies of the form "ESC [ code ; x ; y M", using decimal numbers. This has the advantage of not needing any probing from apps and also working in non-utf-8 locales.

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