From c8c83655f71d3061cabffc02724c7d2b8657bcab Mon Sep 17 00:00:00 2001 From: Jakob L. Kreuze Date: Thu, 2 Jul 2020 21:13:48 -0400 Subject: Only set `comint-terminfo-terminal' in shell-mode. --- lisp/shell.el | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'lisp') diff --git a/lisp/shell.el b/lisp/shell.el index 7045880..81fc82a 100644 --- a/lisp/shell.el +++ b/lisp/shell.el @@ -12,6 +12,14 @@ ;;; [1]: https://ambrevar.xyz/emacs-eshell-versus-shell/index.html ;;; +(defmacro with-temporary-bindings (bindings &rest form) + "Weak and partially underspecified macro to temporarily set +`bindings', undoing them when `form' has finished evaluating." + `(unwind-protect + (progn ,@(mapcar #'(lambda (form) (cons 'setq form)) bindings) + ,@form) + (progn ,@(mapcar #'(lambda (form) `(setq ,(car form) ,(eval (car form)))) bindings)))) + ;; I dislike the default behavior of creating a new window upon invoking ;; `shell', but there isn't a better way of dealing with that. (defun shell-same-window (&optional buffer) @@ -24,6 +32,10 @@ (setq n (1+ n))) (setq buffer (switch-to-buffer buffer-name))) + ;; Don't play 'dumb', but don't ruin it for other modes that use comint. + ;; (make-local-variable 'comint-terminfo-terminal) + ;; (setq comint-terminfo-terminal "xterm-256color") + (with-connection-local-variables ;; On remote hosts, the local `shell-file-name' might be useless. (when (file-remote-p default-directory) @@ -47,20 +59,18 @@ (unless (file-exists-p startfile) (setq startfile (concat user-emacs-directory "init_" name ".sh"))) (setq-local shell--start-prog (file-name-nondirectory prog)) - (apply #'make-comint-in-buffer "shell" buffer prog - (if (file-exists-p startfile) startfile) - (if (and xargs-name (boundp xargs-name)) - (symbol-value xargs-name) - '("-i"))) + (setq comint-terminfo-terminal "xterm-256color") + (with-temporary-bindings ((comint-terminfo-terminal "xterm-256color")) + (apply #'make-comint-in-buffer "shell" buffer prog + (if (file-exists-p startfile) startfile) + (if (and xargs-name (boundp xargs-name)) + (symbol-value xargs-name) + '("-i")))) (shell-mode)))) buffer) ;; Use ANSI colors in `shell' (and elsewhere!?). (use-package xterm-color - ;; Don't play 'dumb'. - :init - (setq comint-terminfo-terminal "xterm-256color") - ;; Use the same colors as Alacritty. :init (setq xterm-color-names -- cgit v1.3