aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Colascione2016-11-02 21:17:48 -0700
committerDaniel Colascione2016-11-02 21:17:48 -0700
commite5cdb5ce7d4ad96b7cd5ca7888e34076b9267eee (patch)
treed67fb10dc83633fec6b0ebb0e5214c5d7042ff7d
parent722e7989fa2efa53a4a4e14e3f358a5b56f3eddd (diff)
downloademacs-e5cdb5ce7d4ad96b7cd5ca7888e34076b9267eee.tar.gz
emacs-e5cdb5ce7d4ad96b7cd5ca7888e34076b9267eee.zip
Revert "Disable bracketed paste in a terminal in char mode"
This change causes regressions, and besides, disabling BPM frame-wide for the sake of one buffer is the wrong solution. This reverts commit cf566b46a6cf85c6d54d0b0db80e32ed6ae8d1ca.
-rw-r--r--lisp/term.el7
-rw-r--r--lisp/term/xterm.el90
2 files changed, 9 insertions, 88 deletions
diff --git a/lisp/term.el b/lisp/term.el
index 5177ab4b921..c067254f414 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -1247,11 +1247,6 @@ intervention from Emacs, except for the escape character (usually C-c)."
1247 (end-of-line) 1247 (end-of-line)
1248 (term-send-input)) 1248 (term-send-input))
1249 (setq term-input-sender save-input-sender)))) 1249 (setq term-input-sender save-input-sender))))
1250
1251 ;; Turn off XTerm bracketed paste (Bug#24639).
1252 (when (fboundp 'xterm-inhibit-bracketed-paste-mode)
1253 (xterm-inhibit-bracketed-paste-mode))
1254
1255 (term-update-mode-line))) 1250 (term-update-mode-line)))
1256 1251
1257(defun term-line-mode () 1252(defun term-line-mode ()
@@ -1261,8 +1256,6 @@ you type \\[term-send-input] which sends the current line to the inferior."
1261 (interactive) 1256 (interactive)
1262 (when (term-in-char-mode) 1257 (when (term-in-char-mode)
1263 (use-local-map term-old-mode-map) 1258 (use-local-map term-old-mode-map)
1264 (when (fboundp 'xterm-inhibit-bracketed-paste-mode)
1265 (xterm-inhibit-bracketed-paste-mode 0))
1266 (term-update-mode-line))) 1259 (term-update-mode-line)))
1267 1260
1268(defun term-update-mode-line () 1261(defun term-update-mode-line ()
diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el
index faf89915536..01c01130e7c 100644
--- a/lisp/term/xterm.el
+++ b/lisp/term/xterm.el
@@ -24,8 +24,6 @@
24 24
25;;; Code: 25;;; Code:
26 26
27(require 'cl-lib)
28
29(defgroup xterm nil 27(defgroup xterm nil
30 "XTerm support." 28 "XTerm support."
31 :version "24.1" 29 :version "24.1"
@@ -767,78 +765,6 @@ We run the first FUNCTION whose STRING matches the input events."
767 basemap 765 basemap
768 (make-composed-keymap map (keymap-parent basemap)))) 766 (make-composed-keymap map (keymap-parent basemap))))
769 767
770(define-minor-mode xterm-inhibit-bracketed-paste-mode
771 "Toggle whether XTerm bracketed paste should be allowed in this buffer.
772With a prefix argument ARG, forbid bracketed paste if ARG is
773positive, and allow it otherwise. If called from Lisp, forbid
774bracketed paste if ARG is omitted or nil, and toggle the state of
775ARG is `toggle'. If XTerm bracketed paste is allowed (the
776default), it will be used to paste text from an X selection upon
777reception of the `xterm-paste' event. Otherwise the selection
778will be inserted character by character, which is much slower.
779Therefore, bracketed paste should only be disabled in buffers
780that can't deal with the `xterm-paste' event, such as terminal
781emulation buffers."
782 :group xterm
783 ;; Update the bracketed paste flag in all terminals that display the
784 ;; current buffer.
785 (mapc #'xterm--update-bracketed-paste (xterm--buffer-terminals)))
786
787(defun xterm--buffer-terminals (&optional buffer)
788 "Return all terminals that contain a window that displays BUFFER.
789BUFFER defaults to the current buffer."
790 (cl-delete-duplicates
791 (cl-loop for window in (get-buffer-window-list buffer nil t)
792 for terminal = (frame-terminal (window-frame window))
793 collect terminal)
794 :test 'eq))
795
796(defun xterm--update-bracketed-paste (&optional terminal)
797 "Enable or disable bracketed paste for TERMINAL.
798TERMINAL must be a live terminal; it defaults to the terminal
799displaying the selected frame. If any buffer displayed on the
800frames of TERMINAL inhibits bracketed paste by enabling
801`xterm-inhibit-bracketed-paste-mode', disable bracketed paste for
802TERMINAL. If there is no such buffer, enable bracketed paste."
803 (unless terminal (setq terminal (frame-terminal)))
804 (cl-check-type terminal terminal-live)
805 (when (xterm--is-xterm terminal)
806 (cl-symbol-macrolet
807 ((enabled-param (terminal-parameter terminal 'xterm--bracketed-paste))
808 (set-strings-param (terminal-parameter terminal 'tty-mode-set-strings))
809 (reset-strings-param
810 (terminal-parameter terminal 'tty-mode-reset-strings)))
811 (let ((is-enabled enabled-param)
812 (should-enable (xterm--bracketed-paste-possible terminal))
813 (enable-seq "\e[?2004h")
814 (disable-seq "\e[?2004l"))
815 (cond
816 ;; Unconditionally send terminal sequences: terminals that
817 ;; don't support bracketed paste just ignore the sequences.
818 ((and (not is-enabled) should-enable)
819 (send-string-to-terminal enable-seq terminal)
820 (push disable-seq reset-strings-param)
821 (push enable-seq set-strings-param)
822 (setq enabled-param t))
823 ((and is-enabled (not should-enable))
824 (send-string-to-terminal disable-seq)
825 (cl-callf2 delete disable-seq reset-strings-param)
826 (cl-callf2 delete enable-seq set-strings-param)
827 (setq enabled-param nil)))))))
828
829(defun xterm--bracketed-paste-possible (terminal)
830 "Return non-nil if bracketed paste could be enabled on TERMINAL.
831If any buffer displayed on the frames of TERMINAL inhibits
832bracketed paste by enabling `xterm-inhibit-bracketed-paste-mode',
833return nil. If there is no such buffer, return non-nil."
834 (cl-check-type terminal terminal-live)
835 (cl-loop for frame being the frames
836 if (eq (frame-terminal frame) terminal)
837 always (cl-loop
838 for window being the windows of frame
839 never (buffer-local-value 'xterm-inhibit-bracketed-paste-mode
840 (window-buffer window)))))
841
842(defun terminal-init-xterm () 768(defun terminal-init-xterm ()
843 "Terminal initialization function for xterm." 769 "Terminal initialization function for xterm."
844 ;; rxvt terminals sometimes set the TERM variable to "xterm", but 770 ;; rxvt terminals sometimes set the TERM variable to "xterm", but
@@ -876,8 +802,9 @@ return nil. If there is no such buffer, return non-nil."
876 (when (memq 'setSelection xterm-extra-capabilities) 802 (when (memq 'setSelection xterm-extra-capabilities)
877 (xterm--init-activate-set-selection))) 803 (xterm--init-activate-set-selection)))
878 804
879 (add-hook 'window-configuration-change-hook #'xterm--update-bracketed-paste) 805 ;; Unconditionally enable bracketed paste mode: terminals that don't
880 (xterm--update-bracketed-paste) 806 ;; support it just ignore the sequence.
807 (xterm--init-bracketed-paste-mode)
881 808
882 (run-hooks 'terminal-init-xterm-hook)) 809 (run-hooks 'terminal-init-xterm-hook))
883 810
@@ -887,6 +814,12 @@ return nil. If there is no such buffer, return non-nil."
887 (push "\e[>4m" (terminal-parameter nil 'tty-mode-reset-strings)) 814 (push "\e[>4m" (terminal-parameter nil 'tty-mode-reset-strings))
888 (push "\e[>4;1m" (terminal-parameter nil 'tty-mode-set-strings))) 815 (push "\e[>4;1m" (terminal-parameter nil 'tty-mode-set-strings)))
889 816
817(defun xterm--init-bracketed-paste-mode ()
818 "Terminal initialization for bracketed paste mode."
819 (send-string-to-terminal "\e[?2004h")
820 (push "\e[?2004l" (terminal-parameter nil 'tty-mode-reset-strings))
821 (push "\e[?2004h" (terminal-parameter nil 'tty-mode-set-strings)))
822
890(defun xterm--init-activate-get-selection () 823(defun xterm--init-activate-get-selection ()
891 "Terminal initialization for `gui-get-selection'." 824 "Terminal initialization for `gui-get-selection'."
892 (set-terminal-parameter nil 'xterm--get-selection t)) 825 (set-terminal-parameter nil 'xterm--get-selection t))
@@ -1067,11 +1000,6 @@ versions of xterm."
1067 (set-terminal-parameter nil 'background-mode 'dark) 1000 (set-terminal-parameter nil 'background-mode 'dark)
1068 t)) 1001 t))
1069 1002
1070(defun xterm--is-xterm (&optional terminal)
1071 "Return non-nil if TERMINAL is an XTerm-like terminal.
1072TERMINAL defaults to the terminal of the selected frame."
1073 (eq (terminal-parameter terminal 'terminal-initted) 'terminal-init-xterm))
1074
1075(provide 'xterm) ;Backward compatibility. 1003(provide 'xterm) ;Backward compatibility.
1076(provide 'term/xterm) 1004(provide 'term/xterm)
1077;;; xterm.el ends here 1005;;; xterm.el ends here