Skip to content

Commit 0102ad9

Browse files
committed
Add ghostel-enable-title-tracking defcustom
Allow users to disable the automatic buffer renaming triggered by OSC 2 title sequences. When set to nil, the buffer keeps its original name from ghostel-buffer-name.
1 parent cc48ae3 commit 0102ad9

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

ghostel.el

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ aggressive partial screen updates, but may use more CPU."
173173
"Default buffer name for ghostel terminals."
174174
:type 'string)
175175

176+
(defcustom ghostel-enable-title-tracking t
177+
"Automatically rename the buffer when the terminal title changes.
178+
When non-nil, OSC 2 title sequences update the buffer name to
179+
\"*ghostel: TITLE*\". Set to nil to keep the buffer name fixed."
180+
:type 'boolean)
181+
176182
(defcustom ghostel-kill-buffer-on-exit t
177183
"Kill the buffer when the shell process exits."
178184
:type 'boolean)
@@ -1629,10 +1635,12 @@ This ensures terminal text is visible regardless of the Emacs theme."
16291635

16301636
(defun ghostel--set-title (title)
16311637
"Update the buffer name with TITLE from the terminal.
1632-
Do not overwrite a manual buffer rename."
1633-
(let ((new-name (format "*ghostel: %s*" title)))
1634-
(when (or (null ghostel--managed-buffer-name)
1635-
(equal (buffer-name) ghostel--managed-buffer-name))
1638+
Only acts when `ghostel-enable-title-tracking' is non-nil and the
1639+
buffer has not been manually renamed by the user."
1640+
(when (and ghostel-enable-title-tracking
1641+
(or (null ghostel--managed-buffer-name)
1642+
(equal (buffer-name) ghostel--managed-buffer-name)))
1643+
(let ((new-name (format "*ghostel: %s*" title)))
16361644
(rename-buffer new-name t)
16371645
;; Keep the actual name because `rename-buffer' may uniquify it.
16381646
(setq ghostel--managed-buffer-name (buffer-name)))))

test/ghostel-test.el

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,28 @@ than the full terminal `cols'."
553553
(when (buffer-live-p buf)
554554
(kill-buffer buf)))))
555555

556+
(ert-deftest ghostel-test-title-tracking-disabled ()
557+
"Test that title updates are ignored when `ghostel-enable-title-tracking' is nil."
558+
(let (buf)
559+
(unwind-protect
560+
(cl-letf (((symbol-function 'ghostel--new)
561+
(lambda (&rest _args) 'fake-term))
562+
((symbol-function 'ghostel--apply-palette)
563+
(lambda (&rest _args) nil))
564+
((symbol-function 'ghostel--start-process)
565+
(lambda () nil)))
566+
(let ((ghostel--buffer-counter 0)
567+
(ghostel-enable-title-tracking nil))
568+
(ghostel)
569+
(setq buf (current-buffer))
570+
(with-current-buffer buf
571+
(should (equal "*ghostel*" (buffer-name)))
572+
(ghostel--set-title "Ignored Title")
573+
(should (equal "*ghostel*" (buffer-name)))
574+
(should (equal "*ghostel*" ghostel--managed-buffer-name)))))
575+
(when (buffer-live-p buf)
576+
(kill-buffer buf)))))
577+
556578
;; -----------------------------------------------------------------------
557579
;; Test: CRLF normalization in Zig
558580
;; -----------------------------------------------------------------------
@@ -2628,6 +2650,7 @@ while :; do sleep 0.1; done'\n")
26282650
ghostel-test-module-version-mismatch
26292651
ghostel-test-module-version-newer-than-minimum
26302652
ghostel-test-title-does-not-overwrite-manual-rename
2653+
ghostel-test-title-tracking-disabled
26312654
ghostel-test-immediate-redraw-triggers-on-small-echo
26322655
ghostel-test-immediate-redraw-skips-large-output
26332656
ghostel-test-immediate-redraw-skips-stale-send

0 commit comments

Comments
 (0)