emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs etc/NEWS lisp/ChangeLog lisp/term/xterm.el


From: Dan Nicolaescu
Subject: [Emacs-diffs] emacs etc/NEWS lisp/ChangeLog lisp/term/xterm.el
Date: Mon, 07 Dec 2009 06:31:41 +0000

CVSROOT:        /cvsroot/emacs
Module name:    emacs
Changes by:     Dan Nicolaescu <dann>   09/12/07 06:31:40

Modified files:
        etc            : NEWS 
        lisp           : ChangeLog 
        lisp/term      : xterm.el 

Log message:
        Get the background mode from the terminal for xterm, and set
        faces accordingly.
        * term/xterm.el (xterm-set-background-mode): New function.
        (terminal-init-xterm): Use it in case xterm supports background
        color queries.  Recompute faces after getting the background
        color.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/etc/NEWS?cvsroot=emacs&r1=1.2142&r2=1.2143
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/ChangeLog?cvsroot=emacs&r1=1.16851&r2=1.16852
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/term/xterm.el?cvsroot=emacs&r1=1.62&r2=1.63

Patches:
Index: etc/NEWS
===================================================================
RCS file: /cvsroot/emacs/emacs/etc/NEWS,v
retrieving revision 1.2142
retrieving revision 1.2143
diff -u -b -r1.2142 -r1.2143
--- etc/NEWS    6 Dec 2009 22:36:11 -0000       1.2142
+++ etc/NEWS    7 Dec 2009 06:30:30 -0000       1.2143
@@ -339,6 +339,11 @@
 and let commands run under that user permissions.  It works even when
 `default-directory' is already remote.
 
+*** When running in a new enough xterm (newer than version 242), emacs
+asks xterm what the background color is and it sets up faces
+accordingly for a dark background if needed (the current default is to
+consider the background light).
+
 
 * New Modes and Packages in Emacs 23.2
 

Index: lisp/ChangeLog
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.16851
retrieving revision 1.16852
diff -u -b -r1.16851 -r1.16852
--- lisp/ChangeLog      7 Dec 2009 06:21:27 -0000       1.16851
+++ lisp/ChangeLog      7 Dec 2009 06:31:35 -0000       1.16852
@@ -1,3 +1,12 @@
+2009-12-07  Dan Nicolaescu  <address@hidden>
+
+       Get the background mode from the terminal for xterm, and set
+       faces accordingly.
+       * term/xterm.el (xterm-set-background-mode): New function.
+       (terminal-init-xterm): Use it in case xterm supports background
+       color queries.  Recompute faces after getting the background
+       color.
+
 2009-12-07  Ulrich Mueller  <address@hidden>
 
        * emacs-lisp/bytecomp.el (byte-compile-insert-header): Put the version

Index: lisp/term/xterm.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/term/xterm.el,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -b -r1.62 -r1.63
--- lisp/term/xterm.el  5 Jan 2009 03:23:59 -0000       1.62
+++ lisp/term/xterm.el  7 Dec 2009 06:31:39 -0000       1.63
@@ -462,8 +462,6 @@
       (set-keymap-parent input-decode-map map)))
 
     (xterm-register-default-colors)
-    ;; This recomputes all the default faces given the colors we've just set 
up.
-    (tty-set-up-initial-frame-faces)
     
     ;; Try to turn on the modifyOtherKeys feature on modern xterms.
     ;; When it is turned on many more key bindings work: things like
@@ -472,7 +470,8 @@
     ;; modifyOtherKeys. At this time only xterm does.
     (let ((coding-system-for-read 'binary)
          (chr nil)
-         (str nil))
+         (str nil)
+         version)
       ;; Pending input can be mistakenly returned by the calls to
       ;; read-event below.  Discard it.
       (discard-input)
@@ -491,11 +490,26 @@
          (while (not (equal (setq chr (read-event nil nil 2)) ?c))
            (setq str (concat str (string chr))))
          (when (string-match ">0;\\([0-9]+\\);0" str)
+           (setq version (string-to-number
+                          (substring str (match-beginning 1) (match-end 1))))
+           ;; xterm version 242 supports reporting the background
+           ;; color, maybe earlier versions do too...
+           (when (>= version 242)
+             (send-string-to-terminal "\e]11;?\e\\")
+             (when (equal (read-event nil nil 2) ?\e)
+               (when (equal (read-event nil nil 2) ?\])
+                 (setq str "")
+                 (while (not (equal (setq chr (read-event nil nil 2)) ?\\))
+                   (setq str (concat str (string chr))))
+                 (when (string-match 
"11;rgb:\\([a-f0-9]+\\)/\\([a-f0-9]+\\)/\\([a-f0-9]+\\)" str)
+                   (xterm-set-background-mode
+                    (string-to-number (match-string 1 str) 16)
+                    (string-to-number (match-string 2 str) 16)
+                    (string-to-number (match-string 3 str) 16))))))
            ;; NUMBER2 is the xterm version number, look for something
            ;; greater than 216, the version when modifyOtherKeys was
            ;; introduced.
-           (when (>= (string-to-number
-                      (substring str (match-beginning 1) (match-end 1))) 216)
+           (when (>= version 216)
              ;; Make sure that the modifyOtherKeys state is restored when
              ;; suspending, resuming and exiting.
              (add-hook 'suspend-hook 'xterm-turn-off-modify-other-keys)
@@ -508,6 +522,9 @@
                    xterm-modify-other-keys-terminal-list)
              (xterm-turn-on-modify-other-keys))))))
 
+    ;; This recomputes all the default faces given the colors we've just set 
up.
+    (tty-set-up-initial-frame-faces)
+
     (run-hooks 'terminal-init-xterm-hook))
 
 ;; Set up colors, for those versions of xterm that support it.
@@ -649,5 +666,11 @@
          (delq terminal xterm-modify-other-keys-terminal-list))
     (send-string-to-terminal "\e[>4m" terminal)))
 
+(defun xterm-set-background-mode (redc greenc bluec)
+  ;; Use the heuristic in `frame-set-background-mode' to decide if a
+  ;; frame is dark.
+  (when (< (+ redc greenc bluec) (* .6 (+ 65535 65535 65535)))
+    (set-terminal-parameter nil 'background-mode 'dark)))
+
 ;; arch-tag: 12e7ebdd-1e6c-4b25-b0f9-35ace25e855a
 ;;; xterm.el ends here




reply via email to

[Prev in Thread] Current Thread [Next in Thread]