diff options
| author | Dan Nicolaescu | 2009-12-07 06:30:30 +0000 |
|---|---|---|
| committer | Dan Nicolaescu | 2009-12-07 06:30:30 +0000 |
| commit | a91e1f6bf8c2c1a721d660dbb49bede3adde0a38 (patch) | |
| tree | 4e53846dd31c4b8161a35be07dcf79ae19bd900f | |
| parent | 5fa9d1ecf496e0c20ee0f263c64c97c40b9cab35 (diff) | |
| download | emacs-a91e1f6bf8c2c1a721d660dbb49bede3adde0a38.tar.gz emacs-a91e1f6bf8c2c1a721d660dbb49bede3adde0a38.zip | |
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.
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/term/xterm.el | 35 |
3 files changed, 43 insertions, 6 deletions
| @@ -339,6 +339,11 @@ That means, they change `default-directory' to the new users value, | |||
| 339 | and let commands run under that user permissions. It works even when | 339 | and let commands run under that user permissions. It works even when |
| 340 | `default-directory' is already remote. | 340 | `default-directory' is already remote. |
| 341 | 341 | ||
| 342 | *** When running in a new enough xterm (newer than version 242), emacs | ||
| 343 | asks xterm what the background color is and it sets up faces | ||
| 344 | accordingly for a dark background if needed (the current default is to | ||
| 345 | consider the background light). | ||
| 346 | |||
| 342 | 347 | ||
| 343 | * New Modes and Packages in Emacs 23.2 | 348 | * New Modes and Packages in Emacs 23.2 |
| 344 | 349 | ||
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2d2d938639a..1630f37ba4d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2009-12-07 Dan Nicolaescu <dann@ics.uci.edu> | ||
| 2 | |||
| 3 | Get the background mode from the terminal for xterm, and set | ||
| 4 | faces accordingly. | ||
| 5 | * term/xterm.el (xterm-set-background-mode): New function. | ||
| 6 | (terminal-init-xterm): Use it in case xterm supports background | ||
| 7 | color queries. Recompute faces after getting the background | ||
| 8 | color. | ||
| 9 | |||
| 1 | 2009-12-07 Ulrich Mueller <ulm@gentoo.org> | 10 | 2009-12-07 Ulrich Mueller <ulm@gentoo.org> |
| 2 | 11 | ||
| 3 | * emacs-lisp/bytecomp.el (byte-compile-insert-header): Put the version | 12 | * emacs-lisp/bytecomp.el (byte-compile-insert-header): Put the version |
diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el index 0fcccc3508d..bef43776dae 100644 --- a/lisp/term/xterm.el +++ b/lisp/term/xterm.el | |||
| @@ -462,9 +462,7 @@ | |||
| 462 | (set-keymap-parent input-decode-map map))) | 462 | (set-keymap-parent input-decode-map map))) |
| 463 | 463 | ||
| 464 | (xterm-register-default-colors) | 464 | (xterm-register-default-colors) |
| 465 | ;; This recomputes all the default faces given the colors we've just set up. | 465 | |
| 466 | (tty-set-up-initial-frame-faces) | ||
| 467 | |||
| 468 | ;; Try to turn on the modifyOtherKeys feature on modern xterms. | 466 | ;; Try to turn on the modifyOtherKeys feature on modern xterms. |
| 469 | ;; When it is turned on many more key bindings work: things like | 467 | ;; When it is turned on many more key bindings work: things like |
| 470 | ;; C-. C-, etc. | 468 | ;; C-. C-, etc. |
| @@ -472,7 +470,8 @@ | |||
| 472 | ;; modifyOtherKeys. At this time only xterm does. | 470 | ;; modifyOtherKeys. At this time only xterm does. |
| 473 | (let ((coding-system-for-read 'binary) | 471 | (let ((coding-system-for-read 'binary) |
| 474 | (chr nil) | 472 | (chr nil) |
| 475 | (str nil)) | 473 | (str nil) |
| 474 | version) | ||
| 476 | ;; Pending input can be mistakenly returned by the calls to | 475 | ;; Pending input can be mistakenly returned by the calls to |
| 477 | ;; read-event below. Discard it. | 476 | ;; read-event below. Discard it. |
| 478 | (discard-input) | 477 | (discard-input) |
| @@ -491,11 +490,26 @@ | |||
| 491 | (while (not (equal (setq chr (read-event nil nil 2)) ?c)) | 490 | (while (not (equal (setq chr (read-event nil nil 2)) ?c)) |
| 492 | (setq str (concat str (string chr)))) | 491 | (setq str (concat str (string chr)))) |
| 493 | (when (string-match ">0;\\([0-9]+\\);0" str) | 492 | (when (string-match ">0;\\([0-9]+\\);0" str) |
| 493 | (setq version (string-to-number | ||
| 494 | (substring str (match-beginning 1) (match-end 1)))) | ||
| 495 | ;; xterm version 242 supports reporting the background | ||
| 496 | ;; color, maybe earlier versions do too... | ||
| 497 | (when (>= version 242) | ||
| 498 | (send-string-to-terminal "\e]11;?\e\\") | ||
| 499 | (when (equal (read-event nil nil 2) ?\e) | ||
| 500 | (when (equal (read-event nil nil 2) ?\]) | ||
| 501 | (setq str "") | ||
| 502 | (while (not (equal (setq chr (read-event nil nil 2)) ?\\)) | ||
| 503 | (setq str (concat str (string chr)))) | ||
| 504 | (when (string-match "11;rgb:\\([a-f0-9]+\\)/\\([a-f0-9]+\\)/\\([a-f0-9]+\\)" str) | ||
| 505 | (xterm-set-background-mode | ||
| 506 | (string-to-number (match-string 1 str) 16) | ||
| 507 | (string-to-number (match-string 2 str) 16) | ||
| 508 | (string-to-number (match-string 3 str) 16)))))) | ||
| 494 | ;; NUMBER2 is the xterm version number, look for something | 509 | ;; NUMBER2 is the xterm version number, look for something |
| 495 | ;; greater than 216, the version when modifyOtherKeys was | 510 | ;; greater than 216, the version when modifyOtherKeys was |
| 496 | ;; introduced. | 511 | ;; introduced. |
| 497 | (when (>= (string-to-number | 512 | (when (>= version 216) |
| 498 | (substring str (match-beginning 1) (match-end 1))) 216) | ||
| 499 | ;; Make sure that the modifyOtherKeys state is restored when | 513 | ;; Make sure that the modifyOtherKeys state is restored when |
| 500 | ;; suspending, resuming and exiting. | 514 | ;; suspending, resuming and exiting. |
| 501 | (add-hook 'suspend-hook 'xterm-turn-off-modify-other-keys) | 515 | (add-hook 'suspend-hook 'xterm-turn-off-modify-other-keys) |
| @@ -508,6 +522,9 @@ | |||
| 508 | xterm-modify-other-keys-terminal-list) | 522 | xterm-modify-other-keys-terminal-list) |
| 509 | (xterm-turn-on-modify-other-keys)))))) | 523 | (xterm-turn-on-modify-other-keys)))))) |
| 510 | 524 | ||
| 525 | ;; This recomputes all the default faces given the colors we've just set up. | ||
| 526 | (tty-set-up-initial-frame-faces) | ||
| 527 | |||
| 511 | (run-hooks 'terminal-init-xterm-hook)) | 528 | (run-hooks 'terminal-init-xterm-hook)) |
| 512 | 529 | ||
| 513 | ;; Set up colors, for those versions of xterm that support it. | 530 | ;; Set up colors, for those versions of xterm that support it. |
| @@ -649,5 +666,11 @@ versions of xterm." | |||
| 649 | (delq terminal xterm-modify-other-keys-terminal-list)) | 666 | (delq terminal xterm-modify-other-keys-terminal-list)) |
| 650 | (send-string-to-terminal "\e[>4m" terminal))) | 667 | (send-string-to-terminal "\e[>4m" terminal))) |
| 651 | 668 | ||
| 669 | (defun xterm-set-background-mode (redc greenc bluec) | ||
| 670 | ;; Use the heuristic in `frame-set-background-mode' to decide if a | ||
| 671 | ;; frame is dark. | ||
| 672 | (when (< (+ redc greenc bluec) (* .6 (+ 65535 65535 65535))) | ||
| 673 | (set-terminal-parameter nil 'background-mode 'dark))) | ||
| 674 | |||
| 652 | ;; arch-tag: 12e7ebdd-1e6c-4b25-b0f9-35ace25e855a | 675 | ;; arch-tag: 12e7ebdd-1e6c-4b25-b0f9-35ace25e855a |
| 653 | ;;; xterm.el ends here | 676 | ;;; xterm.el ends here |