From: Eli Zaretskii <eliz@gnu.org>
To: Jim Porter <jporterbugs@gmail.com>
Cc: 72721@debbugs.gnu.org, gautier@gautierponsinet.xyz
Subject: bug#72721: 31.0.50; Visual-wrap-prefix-mode breaks Magit log buffers
Date: Thu, 22 Aug 2024 12:53:23 +0300 [thread overview]
Message-ID: <86h6bcubn0.fsf@gnu.org> (raw)
In-Reply-To: <c3a6a9e9-0cae-f7bb-a52e-29c30a3a2e46@gmail.com> (message from Jim Porter on Tue, 20 Aug 2024 20:15:48 -0700)
> Date: Tue, 20 Aug 2024 20:15:48 -0700
> Cc: 72721@debbugs.gnu.org, gautier@gautierponsinet.xyz
> From: Jim Porter <jporterbugs@gmail.com>
>
> > M-x describe-text-properties will show you the properties and overlays
> > at point, and it should be possible to concoct some Lisp which just
> > reproduces those properties.
>
> I'd tried that but just wasn't looking at the right point. I've now
> figured it out and provided a few reduced test cases. (The "simple" and
> "consecutive" cases should already work.)
>
> While making these test cases, I noticed a similar issue with a nested
> 'display' property (see the "nested" case), and fixed that too (I hope!).
Thanks for the test cases, they helped a lot.
Can you please try the patch below, including in the original use case
with Magit? I hope I've figured out all of the quirks of min-width
and its possible uses, and the few extensions you demonstrated. It
should be possible now to have min-width on overlay strings as well, I
think (but I didn't test that).
If the patch below gives good results, I will install it.
diff --git a/src/xdisp.c b/src/xdisp.c
index 30771a1..1e92ed4 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -5632,16 +5632,24 @@ find_display_property (Lisp_Object disp, Lisp_Object prop)
return XCDR (elem);
}
+/* Return the value of 'display' property PROP of character at CHARPOS
+ in OBJECT. Return nil if character at CHARPOS has no 'display'
+ property or if the 'display' property of that character does not
+ include PROP. OBJECT can be a buffer or a string. */
static Lisp_Object
-get_display_property (ptrdiff_t bufpos, Lisp_Object prop, Lisp_Object object)
+get_display_property (ptrdiff_t charpos, Lisp_Object prop, Lisp_Object object)
{
- return find_display_property (Fget_text_property (make_fixnum (bufpos),
+ return find_display_property (Fget_text_property (make_fixnum (charpos),
Qdisplay, object),
prop);
}
+/* Handle 'display' property '(min-width (WIDTH))' at CHARPOS in OBJECT.
+ OBJECT can be a buffer (or nil, which means the current buffer) or a
+ string. MIN_WIDTH is the value of min-width spec that we expect to
+ process. */
static void
-display_min_width (struct it *it, ptrdiff_t bufpos,
+display_min_width (struct it *it, ptrdiff_t charpos,
Lisp_Object object, Lisp_Object width_spec)
{
/* We're being called at the end of the `min-width' sequence,
@@ -5652,15 +5660,21 @@ display_min_width (struct it *it, ptrdiff_t bufpos,
/* When called from display_string (i.e., the mode line),
we're being called with a string as the object, and we
may be called with many sub-strings belonging to the same
- :propertize run. */
- if ((bufpos == 0
- && !EQ (it->min_width_property,
- get_display_property (0, Qmin_width, object)))
+ :propertize run. */
+ if ((STRINGP (object)
+ && ((charpos == 0
+ && !EQ (it->min_width_property,
+ get_display_property (0, Qmin_width, object)))
+ || (charpos > 0
+ && EQ (it->min_width_property,
+ get_display_property (charpos - 1, Qmin_width,
+ object)))))
/* In a buffer -- check that we're really right after the
sequence of characters covered by this `min-width'. */
- || (bufpos > BEGV
+ || (!STRINGP (object)
+ && charpos > BEGV
&& EQ (it->min_width_property,
- get_display_property (bufpos - 1, Qmin_width, object))))
+ get_display_property (charpos - 1, Qmin_width, object))))
{
Lisp_Object w = Qnil;
double width;
@@ -5707,15 +5721,18 @@ display_min_width (struct it *it, ptrdiff_t bufpos,
the end. */
if (CONSP (width_spec))
{
- if (bufpos == BEGV
+ if ((!STRINGP (object)
+ && charpos == BEGV)
/* Mode line (see above). */
- || (bufpos == 0
+ || (STRINGP (object)
+ && charpos == 0
&& !EQ (it->min_width_property,
get_display_property (0, Qmin_width, object)))
/* Buffer. */
- || (bufpos > BEGV
+ || (!STRINGP (object)
+ && charpos > BEGV
&& !EQ (width_spec,
- get_display_property (bufpos - 1, Qmin_width, object))))
+ get_display_property (charpos - 1, Qmin_width, object))))
{
it->min_width_property = width_spec;
it->min_width_start = it->current_x;
@@ -5798,7 +5815,17 @@ handle_display_prop (struct it *it)
/* Handle min-width ends. */
if (!NILP (it->min_width_property)
&& NILP (find_display_property (propval, Qmin_width)))
- display_min_width (it, bufpos, object, Qnil);
+ {
+ ptrdiff_t pos = bufpos, start = BEGV;
+
+ if (STRINGP (object))
+ {
+ pos = IT_STRING_CHARPOS (*it);
+ start = 0;
+ }
+ if (pos > start)
+ display_min_width (it, pos, object, Qnil);
+ }
if (NILP (propval))
return HANDLED_NORMALLY;
@@ -6099,7 +6126,13 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
&& CONSP (XCAR (XCDR (spec))))
{
if (it)
- display_min_width (it, bufpos, object, XCAR (XCDR (spec)));
+ {
+ ptrdiff_t pos = bufpos;
+
+ if (STRINGP (object))
+ pos = IT_STRING_CHARPOS (*it);
+ display_min_width (it, pos, object, XCAR (XCDR (spec)));
+ }
return 0;
}
@@ -9004,6 +9037,10 @@ set_iterator_to_next (struct it *it, bool reseat_p)
next, if there is one. */
if (IT_STRING_CHARPOS (*it) >= SCHARS (it->string))
{
+ /* Maybe add a stretch glyph if the string had 'min-width'
+ display spec. */
+ display_min_width (it, IT_STRING_CHARPOS (*it), it->string,
+ Qnil);
it->ellipsis_p = false;
next_overlay_string (it);
if (it->ellipsis_p)
@@ -9019,6 +9056,12 @@ set_iterator_to_next (struct it *it, bool reseat_p)
if (IT_STRING_CHARPOS (*it) == SCHARS (it->string)
&& it->sp > 0)
{
+ /* Maybe add a stretch glyph if the string had 'min-width'
+ display spec. We only do this if it->sp > 0 because
+ mode-line strings are handled differently, see
+ display_min_width. */
+ display_min_width (it, IT_STRING_CHARPOS (*it), it->string,
+ Qnil);
pop_it (it);
if (it->method == GET_FROM_STRING)
goto consider_string_end;
next prev parent reply other threads:[~2024-08-22 9:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-19 21:39 bug#72721: 31.0.50; Visual-wrap-prefix-mode breaks Magit log buffers Gautier Ponsinet
2024-08-20 0:46 ` Jim Porter
2024-08-20 11:53 ` Eli Zaretskii
2024-08-20 17:33 ` Jim Porter
2024-08-20 19:01 ` Eli Zaretskii
2024-08-21 3:15 ` Jim Porter
2024-08-21 5:18 ` Jim Porter
2024-08-21 19:12 ` Jim Porter
2024-08-22 12:54 ` Eli Zaretskii
2024-08-22 9:59 ` Eli Zaretskii
2024-08-22 9:53 ` Eli Zaretskii [this message]
2024-08-22 16:19 ` Jim Porter
2024-08-25 7:29 ` Eli Zaretskii
2024-08-25 16:26 ` Jim Porter
2024-08-25 17:39 ` Eli Zaretskii
2024-08-25 18:41 ` Jim Porter
2024-08-29 11:47 ` Eli Zaretskii
2024-08-30 5:01 ` Jim Porter
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=86h6bcubn0.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=72721@debbugs.gnu.org \
--cc=gautier@gautierponsinet.xyz \
--cc=jporterbugs@gmail.com \
/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.