From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: miha--- via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#58169: 29.0.50; comint-fl-mode fontifies the output Date: Fri, 30 Sep 2022 21:22:27 +0200 Message-ID: <87leq0u0p8.fsf@miha-pc> References: <87h70qcfmt.fsf@gmail.com> <871qrt8w2s.fsf@gmail.com> <8735c976a6.fsf@miha-pc> <87edvt56e3.fsf@gnus.org> <87o7uwu2pt.fsf@miha-pc> <87a66g4t1s.fsf@gnus.org> Reply-To: Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36832"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 58169@debbugs.gnu.org, Augusto Stoffel , Visuwesh To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 30 21:09:22 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oeLNx-0009Ne-3w for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 30 Sep 2022 21:09:21 +0200 Original-Received: from localhost ([::1]:54308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oeLNv-0002fe-Um for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 30 Sep 2022 15:09:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39402) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oeLNe-0002fT-Pb for bug-gnu-emacs@gnu.org; Fri, 30 Sep 2022 15:09:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:43889) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oeLNe-0002N6-H4 for bug-gnu-emacs@gnu.org; Fri, 30 Sep 2022 15:09:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oeLNe-000869-2R for bug-gnu-emacs@gnu.org; Fri, 30 Sep 2022 15:09:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 30 Sep 2022 19:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58169 X-GNU-PR-Package: emacs Original-Received: via spool by 58169-submit@debbugs.gnu.org id=B58169.166456491831100 (code B ref 58169); Fri, 30 Sep 2022 19:09:02 +0000 Original-Received: (at 58169) by debbugs.gnu.org; 30 Sep 2022 19:08:38 +0000 Original-Received: from localhost ([127.0.0.1]:42967 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oeLNF-00085X-Lf for submit@debbugs.gnu.org; Fri, 30 Sep 2022 15:08:38 -0400 Original-Received: from kamnitnik.top ([209.250.245.214]:56378) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oeLNC-00085N-AC for 58169@debbugs.gnu.org; Fri, 30 Sep 2022 15:08:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kamnitnik.top; s=mail; t=1664564911; bh=6qL+7j9XkgpitGjlYW7sc7G6IZS4ajTXCESnFFKx6BU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=UEWlcJ4BADTABQ0D0EFlJcXQPvkHL1pWij/G4tR8GfuQ7jfJN5+XY/rvGApP1/Mhq KsRWacORMDqaAZMRpRkdqrPJbsMQURWuEDa/IqeaziAhqOMdqWkboym3nME8MKoa2p O1ufQMV5mDkoVldpIyKlVMxoj562ko/QzNb0Dg/Vn3E2copVuWBZCF47PELlJ4ARuE nc6FuTeKR/wqyB11E1FVk3DxqMRCe6SYhO1aR0K8m7D3oIzKG58m2mGdbbRB6GIp9H U1BuFGjr7qifk5BvMrYU/LM/IDebed40CsfXbZ4hu5PVNyfd80P8TDGMtGCGvc9+g2 C8bG2sNpuBptw== In-Reply-To: <87a66g4t1s.fsf@gnus.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:244051 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Lars Ingebrigtsen writes: > writes: > >> +(defalias 'comint-fontify-input-mode #'comint-fl-mode) > > Thanks, but why aliases instead of just renaming the functions and > variables? I originally thought that the function names could become too long. But now I tried it and it's not so bad, so here are the revised patches attached. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-comint-fl-Prevent-fontification-of-output-as-input.patch Content-Transfer-Encoding: quoted-printable From=20ddbad11131d0bfcdef33666c028f3d7070cefc31 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Miha=3D20Rihtar=3DC5=3DA1i=3DC4=3D8D?=3D 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). =2D-- 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 =2D-- 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. =2D (insert string) + (make-local-variable 'jit-lock-mode) + (let ((jit-lock-mode nil)) + (insert string) =20 =2D ;; Advance process-mark =2D (set-marker (process-mark process) (point)) + ;; Advance process-mark + (set-marker (process-mark process) (point)) =20 =2D (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))) =20 =2D ;; Run these hooks with point where the user had it. =2D (goto-char saved-point) =2D (run-hook-with-args 'comint-output-filter-functions string) =2D (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)) =20 =2D (goto-char (process-mark process)) ; In case a filter moved it. + (goto-char (process-mark process)) ; In case a filter moved it. =20 =2D (unless comint-use-prompt-regexp =2D (comint--mark-as-output comint-last-output-start (point))) + (unless comint-use-prompt-regexp + (comint--mark-as-output comint-last-output-start (point)))) =20 ;; Highlight the prompt, where we define `prompt' to mean ;; the most recent output that doesn't end with a newline. =2D-=20 2.37.2 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-Rename-comint-fl-to-comint-fontify-input-and-mention.patch Content-Transfer-Encoding: quoted-printable From=20734d2b840618e323f8676f74e152b6c85a68a020 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Miha=3D20Rihtar=3DC5=3DA1i=3DC4=3D8D?=3D Date: Fri, 30 Sep 2022 20:28:15 +0200 Subject: [PATCH 2/2] Rename comint-fl-* to comint-fontify-input-* and menti= on 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). =2D-- etc/NEWS | 14 ++++++++++++++ lisp/comint.el | 46 +++++++++++++++++++++++----------------------- lisp/ielm.el | 10 +++++----- lisp/shell.el | 33 +++++++++++++++++---------------- 4 files changed, 59 insertions(+), 44 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index aad1a17ae7..bce6a72481 100644 =2D-- a/etc/NEWS +++ b/etc/NEWS @@ -1214,6 +1214,14 @@ When nil, this prevents comint from deleting the cur= rent input when inserting previous input using ''. The default is t, to preserve past behavior. =20 +--- +*** 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 =20 --- @@ -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. =20 +--- +*** 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 =20 +++ diff --git a/lisp/comint.el b/lisp/comint.el index 15c9388ea4..a70a75c648 100644 =2D-- a/lisp/comint.el +++ b/lisp/comint.el @@ -1945,7 +1945,7 @@ comint-send-input (when comint-highlight-input (add-text-properties beg end '( font-lock-face comint-highlight-in= put =2D comint--fl-inhibit-fontification= t + comint--fontify-input-inhibit-font= ification t front-sticky t ))) (unless comint-use-prompt-regexp ;; Give old user input a field property of `input', to @@ -3976,9 +3976,9 @@ comint-indirect-setup-hook (defvar-local comint--indirect-buffer nil "Indirect buffer used for input fontification.") =20 =2D(defvar-local comint--fl-saved-jit-lock-contextually nil) +(defvar-local comint--fontify-input-saved-jit-lock-contextually nil) =20 =2D(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 @@ comint-fl-mode non-nil. Input fontification isn't compatible with this setting." :lighter nil =2D (if comint-fl-mode + (if comint-fontify-input-mode (let ((success nil)) (unwind-protect (progn =2D (comint--fl-on) + (comint--fontify-input-on) (setq success t)) (unless success =2D (setq comint-fl-mode nil) =2D (comint--fl-off)))) =2D (comint--fl-off))) + (setq comint-fontify-input-mode nil) + (comint--fontify-input-off)))) + (comint--fontify-input-off))) =20 =2D(defun comint--fl-on () +(defun comint--fontify-input-on () "Enable input fontification in the current comint buffer." =2D (comint--fl-off) + (comint--fontify-input-off) =20 (when comint-use-prompt-regexp (error "Input fontification is incompatible with `comint-use-prompt-regexp'"= )) =20 (add-function :around (local 'font-lock-fontify-region-function) =2D #'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 =2D #'comint--fl-ppss-flush-indirect 99 t) + #'comint--fontify-input-ppss-flush-indirect 99 t) =20 ;; Set up contextual fontification (unless (booleanp jit-lock-contextually) =2D (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)))) =20 =2D(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) =2D #'comint--fl-fontify-region) + #'comint--fontify-input-fontify-region) (remove-hook 'before-change-functions =2D #'comint--fl-ppss-flush-indirect t) + #'comint--fontify-input-ppss-flush-indirect t) =20 ;; Reset contextual fontification =2D (when comint--fl-saved-jit-lock-contextually + (when comint--fontify-input-saved-jit-lock-contextually (setq-local jit-lock-contextually =2D comint--fl-saved-jit-lock-contextually) =2D (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))) =20 (font-lock-flush)) =20 =2D(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))))) =20 =2D(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 =2D`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 @@ comint--fl-fontify-region (comint--intersect-regions nil (lambda (beg end) (unless (get-text-property =2D 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)) diff --git a/lisp/ielm.el b/lisp/ielm.el index ad41cb1f6b..fd41afa243 100644 =2D-- a/lisp/ielm.el +++ b/lisp/ielm.el @@ -474,11 +474,11 @@ ielm-set-pm =20 ;;; Input fontification =20 =2D(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 =2Dthe command `comint-fl-mode' to toggle fontification of input in =2Dan 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 @@ inferior-emacs-lisp-mode :syntax-table emacs-lisp-mode-syntax-table :after-hook (and (null comint-use-prompt-regexp) =2D ielm-comint-fl-enable =2D (comint-fl-mode)) + ielm-fontify-input-enable + (comint-fontify-input-mode)) =20 (setq comint-prompt-regexp (concat "^" (regexp-quote ielm-prompt))) (setq-local paragraph-separate "\\'") diff --git a/lisp/shell.el b/lisp/shell.el index 18bb372242..641f274045 100644 =2D-- a/lisp/shell.el +++ b/lisp/shell.el @@ -308,10 +308,11 @@ shell-input-autoexpand (const :tag "on" t)) :group 'shell) =20 =2D(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 =2Dcommand `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 @@ shell-mode :interactive nil :after-hook (unless comint-use-prompt-regexp =2D (if shell-comint-fl-enable =2D (comint-fl-mode)) + (if shell-fontify-input-enable + (comint-fontify-input-mode)) (if shell-highlight-undef-enable (shell-highlight-undef-mode))) =20 @@ -1664,8 +1665,8 @@ shell-highlight-undef-matcher (if buf (buffer-local-value 'default-directory buf) default-directory))) (cond =2D ;; Don't highlight command output. Mostly useful if =2D ;; `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 @@ sh-other-keywords (define-minor-mode shell-highlight-undef-mode "Highlight undefined shell commands and aliases. This minor mode is mostly useful in `shell-mode' buffers and =2Dworks 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 @@ shell-highlight-undef-mode (with-current-buffer buf (font-lock-remove-keywords nil shell-highlight-undef-keywords)= ))) (font-lock-remove-keywords nil shell-highlight-undef-keywords)) =2D (remove-hook 'comint-fl-mode-hook + (remove-hook 'comint-fontify-input-mode-hook #'shell-highlight-undef-mode-restart t) =20 (when shell-highlight-undef-mode @@ -1722,9 +1723,9 @@ shell-highlight-undef-mode (concat "\\(" "[;(){}`|&]" =2D (if comint-fl-mode =2D ;; `comint-fl-mode' already puts point-min on end of =2D ;; 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 @@ shell-highlight-undef-mode (lambda () (setq shell-highlight-undef-regexp regexp) (font-lock-add-keywords nil shell-highlight-undef-keywords t= )))) =2D (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 @@ shell-highlight-undef-mode (add-hook 'comint-indirect-setup-hook setup nil t))) (t (funcall setup)))) =20 =2D (add-hook 'comint-fl-mode-hook + (add-hook 'comint-fontify-input-mode-hook #'shell-highlight-undef-mode-restart nil t)) =20 (font-lock-flush)) @@ -1756,9 +1757,9 @@ shell-highlight-undef-mode (defun shell-highlight-undef-mode-restart () "If `shell-highlight-undef-mode' is on, restart it. `shell-highlight-undef-mode' performs its setup differently =2Ddepending on `comint-fl-mode'. It's useful to call this function =2Dwhen switching `comint-fl-mode' in order to make =2D`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))) =20 =2D-=20 2.37.2 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJHBAEBCAAxFiEEmxVnesoT5rQXvVXnswkaGpIVmT8FAmM3QfMTHG1paGFAa2Ft bml0bmlrLnRvcAAKCRCzCRoakhWZP/NaEACZalaEIAFv2uadb8aITBzzzB89P8gH uI3PMlSiVBg+3M/SRxkmF0yAH0FPquODyDRa0hBYJOkNUHZ9IABdZRsMh43r64B3 HgM4UdlXhaKWoNHZmYTGOSGt+MeIY2Dq9/Klap2zgjuDlzkYNG2EFka5rrIBYPR/ 838q/yMYTjUJ3kj5mp+TQu3veiVW4lpssWZXbuijp77D2md6udU6M7XoPamhEeqM knQJwn1Q2ZtoCAO+UKHA3ZM8EVT/3Egf2+EmGZeABzZkTsLezhzLbIBjVWaIUoF0 KJaDeEI6cMGlrXPAhWKs/VdPMeIwOItdof1B5QK9kI2emjvIZQfe32i7CThEp428 6/+0GkF3IxTXyFVueQ5c8rc23LaCdva9C3DjfuxwH2owz0OWWMnSMaBDyqs2VpbV YOwEw/8Z821KOg25UcvfZ/rAncjKJ08HLZSeGsC7e8KjQFpw1+JSYBiO4Oklt0E5 pM4dmFo4ZWMSsPfnv1aX54DHKPco0Ju9GMCuHmkaql4INVYvbvkdAX4HWJV8/kOG EdWmhD5lUM+KvlBDc+5PQTcOgwA7Q1eXYtqBA6GWOKtJM+a6XTNk4zy4NOv1fEEN RpoLKofEtDZgd28Yw+LoBy/2HkH/l8816rATKxe4nT0igRjAy+zWzUrjY77MNXfs cMQjDWiCpeLXhg== =2hUJ -----END PGP SIGNATURE----- --==-=-=--