From: Vladimir Kazanov <vekazanov@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] User-defined fringe tooltips (a request for review)
Date: Thu, 21 Dec 2023 16:51:15 +0000 [thread overview]
Message-ID: <CAAs=0-1bHkfPtqLS-99SvAbtW+Q-NmaEBR3r8kPDz_soqPNiBA@mail.gmail.com> (raw)
In-Reply-To: <83sf3xgimq.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 2601 bytes --]
Thanks for looking into this!
> The code in note_mouse_highlight examines
> the buffer text and overlays for text properties whose meaning is to
> display a help-echo string, so why cannot you do the same to look for
> a 'display' property of this specific structure, and extract the
> help-echo directly from there at mouse-highlight time instead of at
> glyph-generation time?
Yes, having Lispy stuff in the glyph_row struct doesn't make sense,
and this is why I was in doubt.
Anyway, a new patch is attached with the approach you suggested (the
way I understood it). I use "struct it" to iterate over the line for
which the fringe indicator is defined, in note_mouse_highlight. The
iterator then pulls out the display spec and saves the last left/right
fringe captions it walked over.
Does that feel right?
Thank you,
Vlad
On Wed, 20 Dec 2023 at 12:32, Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Vladimir Kazanov <vekazanov@gmail.com>
> > Date: Tue, 19 Dec 2023 19:38:09 +0000
> >
> > Recently I've been looking into implementing a suggestion from
> > etc/TODO related to fringe indicator tooltips:
> >
> > > ** Allow fringe indicators to display a tooltip
> > > Provide a help-echo property?
> >
> > Attached is a quick and dirty proof-of-concept. The patch extends the
> > display specification with an optional string that would be displayed
> > through either tooltips or the echo area:
> >
> > (overlay-put (make-overlay (point) (point))
> > 'before-string (propertize "x" 'display `(left-fringe right-arrow
> > nil "left fringe test tooltip")))
> >
> > Moving a mouse pointer to the fringe would then display the string in
> > a tooltip on a relevant line.
>
> Thanks.
>
> > To make this work I've extended "struct it" and "struct glyphs_row"
> > with pointers to strings, and added some mouse hover handling in the
> > "note_mouse_highlight function". Obviously, the code needs more checks
> > but I want to confirm the approach with emacs-devel@ first.
> >
> > Happy to hear comments and suggestions about the path taken!
>
> I'm not sure I like to have Lisp_Object members in 'struct glyph_row'.
> I also don't think I understand why you needed to copy the hel-echo
> string to the glyph row. The code in note_mouse_highlight examines
> the buffer text and overlays for text properties whose meaning is to
> display a help-echo string, so why cannot you do the same to look for
> a 'display' property of this specific structure, and extract the
> help-echo directly from there at mouse-highlight time instead of at
> glyph-generation time?
--
Regards,
Vladimir Kazanov
[-- Attachment #2: add-user-fringe-indicator-tooltips.patch --]
[-- Type: text/x-patch, Size: 4078 bytes --]
diff --git a/src/dispextern.h b/src/dispextern.h
index 3a4d6095f73..e8f984e1a71 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -2801,6 +2801,12 @@ #define OVERLAY_STRING_CHUNK_SIZE 16
is in effect, and only in hscrolled windows. */
int stretch_adjust;
+ /* Left fringe caption (Qnil or a stringp) */
+ Lisp_Object left_user_fringe_caption;
+
+ /* Right fringe caption (Qnil or a stringp)*/
+ Lisp_Object right_user_fringe_caption;
+
/* Left fringe bitmap number (enum fringe_bitmap_type). */
unsigned left_user_fringe_bitmap : FRINGE_ID_BITS;
diff --git a/src/xdisp.c b/src/xdisp.c
index 75d769600c4..5c5d39acde1 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -3265,6 +3265,10 @@ init_iterator (struct it *it, struct window *w,
/* Clear IT, and set it->object and other IT's Lisp objects to Qnil.
Other parts of redisplay rely on that. */
memclear (it, sizeof *it);
+
+ it->left_user_fringe_caption = Qnil;
+ it->right_user_fringe_caption = Qnil;
+
it->current.overlay_string_index = -1;
it->current.dpvec_index = -1;
it->base_face_id = remapped_base_face_id;
@@ -6127,6 +6131,13 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
face_id = face_id2;
}
+ Lisp_Object caption = Qnil;
+ if (CONSP (XCDR (XCDR (XCDR (spec)))))
+ {
+ caption = XCAR (XCDR (XCDR (XCDR (spec))));
+ }
+
+
/* Save current settings of IT so that we can restore them
when we are finished with the glyph property value. */
push_it (it, position);
@@ -6150,11 +6161,13 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
{
it->left_user_fringe_bitmap = fringe_bitmap;
it->left_user_fringe_face_id = face_id;
+ it->left_user_fringe_caption = caption;
}
else
{
it->right_user_fringe_bitmap = fringe_bitmap;
it->right_user_fringe_face_id = face_id;
+ it->right_user_fringe_caption = caption;
}
}
#endif /* HAVE_WINDOW_SYSTEM */
@@ -35720,10 +35733,50 @@ note_mouse_highlight (struct frame *f, int x, int y)
}
else
cursor = FRAME_OUTPUT_DATA (f)->nontext_cursor;
- else if (part == ON_LEFT_FRINGE || part == ON_RIGHT_FRINGE
- || part == ON_VERTICAL_SCROLL_BAR
+ else if (part == ON_LEFT_FRINGE || part == ON_RIGHT_FRINGE) {
+ cursor = FRAME_OUTPUT_DATA (f)->nontext_cursor;
+
+ if (NILP (help_echo_string)) {
+ /* Translate windows coordinates into vertical window
+ position. */
+ int hpos, vpos, area;
+ x_y_to_hpos_vpos (w, x, y, &hpos, &vpos, 0, 0, &area);
+
+ /* Figure out where the window starts - will need to get to
+ the fringe line */
+ struct text_pos start_pos;
+ SET_TEXT_POS_FROM_MARKER (start_pos, w->start);
+
+ /* Need an iterator to walk through all the properties on
+ the line. Find the line first, reset text from previous
+ lines and then collect the properties on it. */
+ struct it it;
+ init_iterator (&it, w, CHARPOS(start_pos), BYTEPOS (start_pos),
+ NULL, DEFAULT_FACE_ID);
+
+ /* Walk to the fringe line and reset captions found on the
+ way*/
+ move_it_by_lines(&it, vpos);
+ it.left_user_fringe_caption = Qnil;
+ it.right_user_fringe_caption = Qnil;
+
+ /* Reset and go through the line. */
+ move_it_by_lines (&it, 1);
+
+ /* Output through whatever the user prefers, most likely a
+ tooltip */
+ if (part == ON_LEFT_FRINGE
+ && !NILP(it.left_user_fringe_caption))
+ help_echo_string = it.left_user_fringe_caption;
+ else if (part == ON_RIGHT_FRINGE
+ && !NILP(it.right_user_fringe_caption))
+ help_echo_string = it.right_user_fringe_caption;
+ }
+
+ }
+ else if (part == ON_VERTICAL_SCROLL_BAR
|| part == ON_HORIZONTAL_SCROLL_BAR)
- cursor = FRAME_OUTPUT_DATA (f)->nontext_cursor;
+ cursor = FRAME_OUTPUT_DATA (f)->nontext_cursor;
else
cursor = FRAME_OUTPUT_DATA (f)->text_cursor;
#endif
next prev parent reply other threads:[~2023-12-21 16:51 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-19 19:38 [PATCH] User-defined fringe tooltips (a request for review) Vladimir Kazanov
2023-12-20 12:31 ` Eli Zaretskii
2023-12-21 16:51 ` Vladimir Kazanov [this message]
2023-12-21 17:37 ` Eli Zaretskii
2023-12-23 13:28 ` Vladimir Kazanov
2023-12-23 13:40 ` Eli Zaretskii
2023-12-24 11:31 ` Vladimir Kazanov
2023-12-24 16:54 ` Eli Zaretskii
2024-03-25 15:55 ` Vladimir Kazanov
2024-03-25 17:11 ` Eli Zaretskii
2024-03-26 22:16 ` Vladimir Kazanov
2024-03-27 10:59 ` Vladimir Kazanov
2024-03-27 11:25 ` Po Lu
2024-03-27 12:48 ` Vladimir Kazanov
2024-03-27 11:25 ` Po Lu
2024-03-31 8:36 ` Eli Zaretskii
2024-04-07 11:14 ` Vladimir Kazanov
2024-04-07 12:44 ` Eli Zaretskii
2024-04-07 17:07 ` Vladimir Kazanov
2024-04-07 18:40 ` Eli Zaretskii
2024-04-08 14:41 ` Vladimir Kazanov
2024-04-13 9:14 ` Eli Zaretskii
2024-04-13 9:32 ` Vladimir Kazanov
2024-04-13 11:21 ` Eli Zaretskii
2024-04-13 14:53 ` Vladimir Kazanov
2024-04-13 15:47 ` Eli Zaretskii
2024-03-27 12:14 ` Eli Zaretskii
2024-03-27 12:48 ` Vladimir Kazanov
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='CAAs=0-1bHkfPtqLS-99SvAbtW+Q-NmaEBR3r8kPDz_soqPNiBA@mail.gmail.com' \
--to=vekazanov@gmail.com \
--cc=eliz@gnu.org \
--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 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).