* lisp/term/xterm.el (xterm--version-handler): Work around for OSX
[bpt/emacs.git] / lisp / term / xterm.el
index 86f4583..5d4112b 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
@@ -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")
+          ;; OSX's Terminal.app (version 2.3 (309), 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...)
@@ -606,7 +617,7 @@ We run the first FUNCTION whose STRING matches the input events."
   (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))
 
@@ -728,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))))
@@ -742,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