Subject: Re: bug#17378: 24.3.1: xterm-mouse-event: Wrong type argument: wholenump, -6

From: Stefan Monnier <[email-masked]>
Date: Sun, 04 May 2014 21:43:16 -0400

> Here's the backtrace.
> Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
>   xterm-mouse--read-event-sequence-1000()
>   xterm-mouse-event(nil)
>   xterm-mouse-translate-1()
>   xterm-mouse-translate(nil)

Good, thanks.  Just one more detail:

do M-x load-library RET xt-mouse.el RET
before producing the backtrace, so we get the backtrace of the
uncompiled code, which should give us many more details.

My guess is that xterm-mouse-last is somehow still nil sometimes (and
other times its value comes from yet elsewhere).

So the patch below should hopefully avoid the crash.  It will probably
end up generating incorrect events instead (e.g. mouse-1 when you
release the mouse-3 button).

        Stefan

=== modified file 'lisp/xt-mouse.el'
--- lisp/xt-mouse.el	2014-04-20 02:29:38 +0000
+++ lisp/xt-mouse.el	2014-05-05 01:40:59 +0000
@@ -161,10 +161,10 @@
 	   (cond ((>= code 64)
 		  (format "mouse-%d" (- code 60)))
 		 ((memq code '(8 9 10))
-		  (setq xterm-mouse-last code)
+		  (setq xterm-mouse-last (- code 8))
 		  (format "M-down-mouse-%d" (- code 7)))
 		 ((= code 11)
-		  (format "M-mouse-%d" (- xterm-mouse-last 7)))
+		  (format "M-mouse-%d" (+ 1 (or xterm-mouse-last 0))))
 		 ((= code 3)
 		  ;; For buttons > 5 xterm only reports a
 		  ;; button-release event.  Avoid error by mapping