Subject: Re: bug#58169: 29.0.50; comint-fl-mode fontifies the output

From: <[email-masked]>
Date: Fri, 30 Sep 2022 20:38:54 +0200

Lars Ingebrigtsen <[email-masked]> writes:

> <[email-masked]> writes:
>
>>> Quickly hijacking this bug report to say: can we please announce
>>> comint-fl-mode in NEWS, and say how to turn it off?  I was confused when
>>> M-x shell randomly started to fontify the input line despite me
>>> disabling every font-lock related thing in *shell* buffers.
>>
>> Thanks for reporting, I'll have time to work one these issues in the
>> afternoon.
>
> And I think we should probably rename it to `comint-font-lock-mode',
> because the current name is obscure.

I went with 'comint-fontify-input-mode'. I also made two more
descriptive variable aliases. Patches attached

From ddbad11131d0bfcdef33666c028f3d7070cefc31 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miha=20Rihtar=C5=A1i=C4=8D?= <[email-masked]>
Date: Fri, 30 Sep 2022 20:07:03 +0200
Subject: [PATCH 1/2] comint-fl: Prevent fontification of output as input

* lisp/comint.el (comint-output-filter): Inhibit jit-lock
fontification of inserted process output before marking it with the
'output' filed property (bug#58169).
---
 lisp/comint.el | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/lisp/comint.el b/lisp/comint.el
index e7d2136c84..15c9388ea4 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -2150,24 +2150,26 @@ comint-output-filter
 	    ;; insert-before-markers is a bad thing. XXX
 	    ;; Luckily we don't have to use it any more, we use
 	    ;; window-point-insertion-type instead.
-	    (insert string)
+	    (make-local-variable 'jit-lock-mode)
+	    (let ((jit-lock-mode nil))
+	      (insert string)
 
-	    ;; Advance process-mark
-	    (set-marker (process-mark process) (point))
+	      ;; Advance process-mark
+	      (set-marker (process-mark process) (point))
 
-	    (unless comint-inhibit-carriage-motion
+	      (unless comint-inhibit-carriage-motion
 	      ;; Interpret any carriage motion characters (newline, backspace)
 	      (comint-carriage-motion comint-last-output-start (point)))
 
-	    ;; Run these hooks with point where the user had it.
-	    (goto-char saved-point)
-	    (run-hook-with-args 'comint-output-filter-functions string)
-	    (set-marker saved-point (point))
+	      ;; Run these hooks with point where the user had it.
+	      (goto-char saved-point)
+	      (run-hook-with-args 'comint-output-filter-functions string)
+	      (set-marker saved-point (point))
 
-	    (goto-char (process-mark process)) ; In case a filter moved it.
+	      (goto-char (process-mark process)) ; In case a filter moved it.
 
-	    (unless comint-use-prompt-regexp
-              (comint--mark-as-output comint-last-output-start (point)))
+	      (unless comint-use-prompt-regexp
+                (comint--mark-as-output comint-last-output-start (point))))
 
 	    ;; Highlight the prompt, where we define `prompt' to mean
 	    ;; the most recent output that doesn't end with a newline.
-- 
2.37.2

From f6d07520aaa2156957962397c59093d6b1c4acd7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miha=20Rihtar=C5=A1i=C4=8D?= <[email-masked]>
Date: Fri, 30 Sep 2022 20:28:15 +0200
Subject: [PATCH 2/2] comint-fl: New descriptive aliases and NEWS

* lisp/comint.el (comint-fontify-input-mode): New alias for
'comint-fl-mode' (bug#58169).
* lisp/ielm.el (ielm-fontify-input-enable): New alias for
'ielm-comint-fl-enable'.
* lisp/shell.el (shell-fontify-input-enable): New alias for
'shell-comint-fl-enable'.
* etc/NEWS: Mention the new modes and how to turn them disable or
enable them.
---
 etc/NEWS       | 14 ++++++++++++++
 lisp/comint.el |  2 ++
 lisp/ielm.el   |  2 ++
 lisp/shell.el  |  2 ++
 4 files changed, 20 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index aad1a17ae7..bce6a72481 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1214,6 +1214,14 @@ When nil, this prevents comint from deleting the current input when
 inserting previous input using '<mouse-2>'.  The default is t, to
 preserve past behavior.
 
+---
+*** New minor mode 'comint-fontify-input-mode'.
+This minor mode is enabled by default in "*shell*" and "*ielm*"
+buffers.  It fontifies input text according to 'shell-mode' or
+'emacs-lisp-mode' font-lock rules.  Customize the user options
+'shell-fontify-input-enable' and 'ielm-fontify-input-enable' to nil if
+you don't want to enable input fontification by default.
+
 ** Mwheel
 
 ---
@@ -2513,6 +2521,12 @@ behavior, customize the new 'eshell-lisp-form-nil-is-failure' option.
 Enabling this will automatically kill a "*shell*" buffer as soon as
 the shell session terminates.
 
+---
+*** New minor mode 'shell-highlight-undef-mode'
+Customize 'shell-highlight-undef-enable' to t if you want to enable
+this minor mode in "*shell*" buffers.  It will highlight undefined
+commands with a warning face as you type.
+
 ** Calc
 
 +++
diff --git a/lisp/comint.el b/lisp/comint.el
index 15c9388ea4..3d7218b868 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -3978,6 +3978,8 @@ comint--indirect-buffer
 
 (defvar-local comint--fl-saved-jit-lock-contextually nil)
 
+(defalias 'comint-fontify-input-mode #'comint-fl-mode)
+
 (define-minor-mode comint-fl-mode
   "Enable input fontification in the current comint buffer.
 This minor mode is useful if the current major mode derives from
diff --git a/lisp/ielm.el b/lisp/ielm.el
index ad41cb1f6b..33a5fc8440 100644
--- a/lisp/ielm.el
+++ b/lisp/ielm.el
@@ -483,6 +483,8 @@ ielm-comint-fl-enable
   :safe 'booleanp
   :version "29.1")
 
+(defvaralias 'ielm-fontify-input-enable 'ilem-comint-fl-enable)
+
 (defcustom ielm-indirect-setup-hook nil
   "Hook run in an indirect buffer for input fontification.
 Input fontification and indentation of an IELM buffer, if
diff --git a/lisp/shell.el b/lisp/shell.el
index 18bb372242..33dcb248ab 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -308,6 +308,8 @@ shell-input-autoexpand
 		 (const :tag "on" t))
   :group 'shell)
 
+(defvaralias 'shell-fontify-input-enable 'shell-comint-fl-enable)
+
 (defcustom shell-comint-fl-enable t
   "Enable fontification of input in shell buffers.
 This variable only has effect when the shell is started.  Use the
-- 
2.37.2