emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PATCH: Don't mark entire man sections bold


From: Jim Blandy
Subject: PATCH: Don't mark entire man sections bold
Date: Fri, 16 Oct 2020 23:26:11 -0700

If Man-bgproc-filter, receiving async output from `man`, happens to get a chunk from the subprocess that ends in a bold (or whatever) section, but not in the middle of an escape sequence, the entire section up to the end of that output chunk gets marked bold.

This is because Man-fontify-manpage wants to process whole sections at once (not sure why, but it's what the comment there says), so Man-bgproc-filter doesn't tell it the true starting position of the newly inserted text it just received, instead always backing up to the last section start. Since successive calls to Man-fontify-manpage are passed regions that overlap, these are passed along to ansi-color-apply-on-region.

ansi-color-apply-on-region is prepared to resume work at a position *earlier* than requested, to handle chunks that ended in the middle of an escape sequence. But it assumes that otherwise, if it left off work with some sort of highlighting active, then when it's called again, it should resume that highlighting at the `begin` position it's passed.

If that `begin` position has been backed up to the last man section start, it ends up bolding the whole section up until the end of some random bold bit.

Maybe `Man-fontify-manpage` should be passed more arguments. But it seemed easier just to make ansi-color-apply-on-region more robust, and have it remember the proper starting position whenever there's some highlighting to be resumed.


commit 2b65205572277260d4a317f82bd7d1dd7493287f (HEAD -> ansi-color-man-restart-fix)
Author: Jim Blandy <jimb@red-bean.com>
Date:   Fri Oct 16 22:35:16 2020 -0700

    Man highlighting: Don't occasionally bold entire sections.
   
    * lisp/ansi-color.el (ansi-color-apply-on-region): Always save a
    restart position in ansi-color-context-region if the region ends with
    highlighting active.

diff --git a/lisp/ansi-color.el b/lisp/ansi-color.el
index 141ad2353e..c3b2d98c14 100644
--- a/lisp/ansi-color.el
+++ b/lisp/ansi-color.el
@@ -414,11 +414,17 @@ ansi-color-apply-on-region
        ;; if the rest of the region should have a face, put it there
        (funcall ansi-color-apply-face-function
                 start-marker end-marker (ansi-color--find-face codes))
-       (setq ansi-color-context-region (if codes (list codes)))))
+        ;; Save a restart position when there are codes active. It's
+        ;; convenient for man.el's process filter to pass `begin'
+        ;; positions that overlap regions previously colored; these
+        ;; `codes' should not be applied to that overlap, so we need
+        ;; to know where they should really start.
+       (setq ansi-color-context-region (if codes (list codes end-marker)))))
     ;; Clean up our temporary markers.
     (unless (eq start-marker (cadr ansi-color-context-region))
       (set-marker start-marker nil))
-    (set-marker end-marker nil)))
+    (unless (eq end-marker (cadr ansi-color-context-region))
+      (set-marker end-marker nil))))
 
 (defun ansi-color-apply-overlay-face (beg end face)
   "Make an overlay from BEG to END, and apply face FACE.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]