From: "Basil L. Contovounesios" <contovob@tcd.ie>
To: "Kévin Le Gouguec" <kevin.legouguec@gmail.com>
Cc: 41810@debbugs.gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>,
Stephen Berman <stephen.berman@gmx.net>
Subject: bug#41810: [PATCH][ELPA] adaptive-wrap: Fontify wrap-prefix
Date: Sun, 21 Jun 2020 19:32:17 +0100 [thread overview]
Message-ID: <87zh8w6zim.fsf@tcd.ie> (raw)
In-Reply-To: <87ftaosa9g.fsf_-_@gmail.com> ("Kévin Le Gouguec"'s message of "Sun, 21 Jun 2020 17:34:35 +0200")
Kévin Le Gouguec <kevin.legouguec@gmail.com> writes:
> OK, here is a patch that I think should be good to push, tested against
> Emacs 28 and 26.3.
Thanks, just some minor comments from me.
> +(defun adaptive-wrap--prefix-face (fcp beg end)
> + (or (get-text-property 0 'face fcp)
> + ;; If the last character is a newline and has a face that
> + ;; extends beyond EOL, assume that this face spans the whole
> + ;; line and apply it to the prefix to preserve the "block"
> + ;; visual effect.
> + ;; NB: the face might not actually span the whole line: see for
> + ;; example removed lines in diff-mode, where the first character
> + ;; has the diff-indicator-removed face, while the rest of the
> + ;; line has the diff-removed face.
> + (when (= (char-before end) ?\n)
> + (let ((eol-face (get-text-property (1- end) 'face)))
Is it guaranteed that (< (point-min) end (1+ (point-max)))?
Otherwise = and get-text-property will barf.
> + (when (and eol-face (adaptive-wrap--face-extends eol-face))
> + eol-face)))))
Nit: Can't the when+and be replaced with a single and?
> +(defun adaptive-wrap--prefix (fcp)
> + (let ((fcp-len (string-width fcp)))
> + (cond
> + ((= 0 adaptive-wrap-extra-indent)
> + fcp)
> + ((< 0 adaptive-wrap-extra-indent)
> + (concat
> + fcp
> + (make-string adaptive-wrap-extra-indent
> + (if (< 0 fcp-len)
> + (string-to-char (substring fcp -1))
> + ?\ ))))
Please change this to ?\s regardless of whether the second patch is
installed.
> + ((< 0 (+ adaptive-wrap-extra-indent fcp-len))
> + (substring fcp
> + 0
> + (+ adaptive-wrap-extra-indent fcp-len)))
> + (t
> + ""))))
> Open questions:
>
> - The (or … (when … (let … (when (and …))))) chain looks clumsy but I
> don't really know how to improve it off the top of my head. Maybe a
> when-let or two would help? That'd mean requiring Emacs 25.1 though.
Apart from the redundant when, I think it's fine. If you really want
to shave off some forms you can write e.g.
(defun adaptive-wrap--prefix-face (fcp beg end)
(or (get-text-property 0 'face fcp)
(let ((face (and (= (char-before end) ?\n)
(get-text-property (1- end) 'face))))
(and face (adaptive-wrap--face-extends face) face))))
or
(defun adaptive-wrap--prefix-face (fcp beg end)
(cond ((get-text-property 0 'face fcp))
((= (char-before end) ?\n)
(let ((face ...))
(and face (adaptive-wrap--face-extends face) face)))))
Thanks,
--
Basil
next prev parent reply other threads:[~2020-06-21 18:32 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-11 16:16 bug#41810: 28.0.50; [ELPA] adaptive-wrap: Fontify wrap-prefix Kévin Le Gouguec
2020-06-11 22:42 ` Stefan Monnier
2020-06-12 8:50 ` Kévin Le Gouguec
2020-06-12 15:33 ` Stefan Monnier
2020-06-12 22:48 ` Kévin Le Gouguec
2020-06-21 15:34 ` bug#41810: [PATCH][ELPA] " Kévin Le Gouguec
2020-06-21 18:32 ` Basil L. Contovounesios [this message]
2020-06-21 22:01 ` Kévin Le Gouguec
2020-08-14 17:15 ` Lars Ingebrigtsen
2020-08-14 17:58 ` Kévin Le Gouguec
2020-08-14 17:59 ` Lars Ingebrigtsen
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87zh8w6zim.fsf@tcd.ie \
--to=contovob@tcd.ie \
--cc=41810@debbugs.gnu.org \
--cc=kevin.legouguec@gmail.com \
--cc=monnier@iro.umontreal.ca \
--cc=stephen.berman@gmx.net \
/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 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).