[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 5a8a5e3d57 2/5: Input fontification for M-x shell
From: |
Lars Ingebrigtsen |
Subject: |
master 5a8a5e3d57 2/5: Input fontification for M-x shell |
Date: |
Fri, 9 Sep 2022 14:14:46 -0400 (EDT) |
branch: master
commit 5a8a5e3d5782e9e138a826e1ce9c06fe501c5343
Author: Miha Rihtaršič <miha@kamnitnik.top>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Input fontification for M-x shell
* lisp/comint.el
(comint-indent-input-line):
(comint-indent-input-line-default):
(comint-indent-input-region):
(comint-indent-input-region-default): New functions that implement a
general mechanism for input indentation through an indirect buffer in
comint derived major modes.
* lisp/shell.el (shell-mode): Set up input indentation according to
sh-mode (bug#51940).
* lisp/comint.el
(comint-indent-input-line):
(comint-indent-input-line-default):
(comint-indent-input-region):
(comint-indent-input-region-default): New functions that implement a
general mechanism for input indentation through an indirect buffer in
comint derived major modes.
* lisp/shell.el (shell-mode): Set up input indentation according to
sh-mode (bug#51940).
---
lisp/shell.el | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/lisp/shell.el b/lisp/shell.el
index 85225b128a..4b11b0ac59 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -99,6 +99,7 @@
(require 'pcomplete)
(eval-when-compile (require 'files-x)) ;with-connection-local-variables
(require 'subr-x)
+(eval-when-compile (require 'cl-lib))
;;; Customization and Buffer Variables
@@ -307,6 +308,22 @@ for Shell mode only."
(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.")
@@ -522,6 +539,8 @@ Shell buffers. It implements `shell-completion-execonly'
for
(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.
\\<shell-mode-map>
@@ -585,6 +604,11 @@ from `shell-mode-hook', Emacs will call the `ding' function
whenever it receives the bell character in output from a
command."
: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 "\\'")
@@ -604,6 +628,19 @@ command."
(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))
@@ -658,6 +695,10 @@ command."
": [[: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