unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* PATCH: Don't mark entire man sections bold
@ 2020-10-17  6:26 Jim Blandy
  2020-10-18  7:50 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Jim Blandy @ 2020-10-17  6:26 UTC (permalink / raw)
  To: Emacs Devel

[-- Attachment #1: Type: text/plain, Size: 3067 bytes --]

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.

[-- Attachment #2: Type: text/html, Size: 3420 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-10-20 16:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-17  6:26 PATCH: Don't mark entire man sections bold Jim Blandy
2020-10-18  7:50 ` Lars Ingebrigtsen
2020-10-20  2:56   ` Jim Blandy
2020-10-20 11:09     ` Lars Ingebrigtsen
2020-10-20 16:17       ` Jim Blandy

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).