Subject: [PATCH] Detect XTerm versions for non-VT100 emulation modes
From: "W. Trevor King" <[email-masked]>
To: [email-masked]
Cc: "W. Trevor King" <[email-masked]>
Date: Wed, 5 Feb 2014 08:47:39 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

* term/xterm.el (xterm--version-handler): Handle cases where the
  terminal type is not zero.  The three numbers in the {CSI}>{Ps}c
  response are: Pp (terminal type), Pv (firmware version), and Pc
  (always zero for xterm).  Before this commit, Emacs only looked at
  Pv if Pp was zero (VT100).  However, for XTerm v280 and later, the
  default emulation is for VT420 (Pp = 41).  See the XTerm changelog
  for details:
  http://invisible-island.net/xterm/xterm.log-contents.html#xterm_280
---
I sent this in a few hours ago, but it doesn't look like it made it to
the list.  I wasn't subscribed to the list then, so it's possible the
original is queued for moderator approval.  I didn't get any message
to that effect though, so I just signed up and am sending this
resubmission ;).

Another useful link (the source for my control code information) is
http://invisible-island.net/xterm/ctlseqs/ctlseqs.html, but I didn't
work that into my commit message.  Let me know if that's worth a
resubmit.

Cheers,
Trevor

 lisp/term/xterm.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el
index 87f8c96..3d1b28b 100644
--- a/lisp/term/xterm.el
+++ b/lisp/term/xterm.el
@@ -500,8 +500,8 @@ 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))))
+    (when (string-match "\\([0-9]+\\);\\([0-9]+\\);0" str)
+      (let ((version (string-to-number (match-string 2 str))))
         ;; If version is 242 or higher, assume the xterm supports
         ;; reporting the background color (TODO: maybe earlier
         ;; versions do too...)
-- 
1.8.5.2.8.g0f6c0d1