all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jim Blandy <jimb@red-bean.com>
To: Emacs Devel <emacs-devel@gnu.org>
Subject: PATCH: Don't mark entire man sections bold
Date: Fri, 16 Oct 2020 23:26:11 -0700	[thread overview]
Message-ID: <CAHgb+0knGr5DCmA5UU1pijqQtTGqhSHsTz4keSqA1nQ6SXe_dQ@mail.gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2020-10-17  6:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-17  6:26 Jim Blandy [this message]
2020-10-18  7:50 ` PATCH: Don't mark entire man sections bold Lars Ingebrigtsen
2020-10-20  2:56   ` Jim Blandy
2020-10-20 11:09     ` Lars Ingebrigtsen
2020-10-20 16:17       ` Jim Blandy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHgb+0knGr5DCmA5UU1pijqQtTGqhSHsTz4keSqA1nQ6SXe_dQ@mail.gmail.com \
    --to=jimb@red-bean.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.