1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-30 12:21:25 -08:00

Rename comint-fl-* to comint-fontify-input-* and mention it in NEWS

* lisp/comint.el
(comint-fontify-input-mode):
(comint--fontify-input-saved-jit-lock-contextually):
(comint--fontify-input-on):
(comint--fontify-input-off):
(comint--fontify-input-ppss-flush-indirect):
(comint--fontify-input-fontify-region): Replace comint-fl-* with
comint-fontify-input-*.

* lisp/ielm.el (ielm-fontify-input-enable):
(ielm-fontify-input-enable):
(ielm-indirect-setup-hook):
(inferior-emacs-lisp-mode): Replace comint-fl-* with
comint-fontify-input-*.

* lisp/shell.el (shell-comint-fl-enable):
(shell-mode): Replace comint-fl-* with comint-fontify-input-*.

* etc/NEWS: Mention the new modes and how to disable or enable
them (bug#58169).
This commit is contained in:
Miha Rihtaršič 2022-09-30 20:28:15 +02:00 committed by Lars Ingebrigtsen
parent 90744ff0be
commit cd4208f6d8
4 changed files with 59 additions and 44 deletions

View file

@ -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
---
@ -2520,6 +2528,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
+++

View file

@ -1945,7 +1945,7 @@ Similarly for Soar, Scheme, etc."
(when comint-highlight-input
(add-text-properties beg end
'( font-lock-face comint-highlight-input
comint--fl-inhibit-fontification t
comint--fontify-input-inhibit-fontification t
front-sticky t )))
(unless comint-use-prompt-regexp
;; Give old user input a field property of `input', to
@ -3976,9 +3976,9 @@ fontification and other behavior of the indirect buffer."
(defvar-local comint--indirect-buffer nil
"Indirect buffer used for input fontification.")
(defvar-local comint--fl-saved-jit-lock-contextually nil)
(defvar-local comint--fontify-input-saved-jit-lock-contextually nil)
(define-minor-mode comint-fl-mode
(define-minor-mode comint-fontify-input-mode
"Enable input fontification in the current comint buffer.
This minor mode is useful if the current major mode derives from
`comint-mode' and if `comint-indirect-setup-function' is set.
@ -3993,71 +3993,71 @@ This function signals an error if `comint-use-prompt-regexp' is
non-nil. Input fontification isn't compatible with this
setting."
:lighter nil
(if comint-fl-mode
(if comint-fontify-input-mode
(let ((success nil))
(unwind-protect
(progn
(comint--fl-on)
(comint--fontify-input-on)
(setq success t))
(unless success
(setq comint-fl-mode nil)
(comint--fl-off))))
(comint--fl-off)))
(setq comint-fontify-input-mode nil)
(comint--fontify-input-off))))
(comint--fontify-input-off)))
(defun comint--fl-on ()
(defun comint--fontify-input-on ()
"Enable input fontification in the current comint buffer."
(comint--fl-off)
(comint--fontify-input-off)
(when comint-use-prompt-regexp
(error
"Input fontification is incompatible with `comint-use-prompt-regexp'"))
(add-function :around (local 'font-lock-fontify-region-function)
#'comint--fl-fontify-region)
#'comint--fontify-input-fontify-region)
;; `before-change-functions' are only run in the current buffer and
;; not in its indirect buffers, which means that we must manually
;; flush ppss cache
(add-hook 'before-change-functions
#'comint--fl-ppss-flush-indirect 99 t)
#'comint--fontify-input-ppss-flush-indirect 99 t)
;; Set up contextual fontification
(unless (booleanp jit-lock-contextually)
(setq comint--fl-saved-jit-lock-contextually
(setq comint--fontify-input-saved-jit-lock-contextually
jit-lock-contextually)
(setq-local jit-lock-contextually t)
(when jit-lock-mode
(jit-lock-mode t))))
(defun comint--fl-off ()
(defun comint--fontify-input-off ()
"Disable input fontification in the current comint buffer."
(remove-function (local 'font-lock-fontify-region-function)
#'comint--fl-fontify-region)
#'comint--fontify-input-fontify-region)
(remove-hook 'before-change-functions
#'comint--fl-ppss-flush-indirect t)
#'comint--fontify-input-ppss-flush-indirect t)
;; Reset contextual fontification
(when comint--fl-saved-jit-lock-contextually
(when comint--fontify-input-saved-jit-lock-contextually
(setq-local jit-lock-contextually
comint--fl-saved-jit-lock-contextually)
(setq comint--fl-saved-jit-lock-contextually nil)
comint--fontify-input-saved-jit-lock-contextually)
(setq comint--fontify-input-saved-jit-lock-contextually nil)
(when jit-lock-mode
(jit-lock-mode t)))
(font-lock-flush))
(defun comint--fl-ppss-flush-indirect (beg &rest rest)
(defun comint--fontify-input-ppss-flush-indirect (beg &rest rest)
(when-let ((buf (comint-indirect-buffer t)))
(with-current-buffer buf
(when (memq #'syntax-ppss-flush-cache before-change-functions)
(apply #'syntax-ppss-flush-cache beg rest)))))
(defun comint--fl-fontify-region (fun beg end verbose)
(defun comint--fontify-input-fontify-region (fun beg end verbose)
"Fontify process output and user input in the current comint buffer.
First, fontify the region between BEG and END using FUN. Then
fontify only the input text in the region with the help of an
indirect buffer. VERBOSE is passed to the fontify-region
functions. Skip fontification of input regions with non-nil
`comint--fl-inhibit-fontification' text property."
`comint--fontify-input-inhibit-fontification' text property."
(pcase (funcall fun beg end verbose)
(`(jit-lock-bounds ,beg1 . ,end1)
(setq beg beg1 end end1)))
@ -4069,7 +4069,7 @@ functions. Skip fontification of input regions with non-nil
(comint--intersect-regions
nil (lambda (beg end)
(unless (get-text-property
beg 'comint--fl-inhibit-fontification)
beg 'comint--fontify-input-inhibit-fontification)
(font-lock-fontify-region beg end verbose)))
beg end)))
(`((jit-lock-bounds ,beg1 . ,_) . (jit-lock-bounds ,_ . ,end1))

View file

@ -474,11 +474,11 @@ nonempty, then flushes the buffer."
;;; Input fontification
(defcustom ielm-comint-fl-enable t
(defcustom ielm-fontify-input-enable t
"Enable fontification of input in ielm buffers.
This variable only has effect when creating an ielm buffer. Use
the command `comint-fl-mode' to toggle fontification of input in
an already existing ielm buffer."
the command `comint-fontify-input-mode' to toggle fontification
of input in an already existing ielm buffer."
:type 'boolean
:safe 'booleanp
:version "29.1")
@ -556,8 +556,8 @@ Customized bindings may be defined in `ielm-map', which currently contains:
:syntax-table emacs-lisp-mode-syntax-table
:after-hook
(and (null comint-use-prompt-regexp)
ielm-comint-fl-enable
(comint-fl-mode))
ielm-fontify-input-enable
(comint-fontify-input-mode))
(setq comint-prompt-regexp (concat "^" (regexp-quote ielm-prompt)))
(setq-local paragraph-separate "\\'")

View file

@ -308,10 +308,11 @@ for Shell mode only."
(const :tag "on" t))
:group 'shell)
(defcustom shell-comint-fl-enable t
(defcustom shell-fontify-input-enable t
"Enable fontification of input in shell buffers.
This variable only has effect when the shell is started. Use the
command `comint-fl-mode' to toggle fontification of input."
command `comint-fontify-input-mode' to toggle fontification of
input."
:type 'boolean
:group 'shell
:safe 'booleanp
@ -623,8 +624,8 @@ command."
:interactive nil
:after-hook
(unless comint-use-prompt-regexp
(if shell-comint-fl-enable
(comint-fl-mode))
(if shell-fontify-input-enable
(comint-fontify-input-mode))
(if shell-highlight-undef-enable
(shell-highlight-undef-mode)))
@ -1664,8 +1665,8 @@ Similar to `executable-find', but use cache stored in
(if buf (buffer-local-value 'default-directory buf)
default-directory)))
(cond
;; Don't highlight command output. Mostly useful if
;; `comint-fl-mode' is disabled.
;; Don't fontify command output. Mostly useful if
;; `comint-fontify-input-mode' is disabled.
((text-property-any beg (point) 'field 'output)
nil)
((member cmd shell-highlight-undef-aliases)
@ -1696,7 +1697,7 @@ Similar to `executable-find', but use cache stored in
(define-minor-mode shell-highlight-undef-mode
"Highlight undefined shell commands and aliases.
This minor mode is mostly useful in `shell-mode' buffers and
works better if `comint-fl-mode' is enabled."
works better if `comint-fontify-input-mode' is enabled."
:init-value nil
(if shell--highlight-undef-indirect
(progn
@ -1706,7 +1707,7 @@ works better if `comint-fl-mode' is enabled."
(with-current-buffer buf
(font-lock-remove-keywords nil shell-highlight-undef-keywords))))
(font-lock-remove-keywords nil shell-highlight-undef-keywords))
(remove-hook 'comint-fl-mode-hook
(remove-hook 'comint-fontify-input-mode-hook
#'shell-highlight-undef-mode-restart t)
(when shell-highlight-undef-mode
@ -1722,9 +1723,9 @@ works better if `comint-fl-mode' is enabled."
(concat
"\\("
"[;(){}`|&]"
(if comint-fl-mode
;; `comint-fl-mode' already puts point-min on end of
;; prompt
(if comint-fontify-input-mode
;; `comint-fontify-input-mode' already puts
;; point-min on end of prompt
""
(concat "\\|" comint-prompt-regexp))
"\\|^"
@ -1740,7 +1741,7 @@ works better if `comint-fl-mode' is enabled."
(lambda ()
(setq shell-highlight-undef-regexp regexp)
(font-lock-add-keywords nil shell-highlight-undef-keywords t))))
(cond (comint-fl-mode
(cond (comint-fontify-input-mode
(setq shell--highlight-undef-indirect setup)
(if-let ((buf (comint-indirect-buffer t)))
(with-current-buffer buf
@ -1748,7 +1749,7 @@ works better if `comint-fl-mode' is enabled."
(add-hook 'comint-indirect-setup-hook setup nil t)))
(t (funcall setup))))
(add-hook 'comint-fl-mode-hook
(add-hook 'comint-fontify-input-mode-hook
#'shell-highlight-undef-mode-restart nil t))
(font-lock-flush))
@ -1756,9 +1757,9 @@ works better if `comint-fl-mode' is enabled."
(defun shell-highlight-undef-mode-restart ()
"If `shell-highlight-undef-mode' is on, restart it.
`shell-highlight-undef-mode' performs its setup differently
depending on `comint-fl-mode'. It's useful to call this function
when switching `comint-fl-mode' in order to make
`shell-highlight-undef-mode' redo its setup."
depending on `comint-fontify-input-mode'. It's useful to call
this function when switching `comint-fontify-input-mode' in order
to make `shell-highlight-undef-mode' redo its setup."
(when shell-highlight-undef-mode
(shell-highlight-undef-mode 1)))