]> code.delx.au - gnu-emacs/blobdiff - lisp/xt-mouse.el
* lisp/xt-mouse.el (turn-on-xterm-mouse-tracking-on-terminal)
[gnu-emacs] / lisp / xt-mouse.el
index 54fd1a44d5b7b35717fb44bc1da285506ce67946..e5e77405b022da018835ef73044cce78e077e88e 100644 (file)
@@ -145,26 +145,25 @@ http://invisible-island.net/xterm/ctlseqs/ctlseqs.html)."
 (defun xterm-mouse--read-event-sequence-1000 ()
   (let* ((code (- (read-event) 32))
          (type
-         (intern
-          ;; For buttons > 3, the release-event looks differently
-          ;; (see xc/programs/xterm/button.c, function EditorButton),
-          ;; and come in a release-event only, no down-event.
-          (cond ((>= code 64)
-                 (format "mouse-%d" (- code 60)))
-                ((memq code '(8 9 10))
-                 (format "M-down-mouse-%d" (- code 7)))
-                ((memq code '(3 11))
-                  (let ((down (car (terminal-parameter
-                                    nil 'xterm-mouse-last-down))))
-                    (when (and down (string-match "[0-9]" (symbol-name down)))
-                      (format (if (eq code 3) "mouse-%s" "M-mouse-%s")
-                              (match-string 0 (symbol-name down))))))
-                ((memq code '(0 1 2))
-                 (format "down-mouse-%d" (+ 1 code))))))
+         ;; For buttons > 3, the release-event looks differently
+         ;; (see xc/programs/xterm/button.c, function EditorButton),
+         ;; and come in a release-event only, no down-event.
+         (cond ((>= code 64)
+                (format "mouse-%d" (- code 60)))
+               ((memq code '(8 9 10))
+                (format "M-down-mouse-%d" (- code 7)))
+               ((memq code '(3 11))
+                 (let ((down (car (terminal-parameter
+                                   nil 'xterm-mouse-last-down))))
+                   (when (and down (string-match "[0-9]" (symbol-name down)))
+                     (format (if (eq code 3) "mouse-%s" "M-mouse-%s")
+                             (match-string 0 (symbol-name down))))))
+               ((memq code '(0 1 2))
+                (format "down-mouse-%d" (+ 1 code)))))
          (x (- (read-event) 33))
          (y (- (read-event) 33)))
     (and type (wholenump x) (wholenump y)
-         (list type x y))))
+         (list (intern type) x y))))
 
 ;; XTerm's 1006-mode terminal mouse click reporting has the form
 ;; <BUTTON> ; <X> ; <Y> <M or m>, where the button and ordinates are
@@ -313,7 +312,8 @@ terminals that support it.")
   "Enable xterm mouse tracking on TERMINAL."
   (when (and xterm-mouse-mode (eq t (terminal-live-p terminal))
             ;; Avoid the initial terminal which is not a termcap device.
-            ;; FIXME: is there more elegant way to detect the initial terminal?
+            ;; FIXME: is there more elegant way to detect the initial
+             ;; terminal?
             (not (string= (terminal-name terminal) "initial_terminal")))
     (unless (terminal-parameter terminal 'xterm-mouse-mode)
       ;; Simulate selecting a terminal by selecting one of its frames
@@ -321,7 +321,13 @@ terminals that support it.")
       (with-selected-frame (car (frames-on-display-list terminal))
         (define-key input-decode-map "\e[M" 'xterm-mouse-translate)
         (define-key input-decode-map "\e[<" 'xterm-mouse-translate-extended))
-      (send-string-to-terminal xterm-mouse-tracking-enable-sequence terminal)
+      (condition-case err
+          (send-string-to-terminal xterm-mouse-tracking-enable-sequence
+                                   terminal)
+        ;; FIXME: This should use a dedicated error signal.
+        (error (if (equal (cadr err) "Terminal is currently suspended")
+                   nil                  ;The sequence will be sent upon resume.
+                 (signal (car err) (cdr err)))))
       (push xterm-mouse-tracking-enable-sequence
             (terminal-parameter nil 'tty-mode-set-strings))
       (push xterm-mouse-tracking-disable-sequence
@@ -339,7 +345,13 @@ terminals that support it.")
     ;; command too many times (or to catch an unintended key sequence), than
     ;; to send it too few times (or to fail to let xterm-mouse events
     ;; pass by untranslated).
-    (send-string-to-terminal xterm-mouse-tracking-disable-sequence terminal)
+    (condition-case err
+        (send-string-to-terminal xterm-mouse-tracking-disable-sequence
+                                 terminal)
+      ;; FIXME: This should use a dedicated error signal.
+      (error (if (equal (cadr err) "Terminal is currently suspended")
+                 nil
+               (signal (car err) (cdr err)))))
     (setf (terminal-parameter nil 'tty-mode-set-strings)
           (remq xterm-mouse-tracking-enable-sequence
                 (terminal-parameter nil 'tty-mode-set-strings)))