summaryrefslogtreecommitdiff
path: root/lisp/shell.el
diff options
context:
space:
mode:
authorJakob L. Kreuze2020-12-04 21:58:58 -0500
committerJakob L. Kreuze2020-12-04 21:58:58 -0500
commit25636bc58f29c12a38f4ee265cdb715d6b835d8e (patch)
tree9ee1207aa162b9240797c8739ca1f73b5c86e8c9 /lisp/shell.el
parent4a0f0e56577ab6ed49d1f039f27c0f2847b63a1e (diff)
Implement modeline title for shell-mode.
Diffstat (limited to 'lisp/shell.el')
-rw-r--r--lisp/shell.el25
1 files changed, 19 insertions, 6 deletions
diff --git a/lisp/shell.el b/lisp/shell.el
index 843f51e..1b42c19 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -89,6 +89,18 @@
(remove 'ansi-color-process-output
comint-output-filter-functions))
+ :init
+ (defun xterm-title-filter (string)
+ "Pre-match filter for setting a buffer-local variable
+`shell-title' upon reading the ANSI escape sequence for setting
+the terminal emulator's window title."
+ (let ((pattern (rx "\033]0;"
+ (group-n 1 (one-or-more (not "\007")))
+ "\007")))
+ (when (string-match pattern string)
+ (setq-local shell-title (match-string 1 string))))
+ string)
+
:hook
(shell-mode .
(lambda ()
@@ -97,7 +109,8 @@
;; Prevent font-locking from being re-enabled in this buffer
(make-local-variable 'font-lock-function)
(setq font-lock-function (lambda (_) nil))
- (add-hook 'comint-preoutput-filter-functions 'xterm-color-filter nil t))))
+ (add-hook 'comint-preoutput-filter-functions 'xterm-color-filter nil t)
+ (add-hook 'comint-preoutput-filter-functions 'xterm-title-filter nil t))))
@@ -129,9 +142,9 @@
(let* ((pmark (process-mark proc))
(intxt (if (>= (point) (marker-position pmark))
(progn (if comint-eol-on-send
- (if comint-use-prompt-regexp
- (end-of-line)
- (goto-char (field-end))))
+ (if comint-use-prompt-regexp
+ (end-of-line)
+ (goto-char (field-end))))
(buffer-substring pmark (point)))
(let ((copy (funcall comint-get-old-input)))
(goto-char pmark)
@@ -147,7 +160,7 @@
(args (cl-rest (split-string input " ")))
(visual (cl-member command visual-commands :test #'string=)))
(cond ((string= command "man") (man (string-join args " "))
- (shell-fake-comint-send pmark))
+ (shell-fake-comint-send pmark))
(visual (start-process
"" nil "alacritty"
"--class" (format "*%s*,*%s*" command command)
@@ -187,6 +200,6 @@ Kills the buffer when the shell program quits."
(defun add-shell-sentinel (&rest args)
(ignore args)
(set-process-sentinel (get-buffer-process (current-buffer))
- #'shell-kill-buffer-on-quit))
+ #'shell-kill-buffer-on-quit))
(add-hook 'shell-mode-hook #'add-shell-sentinel)

© 2015 - 2026 Jakob L. Kreuze