aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorDaniel Colascione2014-04-17 00:54:23 -0700
committerDaniel Colascione2014-04-17 00:54:23 -0700
commitbfc30790686607fac1b7667d3a73d0f46b80e85f (patch)
treed492a6b10405b75ad5341d1e5509b86ad09e75f8 /lisp
parenta3f989d4c430f4788352b2bad801ba99ccf2bb21 (diff)
downloademacs-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')
-rw-r--r--lisp/ChangeLog32
-rw-r--r--lisp/term/screen.el11
-rw-r--r--lisp/term/xterm.el82
-rw-r--r--lisp/xt-mouse.el61
4 files changed, 109 insertions, 77 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a811b876e3c..ab9240c8f82 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,35 @@
12014-04-17 Daniel Colascione <dancol@dancol.org>
2
3 Add support for bracketed paste mode; add infrastructure for
4 managing terminal mode enabling and disabling automatically.
5
6 * xt-mouse.el:
7 (xterm-mouse-mode): Simplify.
8 (xterm-mouse-tracking-enable-sequence)
9 (xterm-mouse-tracking-disable-sequence): New constants.
10 (turn-on-xterm-mouse-tracking-on-terminal)
11 (turn-off-xterm-mouse-tracking-on-terminal): Use
12 tty-mode-set-strings and tty-mode-reset-strings terminal
13 parameters instead of random hooks.
14 (turn-on-xterm-mouse-tracking)
15 (turn-off-xterm-mouse-tracking): Delete.
16
17 * term/xterm.el (xterm-extra-capabilities): Fix bitrotted comment.
18 (xterm-paste-ending-sequence): New constant.
19 (xterm-paste): New command used for bracketed paste support.
20
21 (xterm-modify-other-keys-terminal-list): Delete obsolete variable.
22 (terminal-init-xterm-bracketed-paste-mode): New function.
23 (terminal-init-xterm): Call it.
24 (terminal-init-xterm-modify-other-keys): Use tty-mode-set-strings
25 and tty-mode-reset-strings instead of random hooks.
26 (xterm-turn-on-modify-other-keys)
27 (xterm-turn-off-modify-other-keys)
28 (xterm-remove-modify-other-keys): Delete obsolete functions.
29
30 * term/screen.el: Rewrite to just use the xterm code. Add
31 copyright notice. Mention tmux.
32
12014-04-17 Ian D <dunni@gnu.org> (tiny change) 332014-04-17 Ian D <dunni@gnu.org> (tiny change)
2 34
3 * image-mode.el (image-mode-window-put): Also update the property of 35 * image-mode.el (image-mode-window-put): Also update the property of
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.
diff --git a/lisp/xt-mouse.el b/lisp/xt-mouse.el
index 26a07b46840..b03b2c95394 100644
--- a/lisp/xt-mouse.el
+++ b/lisp/xt-mouse.el
@@ -263,36 +263,27 @@ single clicks are supported. When turned on, the normal xterm
263mouse functionality for such clicks is still available by holding 263mouse functionality for such clicks is still available by holding
264down the SHIFT key while pressing the mouse button." 264down the SHIFT key while pressing the mouse button."
265 :global t :group 'mouse 265 :global t :group 'mouse
266 (let ((do-hook (if xterm-mouse-mode 'add-hook 'remove-hook))) 266 (funcall (if xterm-mouse-mode 'add-hook 'remove-hook)
267 (funcall do-hook 'terminal-init-xterm-hook 267 'terminal-init-xterm-hook
268 'turn-on-xterm-mouse-tracking-on-terminal) 268 'turn-on-xterm-mouse-tracking-on-terminal)
269 (funcall do-hook 'delete-terminal-functions
270 'turn-off-xterm-mouse-tracking-on-terminal)
271 (funcall do-hook 'suspend-tty-functions
272 'turn-off-xterm-mouse-tracking-on-terminal)
273 (funcall do-hook 'resume-tty-functions
274 'turn-on-xterm-mouse-tracking-on-terminal)
275 (funcall do-hook 'suspend-hook 'turn-off-xterm-mouse-tracking)
276 (funcall do-hook 'suspend-resume-hook 'turn-on-xterm-mouse-tracking)
277 (funcall do-hook 'kill-emacs-hook 'turn-off-xterm-mouse-tracking))
278 (if xterm-mouse-mode 269 (if xterm-mouse-mode
279 ;; Turn it on 270 ;; Turn it on
280 (progn 271 (progn
281 (setq mouse-position-function #'xterm-mouse-position-function) 272 (setq mouse-position-function #'xterm-mouse-position-function)
282 (turn-on-xterm-mouse-tracking)) 273 (mapc #'turn-on-xterm-mouse-tracking-on-terminal (terminal-list)))
283 ;; Turn it off 274 ;; Turn it off
284 (turn-off-xterm-mouse-tracking 'force) 275 (mapc #'turn-off-xterm-mouse-tracking-on-terminal (terminal-list))
285 (setq mouse-position-function nil))) 276 (setq mouse-position-function nil)))
286 277
287(defun turn-on-xterm-mouse-tracking () 278(defconst xterm-mouse-tracking-enable-sequence
288 "Enable Emacs mouse tracking in xterm." 279 "\e[?1000h\e[?1006h"
289 (dolist (terminal (terminal-list)) 280 "Control sequence to enable xterm mouse tracking.
290 (turn-on-xterm-mouse-tracking-on-terminal terminal))) 281Enables basic tracking, then extended tracking on
282terminals that support it.")
291 283
292(defun turn-off-xterm-mouse-tracking (&optional _force) 284(defconst xterm-mouse-tracking-disable-sequence
293 "Disable Emacs mouse tracking in xterm." 285 "\e[?1006l\e[?1000l"
294 (dolist (terminal (terminal-list)) 286 "Reset the modes set by `xterm-mouse-tracking-enable-sequence'.")
295 (turn-off-xterm-mouse-tracking-on-terminal terminal)))
296 287
297(defun turn-on-xterm-mouse-tracking-on-terminal (&optional terminal) 288(defun turn-on-xterm-mouse-tracking-on-terminal (&optional terminal)
298 "Enable xterm mouse tracking on TERMINAL." 289 "Enable xterm mouse tracking on TERMINAL."
@@ -302,30 +293,36 @@ down the SHIFT key while pressing the mouse button."
302 (not (string= (terminal-name terminal) "initial_terminal"))) 293 (not (string= (terminal-name terminal) "initial_terminal")))
303 (unless (terminal-parameter terminal 'xterm-mouse-mode) 294 (unless (terminal-parameter terminal 'xterm-mouse-mode)
304 ;; Simulate selecting a terminal by selecting one of its frames 295 ;; Simulate selecting a terminal by selecting one of its frames
296 ;; so that we can set the terminal-local `input-decode-map'.
305 (with-selected-frame (car (frames-on-display-list terminal)) 297 (with-selected-frame (car (frames-on-display-list terminal))
306 (define-key input-decode-map "\e[M" 'xterm-mouse-translate) 298 (define-key input-decode-map "\e[M" 'xterm-mouse-translate)
307 (define-key input-decode-map "\e[<" 'xterm-mouse-translate-extended)) 299 (define-key input-decode-map "\e[<" 'xterm-mouse-translate-extended))
308 (set-terminal-parameter terminal 'xterm-mouse-mode t)) 300 (send-string-to-terminal xterm-mouse-tracking-enable-sequence terminal)
309 (send-string-to-terminal "\e[?1000h" terminal) 301 (push xterm-mouse-tracking-enable-sequence
310 ;; Request extended mouse support, if available (xterm >= 277). 302 (terminal-parameter nil 'tty-mode-set-strings))
311 (send-string-to-terminal "\e[?1006h" terminal))) 303 (push xterm-mouse-tracking-disable-sequence
304 (terminal-parameter nil 'tty-mode-reset-strings))
305 (set-terminal-parameter terminal 'xterm-mouse-mode t))))
312 306
313(defun turn-off-xterm-mouse-tracking-on-terminal (terminal) 307(defun turn-off-xterm-mouse-tracking-on-terminal (terminal)
314 "Disable xterm mouse tracking on TERMINAL." 308 "Disable xterm mouse tracking on TERMINAL."
315 ;; Only send the disable command to those terminals to which we've already 309 ;; Only send the disable command to those terminals to which we've already
316 ;; sent the enable command. 310 ;; sent the enable command.
317 (when (and (terminal-parameter terminal 'xterm-mouse-mode) 311 (when (and (terminal-parameter terminal 'xterm-mouse-mode)
318 (eq t (terminal-live-p terminal)) 312 (eq t (terminal-live-p terminal)))
319 ;; Avoid the initial terminal which is not a termcap device.
320 ;; FIXME: is there more elegant way to detect the initial terminal?
321 (not (string= (terminal-name terminal) "initial_terminal")))
322 ;; We could remove the key-binding and unset the `xterm-mouse-mode' 313 ;; We could remove the key-binding and unset the `xterm-mouse-mode'
323 ;; terminal parameter, but it seems less harmful to send this escape 314 ;; terminal parameter, but it seems less harmful to send this escape
324 ;; command too many times (or to catch an unintended key sequence), than 315 ;; command too many times (or to catch an unintended key sequence), than
325 ;; to send it too few times (or to fail to let xterm-mouse events 316 ;; to send it too few times (or to fail to let xterm-mouse events
326 ;; pass by untranslated). 317 ;; pass by untranslated).
327 (send-string-to-terminal "\e[?1000l" terminal) 318 (send-string-to-terminal xterm-mouse-tracking-disable-sequence terminal)
328 (send-string-to-terminal "\e[?1006l" terminal))) 319 (setf (terminal-parameter nil 'tty-mode-set-strings)
320 (remq xterm-mouse-tracking-enable-sequence
321 (terminal-parameter nil 'tty-mode-set-strings)))
322 (setf (terminal-parameter nil 'tty-mode-reset-strings)
323 (remq xterm-mouse-tracking-disable-sequence
324 (terminal-parameter nil 'tty-mode-reset-strings)))
325 (set-terminal-parameter terminal 'xterm-mouse-mode nil)))
329 326
330(provide 'xt-mouse) 327(provide 'xt-mouse)
331 328