* lisp/url/url-handlers.el (url-http-parse-response): Remove unused autoload.
[bpt/emacs.git] / lisp / term / xterm.el
index dcf32e5..ba017e9 100644 (file)
@@ -1,6 +1,6 @@
 ;;; xterm.el --- define function key sequences and standard colors for xterm  -*- lexical-binding: t -*-
 
-;; Copyright (C) 1995, 2001-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1995, 2001-2014 Free Software Foundation, Inc.
 
 ;; Author: FSF
 ;; Keywords: terminals
@@ -27,7 +27,7 @@
 (defgroup xterm nil
   "XTerm support."
   :version "24.1"
-  :group 'environment)
+  :group 'terminals)
 
 (defcustom xterm-extra-capabilities 'check
   "Whether Xterm supports some additional, more modern, features.
@@ -500,8 +500,19 @@ The relevant features are:
     ;; see if by using a longer timeout we get rid of most issues.
     (while (and (setq chr (read-event nil nil 2)) (not (equal chr ?c)))
       (setq str (concat str (string chr))))
-    (when (string-match "0;\\([0-9]+\\);0" str)
-      (let ((version (string-to-number (match-string 1 str))))
+    ;; Since xterm-280, the terminal type (NUMBER1) is now 41 instead of 0.
+    (when (string-match "\\([0-9]+\\);\\([0-9]+\\);0" str)
+      (let ((version (string-to-number (match-string 2 str))))
+        (when (and (> version 2000) (equal (match-string 1 str) "1"))
+          ;; Hack attack!  bug#16988: gnome-terminal reports "1;NNNN;0"
+          ;; with a large NNNN but is based on a rather old xterm code.
+          ;; Gnome terminal 3.6.1 reports 1;3406;0
+          ;; Gnome terminal 2.32.1 reports 1;2802;0
+          (setq version 200))
+        (when (equal (match-string 1 str) "83")
+          ;; `screen' (which returns 83;40003;0) seems to also lack support for
+          ;; some of these (bug#17607).
+          (setq version 240))
         ;; If version is 242 or higher, assume the xterm supports
         ;; reporting the background color (TODO: maybe earlier
         ;; versions do too...)
@@ -516,6 +527,9 @@ The relevant features are:
           (terminal-init-xterm-modify-other-keys))))))
 
 (defun xterm--query (query handlers)
+  "Send QUERY string to the terminal and watch for a response.
+HANDLERS is an alist with elements of the form (STRING . FUNCTION).
+We run the first FUNCTION whose STRING matches the input events."
   ;; We used to query synchronously, but the need to use `discard-input' is
   ;; rather annoying (bug#6758).  Maybe we could always use the asynchronous
   ;; approach, but it's less tested.
@@ -544,7 +558,8 @@ The relevant features are:
                                  nil))))
           (setq i (1+ i)))
         (if (= i (length (car handler)))
-            (funcall (cdr handler))
+            (progn (setq handlers nil)
+                   (funcall (cdr handler)))
           (while (> i 0)
             (push (aref (car handler) (setq i (1- i)))
                   unread-command-events)))))))
@@ -602,7 +617,7 @@ The relevant features are:
   (add-hook 'delete-terminal-functions 'xterm-remove-modify-other-keys)
   ;; Add the selected frame to the list of frames that
   ;; need to deal with modify-other-keys.
-  (push (frame-terminal (selected-frame))
+  (push (frame-terminal)
       xterm-modify-other-keys-terminal-list)
   (xterm-turn-on-modify-other-keys))
 
@@ -724,7 +739,7 @@ versions of xterm."
 
 (defun xterm-turn-on-modify-other-keys ()
   "Turn the modifyOtherKeys feature of xterm back on."
-  (let ((terminal (frame-terminal (selected-frame))))
+  (let ((terminal (frame-terminal)))
     (when (and (terminal-live-p terminal)
               (memq terminal xterm-modify-other-keys-terminal-list))
       (send-string-to-terminal "\e[>4;1m" terminal))))
@@ -738,7 +753,7 @@ versions of xterm."
 
 (defun xterm-remove-modify-other-keys (&optional terminal)
   "Turn off the modifyOtherKeys feature of xterm for good."
-  (setq terminal (or terminal (frame-terminal (selected-frame))))
+  (setq terminal (or terminal (frame-terminal)))
   (when (and (terminal-live-p terminal)
             (memq terminal xterm-modify-other-keys-terminal-list))
     (setq xterm-modify-other-keys-terminal-list
@@ -752,4 +767,6 @@ versions of xterm."
     (set-terminal-parameter nil 'background-mode 'dark)
     t))
 
+(provide 'xterm)
+
 ;;; xterm.el ends here