From c4eac600dffc7cfd04e260059cb40757f46fa8a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miha=20Rihtar=C5=A1i=C4=8D?= Date: Mon, 15 Nov 2021 23:13:03 +0100 Subject: [PATCH 2/5] Input fontification for M-x shell * lisp/shell.el (shell-comint-fl-enable): New user option to control input fontification. (shell-indirect-setup-hook): New hook. (shell-mode): Set up and enable input fontification. --- lisp/shell.el | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lisp/shell.el b/lisp/shell.el index 370532ea46..a91a59f070 100644 --- a/lisp/shell.el +++ b/lisp/shell.el @@ -306,6 +306,22 @@ shell-input-autoexpand (const :tag "on" t)) :group 'shell) +(defcustom shell-comint-fl-enable t + "Enable highlighting of input in shell buffers. +This variable only has effect when the shell is started. Use the +command `comint-fl-mode' to toggle highlighting of input." + :type 'boolean + :group 'shell + :safe 'booleanp + :version "29.1") + +(defcustom shell-indirect-setup-hook nil + "Hook run after setting up an indirect shell fontification buffer." + :type 'boolean + :group 'shell + :safe 'booleanp + :version "29.1") + (defvar shell-dirstack nil "List of directories saved by pushd in this buffer's shell. Thus, this does not include the shell's current directory.") @@ -516,6 +532,8 @@ shell-completion-vars (put 'shell-mode 'mode-class 'special) +(defvar sh-shell-file) + (define-derived-mode shell-mode comint-mode "Shell" "Major mode for interacting with an inferior shell. \\ @@ -572,6 +590,11 @@ shell-mode control whether input and output cause the window to scroll to the end of the buffer." :interactive nil + :after-hook + (and (null comint-use-prompt-regexp) + shell-comint-fl-enable + (comint-fl-mode)) + (setq comint-prompt-regexp shell-prompt-pattern) (shell-completion-vars) (setq-local paragraph-separate "\\'") @@ -591,6 +614,19 @@ shell-mode (setq-local ansi-color-apply-face-function #'shell-apply-ansi-color) (shell-reapply-ansi-color) + (add-hook 'comint-indirect-setup-hook + #'shell-indirect-setup-hook 'append t) + (setq comint-indirect-setup-function + (let ((shell shell--start-prog)) + (lambda () + (require 'sh-script) + (cl-letf + (((default-value 'sh-shell-file) + (or shell sh-shell-file)) + (inhibit-message t) + (message-log-max nil)) + (sh-mode))))) + ;; This is not really correct, since the shell buffer does not really ;; edit this directory. But it is useful in the buffer list and menus. (setq list-buffers-directory (expand-file-name default-directory)) @@ -645,6 +681,10 @@ shell-mode ": [[:digit:]]+:[[:digit:]]+;"))) (comint-read-input-ring t))) +(defun shell-indirect-setup-hook () + "Run `shell-indirect-setup-hook'." + (run-hooks 'shell-indirect-setup-hook)) + (defun shell-apply-ansi-color (beg end face) "Apply FACE as the ansi-color face for the text between BEG and END." (when face -- 2.34.0