chiark / gitweb /
el/dot-emacs.el: Update terminal titles as we go.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 23 Apr 2020 01:23:13 +0000 (02:23 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 23 Apr 2020 01:23:13 +0000 (02:23 +0100)
el/dot-emacs.el

index 030dbcd7cd952034025ef817e736d4178111d58c..0a5274cc18ce83cfbe014824681574c7d034f19b 100644 (file)
@@ -1868,6 +1868,21 @@ (define-globalized-minor-mode mdw-global-point-overlay-mode
   mdw-point-overlay-mode
   (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t))))
 
+(defvar terminal-title-alist nil)
+(defun mdw-update-terminal-title ()
+  (when (let ((term (frame-parameter nil 'tty-type)))
+         (and term (string-match "^xterm" term)))
+    (let* ((tty (frame-parameter nil 'tty))
+          (old (assoc tty terminal-title-alist #'string=))
+          (new (format-mode-line frame-title-format)))
+      (unless (and old (string= (cdr old) new))
+       (if old (rplacd old new)
+         (setq terminal-title-alist
+               (cons (cons tty new) terminal-title-alist)))
+       (send-string-to-terminal (concat "\e]2;" new "\e\\"))))))
+
+(add-hook 'post-command-hook 'mdw-update-terminal-title)
+
 ;;;--------------------------------------------------------------------------
 ;;; C programming configuration.