diff options
| author | Ted Zlatanov | 2011-06-09 11:58:18 -0500 |
|---|---|---|
| committer | Ted Zlatanov | 2011-06-09 11:58:18 -0500 |
| commit | 59f623b770909ad4d0e71ccedbcbdcabfbe2abc1 (patch) | |
| tree | 78cb0f00442d543299b650ff0d90394f31d5d8fd | |
| parent | cc322c061d712688ec1f25c70b9d945e0f3d49a6 (diff) | |
| download | emacs-59f623b770909ad4d0e71ccedbcbdcabfbe2abc1.tar.gz emacs-59f623b770909ad4d0e71ccedbcbdcabfbe2abc1.zip | |
Add `xterm-extra-capabilities' defcustom for terminals where the xterm capabilities query is not needed or wanted.
* term/xterm.el (xterm): Add defgroup.
(xterm-extra-capabilities): Add defcustom to supply known xterm
capabilities, skip querying them, or query them (default).
(terminal-init-xterm): Use it.
(terminal-init-xterm-modify-other-keys): New function to set up
modifyOtherKeys support to simplify `terminal-init-xterm'.
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/term/xterm.el | 192 |
2 files changed, 131 insertions, 70 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 7b4c4300900..d6e247eeb43 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2011-06-09 Teodor Zlatanov <tzz@lifelogs.com> | ||
| 2 | |||
| 3 | * term/xterm.el (xterm): Add defgroup. | ||
| 4 | (xterm-extra-capabilities): Add defcustom to supply known xterm | ||
| 5 | capabilities, skip querying them, or query them (default). | ||
| 6 | (terminal-init-xterm): Use it. | ||
| 7 | (terminal-init-xterm-modify-other-keys): New function to set up | ||
| 8 | modifyOtherKeys support to simplify `terminal-init-xterm'. | ||
| 9 | |||
| 1 | 2011-06-09 Martin Rudalics <rudalics@gmx.at> | 10 | 2011-06-09 Martin Rudalics <rudalics@gmx.at> |
| 2 | 11 | ||
| 3 | * window.el (resize-window-reset, resize-window-reset-1) | 12 | * window.el (resize-window-reset, resize-window-reset-1) |
diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el index 0db33b5a4de..c2b870bd535 100644 --- a/lisp/term/xterm.el +++ b/lisp/term/xterm.el | |||
| @@ -24,6 +24,23 @@ | |||
| 24 | 24 | ||
| 25 | ;;; Code: | 25 | ;;; Code: |
| 26 | 26 | ||
| 27 | (defgroup xterm nil | ||
| 28 | "XTerm support." | ||
| 29 | :version "24.1" | ||
| 30 | :group 'emacs) | ||
| 31 | |||
| 32 | (defcustom xterm-extra-capabilities 'check | ||
| 33 | "Set to a list if the XTerm supports modifyOtherKeys or | ||
| 34 | reporting the background color. Set to 'check to check for those | ||
| 35 | features. Set to nil to skip the checks." | ||
| 36 | :group 'xterm | ||
| 37 | :type '(choice (const :tag "No" nil) | ||
| 38 | (const :tag "Check" check) | ||
| 39 | ;; NOTE: If you add entries here, make sure to update | ||
| 40 | ;; `tocheck-capabilities' in `terminal-init-xterm' as well. | ||
| 41 | (set (const :tag "modifyOtherKeys support" modifyOtherKeys) | ||
| 42 | (const :tag "report background" reportBackground)))) | ||
| 43 | |||
| 27 | (defvar xterm-function-map | 44 | (defvar xterm-function-map |
| 28 | (let ((map (make-sparse-keymap))) | 45 | (let ((map (make-sparse-keymap))) |
| 29 | 46 | ||
| @@ -460,81 +477,116 @@ | |||
| 460 | (set-keymap-parent map (keymap-parent input-decode-map)) | 477 | (set-keymap-parent map (keymap-parent input-decode-map)) |
| 461 | (set-keymap-parent input-decode-map map))) | 478 | (set-keymap-parent input-decode-map map))) |
| 462 | 479 | ||
| 463 | (xterm-register-default-colors) | 480 | (xterm-register-default-colors) |
| 464 | (tty-set-up-initial-frame-faces) | 481 | (tty-set-up-initial-frame-faces) |
| 465 | 482 | ||
| 466 | ;; Try to turn on the modifyOtherKeys feature on modern xterms. | 483 | ;; Try to turn on the modifyOtherKeys feature on modern xterms. |
| 467 | ;; When it is turned on many more key bindings work: things like | 484 | ;; When it is turned on many more key bindings work: things like |
| 468 | ;; C-. C-, etc. | 485 | ;; C-. C-, etc. |
| 469 | ;; To do that we need to find out if the current terminal supports | 486 | ;; To do that we need to find out if the current terminal supports |
| 470 | ;; modifyOtherKeys. At this time only xterm does. | 487 | ;; modifyOtherKeys. At this time only xterm does. |
| 488 | (when xterm-extra-capabilities | ||
| 471 | (let ((coding-system-for-read 'binary) | 489 | (let ((coding-system-for-read 'binary) |
| 472 | (chr nil) | 490 | (chr nil) |
| 473 | (str nil) | 491 | (str nil) |
| 474 | (recompute-faces nil) | 492 | (background-regex |
| 475 | version) | 493 | "11;rgb:\\([a-f0-9]+\\)/\\([a-f0-9]+\\)/\\([a-f0-9]+\\)") |
| 476 | ;; Pending input can be mistakenly returned by the calls to | 494 | (recompute-faces nil) |
| 477 | ;; read-event below. Discard it. | 495 | ;; If `xterm-extra-capabilities' is 'check, we don't know |
| 478 | (discard-input) | 496 | ;; the capabilities. We need to check for those defined |
| 479 | ;; Try to find out the type of terminal by sending a "Secondary | 497 | ;; as `xterm-extra-capabilities' set options. Otherwise, |
| 480 | ;; Device Attributes (DA)" query. | 498 | ;; we don't need to check for any capabilities because |
| 481 | (send-string-to-terminal "\e[>0c") | 499 | ;; they are given by setting `xterm-extra-capabilities' to |
| 482 | 500 | ;; a list (which could be empty). | |
| 483 | ;; The reply should be of the form: \e [ > NUMBER1 ; NUMBER2 ; NUMBER3 c | 501 | (tocheck-capabilities (when (eq 'check xterm-extra-capabilities) |
| 484 | ;; If the timeout is completely removed for read-event, this | 502 | '(modifyOtherKeys reportBackground))) |
| 485 | ;; might hang for terminals that pretend to be xterm, but don't | 503 | ;; The given capabilities are either the contents of |
| 486 | ;; respond to this escape sequence. RMS' opinion was to remove | 504 | ;; `xterm-extra-capabilities', if it's a list, or an empty |
| 487 | ;; it completely. That might be right, but let's first try to | 505 | ;; list. |
| 488 | ;; see if by using a longer timeout we get rid of most issues. | 506 | (given-capabilities (when (consp xterm-extra-capabilities) |
| 489 | (when (equal (read-event nil nil 2) ?\e) | 507 | xterm-extra-capabilities)) |
| 490 | (when (equal (read-event nil nil 2) ?\[) | 508 | version) |
| 491 | (while (not (equal (setq chr (read-event nil nil 2)) ?c)) | 509 | |
| 492 | (setq str (concat str (string chr)))) | 510 | ;; Do the following if `xterm-extra-capabilities' is anything but nil. |
| 493 | (when (string-match ">0;\\([0-9]+\\);0" str) | 511 | (when xterm-extra-capabilities |
| 494 | (setq version (string-to-number | 512 | ;; 1. Set `version' |
| 495 | (substring str (match-beginning 1) (match-end 1)))) | 513 | |
| 496 | ;; xterm version 242 supports reporting the background | 514 | ;; Pending input can be mistakenly returned by the calls to |
| 497 | ;; color, maybe earlier versions do too... | 515 | ;; read-event below. Discard it. |
| 498 | (when (>= version 242) | 516 | (discard-input) |
| 499 | (send-string-to-terminal "\e]11;?\e\\") | 517 | ;; Try to find out the type of terminal by sending a "Secondary |
| 500 | (when (equal (read-event nil nil 2) ?\e) | 518 | ;; Device Attributes (DA)" query. |
| 501 | (when (equal (read-event nil nil 2) ?\]) | 519 | (send-string-to-terminal "\e[>0c") |
| 502 | (setq str "") | 520 | |
| 503 | (while (not (equal (setq chr (read-event nil nil 2)) ?\\)) | 521 | ;; The reply should be: \e [ > NUMBER1 ; NUMBER2 ; NUMBER3 c |
| 504 | (setq str (concat str (string chr)))) | 522 | ;; If the timeout is completely removed for read-event, this |
| 505 | (when (string-match "11;rgb:\\([a-f0-9]+\\)/\\([a-f0-9]+\\)/\\([a-f0-9]+\\)" str) | 523 | ;; might hang for terminals that pretend to be xterm, but don't |
| 506 | (setq recompute-faces | 524 | ;; respond to this escape sequence. RMS' opinion was to remove |
| 507 | (xterm-maybe-set-dark-background-mode | 525 | ;; it completely. That might be right, but let's first try to |
| 508 | (string-to-number (match-string 1 str) 16) | 526 | ;; see if by using a longer timeout we get rid of most issues. |
| 509 | (string-to-number (match-string 2 str) 16) | 527 | (when (equal (read-event nil nil 2) ?\e) |
| 510 | (string-to-number (match-string 3 str) 16))))))) | 528 | (when (equal (read-event nil nil 2) ?\[) |
| 511 | ;; NUMBER2 is the xterm version number, look for something | 529 | (while (not (equal (setq chr (read-event nil nil 2)) ?c)) |
| 512 | ;; greater than 216, the version when modifyOtherKeys was | 530 | (setq str (concat str (string chr)))) |
| 513 | ;; introduced. | 531 | (when (string-match ">0;\\([0-9]+\\);0" str) |
| 514 | (when (>= version 216) | 532 | (setq version |
| 515 | ;; Make sure that the modifyOtherKeys state is restored when | 533 | (string-to-number |
| 516 | ;; suspending, resuming and exiting. | 534 | (substring str (match-beginning 1) (match-end 1))))))) |
| 517 | (add-hook 'suspend-hook 'xterm-turn-off-modify-other-keys) | 535 | |
| 518 | (add-hook 'suspend-resume-hook 'xterm-turn-on-modify-other-keys) | 536 | ;; 2. If reportBackground is known to be supported, or the |
| 519 | (add-hook 'kill-emacs-hook 'xterm-remove-modify-other-keys) | 537 | ;; version is 242 or higher, assume the xterm supports |
| 520 | (add-hook 'delete-terminal-functions 'xterm-remove-modify-other-keys) | 538 | ;; reporting the background color (TODO: maybe earlier |
| 521 | ;; Add the selected frame to the list of frames that | 539 | ;; versions do too...) |
| 522 | ;; need to deal with modify-other-keys. | 540 | (when (or (memq 'reportBackground given-capabilities) |
| 523 | (push (frame-terminal (selected-frame)) | 541 | (and (memq 'reportBackground tocheck-capabilities) |
| 524 | xterm-modify-other-keys-terminal-list) | 542 | (>= version 242))) |
| 525 | (xterm-turn-on-modify-other-keys)) | 543 | (send-string-to-terminal "\e]11;?\e\\") |
| 526 | 544 | (when (equal (read-event nil nil 2) ?\e) | |
| 527 | ;; Recompute faces here in case the background mode was | 545 | (when (equal (read-event nil nil 2) ?\]) |
| 528 | ;; set to dark. We used to call | 546 | (setq str "") |
| 529 | ;; `tty-set-up-initial-frame-faces' only once, but that | 547 | (while (not (equal (setq chr (read-event nil nil 2)) ?\\)) |
| 530 | ;; caused the light background faces to be computed | 548 | (setq str (concat str (string chr)))) |
| 531 | ;; incorrectly. See: | 549 | (when (string-match background-regex str) |
| 532 | ;; http://permalink.gmane.org/gmane.emacs.devel/119627 | 550 | (setq recompute-faces |
| 533 | (when recompute-faces | 551 | (xterm-maybe-set-dark-background-mode |
| 534 | (tty-set-up-initial-frame-faces)))))) | 552 | (string-to-number (match-string 1 str) 16) |
| 553 | (string-to-number (match-string 2 str) 16) | ||
| 554 | (string-to-number (match-string 3 str) 16))))))) | ||
| 555 | |||
| 556 | ;; 3. If modifyOtherKeys is known to be supported or the | ||
| 557 | ;; version is 216 (the version when modifyOtherKeys was | ||
| 558 | ;; introduced) or higher, initialize the modifyOtherKeys | ||
| 559 | ;; support. | ||
| 560 | (when (or (memq 'modifyOtherKeys given-capabilities) | ||
| 561 | (and (memq 'modifyOtherKeys tocheck-capabilities) | ||
| 562 | (>= version 216))) | ||
| 563 | (terminal-init-xterm-modify-other-keys)) | ||
| 564 | |||
| 565 | ;; Recompute faces here in case the background mode was | ||
| 566 | ;; set to dark. We used to call | ||
| 567 | ;; `tty-set-up-initial-frame-faces' only once, but that | ||
| 568 | ;; caused the light background faces to be computed | ||
| 569 | ;; incorrectly. See: | ||
| 570 | ;; http://permalink.gmane.org/gmane.emacs.devel/119627 | ||
| 571 | (when recompute-faces | ||
| 572 | (tty-set-up-initial-frame-faces))))) | ||
| 535 | 573 | ||
| 536 | (run-hooks 'terminal-init-xterm-hook)) | 574 | (run-hooks 'terminal-init-xterm-hook)) |
| 537 | 575 | ||
| 576 | (defun terminal-init-xterm-modify-other-keys () | ||
| 577 | "Terminal initialization for xterm's modifyOtherKeys support." | ||
| 578 | ;; Make sure that the modifyOtherKeys state is restored when | ||
| 579 | ;; suspending, resuming and exiting. | ||
| 580 | (add-hook 'suspend-hook 'xterm-turn-off-modify-other-keys) | ||
| 581 | (add-hook 'suspend-resume-hook 'xterm-turn-on-modify-other-keys) | ||
| 582 | (add-hook 'kill-emacs-hook 'xterm-remove-modify-other-keys) | ||
| 583 | (add-hook 'delete-terminal-functions 'xterm-remove-modify-other-keys) | ||
| 584 | ;; Add the selected frame to the list of frames that | ||
| 585 | ;; need to deal with modify-other-keys. | ||
| 586 | (push (frame-terminal (selected-frame)) | ||
| 587 | xterm-modify-other-keys-terminal-list) | ||
| 588 | (xterm-turn-on-modify-other-keys)) | ||
| 589 | |||
| 538 | ;; Set up colors, for those versions of xterm that support it. | 590 | ;; Set up colors, for those versions of xterm that support it. |
| 539 | (defvar xterm-standard-colors | 591 | (defvar xterm-standard-colors |
| 540 | ;; The names in the comments taken from XTerm-col.ad in the xterm | 592 | ;; The names in the comments taken from XTerm-col.ad in the xterm |