diff options
| author | Daniel Colascione | 2014-04-17 00:54:23 -0700 |
|---|---|---|
| committer | Daniel Colascione | 2014-04-17 00:54:23 -0700 |
| commit | bfc30790686607fac1b7667d3a73d0f46b80e85f (patch) | |
| tree | d492a6b10405b75ad5341d1e5509b86ad09e75f8 /lisp/term | |
| parent | a3f989d4c430f4788352b2bad801ba99ccf2bb21 (diff) | |
| download | emacs-bfc30790686607fac1b7667d3a73d0f46b80e85f.tar.gz emacs-bfc30790686607fac1b7667d3a73d0f46b80e85f.zip | |
2014-04-17 Daniel Colascione <dancol@dancol.org>
Add support for bracketed paste mode; add infrastructure for
managing terminal mode enabling and disabling automatically.
* xt-mouse.el:
(xterm-mouse-mode): Simplify.
(xterm-mouse-tracking-enable-sequence)
(xterm-mouse-tracking-disable-sequence): New constants.
(turn-on-xterm-mouse-tracking-on-terminal)
(turn-off-xterm-mouse-tracking-on-terminal): Use
tty-mode-set-strings and tty-mode-reset-strings terminal
parameters instead of random hooks.
(turn-on-xterm-mouse-tracking)
(turn-off-xterm-mouse-tracking): Delete.
* term/xterm.el (xterm-extra-capabilities): Fix bitrotted comment.
(xterm-paste-ending-sequence): New constant.
(xterm-paste): New command used for bracketed paste support.
(xterm-modify-other-keys-terminal-list): Delete obsolete variable.
(terminal-init-xterm-bracketed-paste-mode): New function.
(terminal-init-xterm): Call it.
(terminal-init-xterm-modify-other-keys): Use tty-mode-set-strings
and tty-mode-reset-strings instead of random hooks.
(xterm-turn-on-modify-other-keys)
(xterm-turn-off-modify-other-keys)
(xterm-remove-modify-other-keys): Delete obsolete functions.
* term/screen.el: Rewrite to just use the xterm code. Add
copyright notice. Mention tmux.
Diffstat (limited to 'lisp/term')
| -rw-r--r-- | lisp/term/screen.el | 11 | ||||
| -rw-r--r-- | lisp/term/xterm.el | 82 |
2 files changed, 48 insertions, 45 deletions
diff --git a/lisp/term/screen.el b/lisp/term/screen.el index d37a695086a..69ddda80983 100644 --- a/lisp/term/screen.el +++ b/lisp/term/screen.el | |||
| @@ -1,12 +1,9 @@ | |||
| 1 | ;; Treat a screen terminal similar to an xterm. | 1 | ;;; screen.el --- terminal initialization for screen and tmux -*- lexical-binding: t -*- |
| 2 | (load "term/xterm") | 2 | ;; Copyright (C) 1995, 2001-2014 Free Software Foundation, Inc. |
| 3 | |||
| 4 | (declare-function xterm-register-default-colors "xterm" ()) | ||
| 5 | 3 | ||
| 6 | (defun terminal-init-screen () | 4 | (defun terminal-init-screen () |
| 7 | "Terminal initialization function for screen." | 5 | "Terminal initialization function for screen." |
| 8 | ;; Use the xterm color initialization code. | 6 | ;; Treat a screen terminal similar to an xterm. |
| 9 | (xterm-register-default-colors) | 7 | (tty-run-terminal-initialization (selected-frame) "xterm")) |
| 10 | (tty-set-up-initial-frame-faces)) | ||
| 11 | 8 | ||
| 12 | ;; screen.el ends here | 9 | ;; screen.el ends here |
diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el index eac40141979..33eb61dac1e 100644 --- a/lisp/term/xterm.el +++ b/lisp/term/xterm.el | |||
| @@ -43,10 +43,35 @@ The relevant features are: | |||
| 43 | :type '(choice (const :tag "No" nil) | 43 | :type '(choice (const :tag "No" nil) |
| 44 | (const :tag "Check" check) | 44 | (const :tag "Check" check) |
| 45 | ;; NOTE: If you add entries here, make sure to update | 45 | ;; NOTE: If you add entries here, make sure to update |
| 46 | ;; `tocheck-capabilities' in `terminal-init-xterm' as well. | 46 | ;; `terminal-init-xterm' as well. |
| 47 | (set (const :tag "modifyOtherKeys support" modifyOtherKeys) | 47 | (set (const :tag "modifyOtherKeys support" modifyOtherKeys) |
| 48 | (const :tag "report background" reportBackground)))) | 48 | (const :tag "report background" reportBackground)))) |
| 49 | 49 | ||
| 50 | (defconst xterm-paste-ending-sequence "\e[201~" | ||
| 51 | "Characters send by the terminal to end a bracketed paste.") | ||
| 52 | |||
| 53 | (defun xterm-paste () | ||
| 54 | "Handle the start of a terminal paste operation." | ||
| 55 | (interactive) | ||
| 56 | (let* ((end-marker-length (length xterm-paste-ending-sequence)) | ||
| 57 | (pasted-text (with-temp-buffer | ||
| 58 | (set-buffer-multibyte nil) | ||
| 59 | (while (not (search-backward | ||
| 60 | xterm-paste-ending-sequence | ||
| 61 | (- (point) end-marker-length) t)) | ||
| 62 | (let ((event (read-event))) | ||
| 63 | (when (eql event ?\r) | ||
| 64 | (setf event ?\n)) | ||
| 65 | (insert event))) | ||
| 66 | (let ((last-coding-system-used)) | ||
| 67 | (decode-coding-region | ||
| 68 | (point-min) (point) | ||
| 69 | (keyboard-coding-system) t)))) | ||
| 70 | (interprogram-paste-function (lambda () pasted-text))) | ||
| 71 | (yank))) | ||
| 72 | |||
| 73 | (define-key global-map [xterm-paste] #'xterm-paste) | ||
| 74 | |||
| 50 | (defvar xterm-function-map | 75 | (defvar xterm-function-map |
| 51 | (let ((map (make-sparse-keymap))) | 76 | (let ((map (make-sparse-keymap))) |
| 52 | 77 | ||
| @@ -394,6 +419,11 @@ The relevant features are: | |||
| 394 | (define-key map "\e[12~" [f2]) | 419 | (define-key map "\e[12~" [f2]) |
| 395 | (define-key map "\e[13~" [f3]) | 420 | (define-key map "\e[13~" [f3]) |
| 396 | (define-key map "\e[14~" [f4]) | 421 | (define-key map "\e[14~" [f4]) |
| 422 | |||
| 423 | ;; Recognize the start of a bracketed paste sequence. The handler | ||
| 424 | ;; internally recognizes the end. | ||
| 425 | (define-key map "\e[200~" [xterm-paste]) | ||
| 426 | |||
| 397 | map) | 427 | map) |
| 398 | "Function key map overrides for xterm.") | 428 | "Function key map overrides for xterm.") |
| 399 | 429 | ||
| @@ -463,9 +493,6 @@ The relevant features are: | |||
| 463 | map) | 493 | map) |
| 464 | "Keymap of possible alternative meanings for some keys.") | 494 | "Keymap of possible alternative meanings for some keys.") |
| 465 | 495 | ||
| 466 | ;; List of terminals for which modify-other-keys has been turned on. | ||
| 467 | (defvar xterm-modify-other-keys-terminal-list nil) | ||
| 468 | |||
| 469 | (defun xterm--report-background-handler () | 496 | (defun xterm--report-background-handler () |
| 470 | (let ((str "") | 497 | (let ((str "") |
| 471 | chr) | 498 | chr) |
| @@ -595,21 +622,23 @@ We run the first FUNCTION whose STRING matches the input events." | |||
| 595 | (when (memq 'modifyOtherKeys xterm-extra-capabilities) | 622 | (when (memq 'modifyOtherKeys xterm-extra-capabilities) |
| 596 | (terminal-init-xterm-modify-other-keys))) | 623 | (terminal-init-xterm-modify-other-keys))) |
| 597 | 624 | ||
| 625 | ;; Unconditionally enable bracketed paste mode: terminals that don't | ||
| 626 | ;; support it just ignore the sequence. | ||
| 627 | (terminal-init-xterm-bracketed-paste-mode) | ||
| 628 | |||
| 598 | (run-hooks 'terminal-init-xterm-hook)) | 629 | (run-hooks 'terminal-init-xterm-hook)) |
| 599 | 630 | ||
| 600 | (defun terminal-init-xterm-modify-other-keys () | 631 | (defun terminal-init-xterm-modify-other-keys () |
| 601 | "Terminal initialization for xterm's modifyOtherKeys support." | 632 | "Terminal initialization for xterm's modifyOtherKeys support." |
| 602 | ;; Make sure that the modifyOtherKeys state is restored when | 633 | (send-string-to-terminal "\e[>4;1m") |
| 603 | ;; suspending, resuming and exiting. | 634 | (push "\e[>4m" (terminal-parameter nil 'tty-mode-reset-strings)) |
| 604 | (add-hook 'suspend-hook 'xterm-turn-off-modify-other-keys) | 635 | (push "\e[>4;1m" (terminal-parameter nil 'tty-mode-set-strings))) |
| 605 | (add-hook 'suspend-resume-hook 'xterm-turn-on-modify-other-keys) | 636 | |
| 606 | (add-hook 'kill-emacs-hook 'xterm-remove-modify-other-keys) | 637 | (defun terminal-init-xterm-bracketed-paste-mode () |
| 607 | (add-hook 'delete-terminal-functions 'xterm-remove-modify-other-keys) | 638 | "Terminal initialization for bracketed paste mode." |
| 608 | ;; Add the selected frame to the list of frames that | 639 | (send-string-to-terminal "\e[?2004h") |
| 609 | ;; need to deal with modify-other-keys. | 640 | (push "\e[?2004l" (terminal-parameter nil 'tty-mode-reset-strings)) |
| 610 | (push (frame-terminal) | 641 | (push "\e[?2004h" (terminal-parameter nil 'tty-mode-set-strings))) |
| 611 | xterm-modify-other-keys-terminal-list) | ||
| 612 | (xterm-turn-on-modify-other-keys)) | ||
| 613 | 642 | ||
| 614 | ;; Set up colors, for those versions of xterm that support it. | 643 | ;; Set up colors, for those versions of xterm that support it. |
| 615 | (defvar xterm-standard-colors | 644 | (defvar xterm-standard-colors |
| @@ -727,29 +756,6 @@ versions of xterm." | |||
| 727 | ;; right colors, so clear them. | 756 | ;; right colors, so clear them. |
| 728 | (clear-face-cache))) | 757 | (clear-face-cache))) |
| 729 | 758 | ||
| 730 | (defun xterm-turn-on-modify-other-keys () | ||
| 731 | "Turn the modifyOtherKeys feature of xterm back on." | ||
| 732 | (let ((terminal (frame-terminal))) | ||
| 733 | (when (and (terminal-live-p terminal) | ||
| 734 | (memq terminal xterm-modify-other-keys-terminal-list)) | ||
| 735 | (send-string-to-terminal "\e[>4;1m" terminal)))) | ||
| 736 | |||
| 737 | (defun xterm-turn-off-modify-other-keys (&optional frame) | ||
| 738 | "Temporarily turn off the modifyOtherKeys feature of xterm." | ||
| 739 | (let ((terminal (when frame (frame-terminal frame)))) | ||
| 740 | (when (and (terminal-live-p terminal) | ||
| 741 | (memq terminal xterm-modify-other-keys-terminal-list)) | ||
| 742 | (send-string-to-terminal "\e[>4m" terminal)))) | ||
| 743 | |||
| 744 | (defun xterm-remove-modify-other-keys (&optional terminal) | ||
| 745 | "Turn off the modifyOtherKeys feature of xterm for good." | ||
| 746 | (setq terminal (or terminal (frame-terminal))) | ||
| 747 | (when (and (terminal-live-p terminal) | ||
| 748 | (memq terminal xterm-modify-other-keys-terminal-list)) | ||
| 749 | (setq xterm-modify-other-keys-terminal-list | ||
| 750 | (delq terminal xterm-modify-other-keys-terminal-list)) | ||
| 751 | (send-string-to-terminal "\e[>4m" terminal))) | ||
| 752 | |||
| 753 | (defun xterm-maybe-set-dark-background-mode (redc greenc bluec) | 759 | (defun xterm-maybe-set-dark-background-mode (redc greenc bluec) |
| 754 | ;; Use the heuristic in `frame-set-background-mode' to decide if a | 760 | ;; Use the heuristic in `frame-set-background-mode' to decide if a |
| 755 | ;; frame is dark. | 761 | ;; frame is dark. |