Subject: bug#6594: 23.2; xterm-mouse-mode bug

From: Asher Langton <[email-masked]>
Date: Tue, 26 Jul 2011 11:53:34 -0700

[Apologies if this is a duplicate; I tried both [email-masked]
and the bug-gnu-emacs list yesterday, but neither seems to have
worked.]

I put a print statement in xterm-mouse-event that displayed the values of
type, x, and y. For some arbitrary clicks, here was the output (all in
pairs; mouse-1 and down-mouse-1, I assume):

In xterm-mouse-event with 0,130023656,46
In xterm-mouse-event with 3,130023656,46
In xterm-mouse-event with 0,37,35
In xterm-mouse-event with 3,37,35
In xterm-mouse-event with 0,12,33
In xterm-mouse-event with 3,12,33
In xterm-mouse-event with 0,130023730,17
In xterm-mouse-event with 3,130023730,17

It appears that the value of x jumps to 0x8000000 around the 94th column.
I don't know much about the internals of emacs nor what the valid
character values are here, but this fix works for me on both Linux and OSX:

--- xt-mouse.el	2011-07-25 20:41:03.000000000 -0700
+++ xt-mouse_modified.el	2011-07-25 20:40:39.000000000 -0700
@@ -122,9 +122,11 @@
;; read xterm sequences above ascii 127 (#x7f)
(defun xterm-mouse-event-read ()
   (let ((c (read-char)))
-    (if (> c #x3FFF80)
-        (+ 128 (- c #x3FFF80))
-      c)))
+    (cond ((and (> c #x3FFF80) (< c #x3FFFFF))
+           (+ 128 (- c #x3FFF80)))
+          ((>= c #x8000000)
+           (+ 128 (- c #x8000000)))
+          (t c))))

-Asher