Commit 3a09343e authored by Mark Oteiza's avatar Mark Oteiza

Teach Emacs to set XTerm window titles

* lisp/term/xterm.el (terminal-init-xterm): Add initialization.
(xterm--init-frame-title, xterm-set-window-title-flag):
(xterm-unset-window-title-flag, xterm-set-window-title): New functions.
(xterm-window-title-flag): New variable.
(xterm-set-window-title): New custom variable.
* etc/NEWS: Mention it.
parent b1f83c10
......@@ -37,6 +37,11 @@ When you add a new item, use the appropriate mark if you are sure it applies,
* Changes in Specialized Modes and Packages in Emacs 27.1
** Enhanced xterm support
*** New variable 'xterm-set-window-title' controls whether Emacs
sets the XTerm window title. The default is to set the window title.
* New Modes and Packages in Emacs 27.1
......@@ -68,6 +68,11 @@ string bytes that can be copied is 3/4 of this value."
:version "25.1"
:type 'integer)
(defcustom xterm-set-window-title t
"Whether Emacs should set window titles to an Emacs frame in an XTerm."
:version "27.1"
:type 'boolean)
(defconst xterm-paste-ending-sequence "\e[201~"
"Characters send by the terminal to end a bracketed paste.")
......@@ -802,6 +807,8 @@ We run the first FUNCTION whose STRING matches the input events."
(when (memq 'setSelection xterm-extra-capabilities)
(when xterm-set-window-title
;; Unconditionally enable bracketed paste mode: terminals that don't
;; support it just ignore the sequence.
......@@ -828,6 +835,34 @@ We run the first FUNCTION whose STRING matches the input events."
"Terminal initialization for `gui-set-selection'."
(set-terminal-parameter nil 'xterm--set-selection t))
(defun xterm--init-frame-title ()
"Terminal initialization for XTerm frame titles."
(add-hook 'after-make-frame-functions 'xterm-set-window-title-flag)
(add-hook 'window-configuration-change-hook 'xterm-unset-window-title-flag)
(add-hook 'post-command-hook 'xterm-set-window-title)
(add-hook 'minibuffer-exit-hook 'xterm-set-window-title))
(defvar xterm-window-title-flag nil
"Whether a new frame has been created, calling for a title update.")
(defun xterm-set-window-title-flag (_frame)
"Set `xterm-window-title-flag'.
See `xterm--init-frame-title'"
(setq xterm-window-title-flag t))
(defun xterm-unset-window-title-flag ()
(when xterm-window-title-flag
(setq xterm-window-title-flag nil)
(defun xterm-set-window-title (&optional terminal)
"Set the window title of the Xterm TERMINAL.
The title is constructed from `frame-title-format'."
(format "\e]2;%s\a" (format-mode-line frame-title-format))
(defun xterm--selection-char (type)
(pcase type
('PRIMARY "p")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment