unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] User-defined fringe tooltips (a request for review)
@ 2023-12-19 19:38 Vladimir Kazanov
  2023-12-20 12:31 ` Eli Zaretskii
  0 siblings, 1 reply; 28+ messages in thread
From: Vladimir Kazanov @ 2023-12-19 19:38 UTC (permalink / raw)
  To: emacs-devel

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

Hi all,

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.

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!

Thank you

-- 
Regards,

Vladimir Kazanov

[-- Attachment #2: 0001-first-draft-version-of-user-fringe-tooltips.patch --]
[-- Type: text/x-patch, Size: 4764 bytes --]

From 09551c3a191201ebe45e1345e5c515b59ad3d728 Mon Sep 17 00:00:00 2001
From: Vladimir Kazanov <vekazanov@gmail.com>
Date: Tue, 19 Dec 2023 19:11:26 +0000
Subject: [PATCH] first draft version of user fringe tooltips

---
 src/dispextern.h | 12 ++++++++++++
 src/xdisp.c      | 39 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/src/dispextern.h b/src/dispextern.h
index ece128949f5..53dee99ab05 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -940,6 +940,12 @@ #define CHECK_MATRIX(MATRIX) ((void) 0)
      it specifies actual fringe bitmap number.  */
   int overlay_arrow_bitmap;

+  /* 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;

@@ -2762,6 +2768,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 fdb4acd71bf..0e8a18da358 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -3252,6 +3252,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;
@@ -6082,6 +6086,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);
@@ -6105,11 +6116,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 */
@@ -25593,13 +25606,19 @@ #define RECORD_MAX_MIN_POS(IT)					\
   /* Save fringe bitmaps in this row.  */
   row->left_user_fringe_bitmap = it->left_user_fringe_bitmap;
   row->left_user_fringe_face_id = it->left_user_fringe_face_id;
+  row->left_user_fringe_caption = it->left_user_fringe_caption;
+
   row->right_user_fringe_bitmap = it->right_user_fringe_bitmap;
   row->right_user_fringe_face_id = it->right_user_fringe_face_id;
+  row->right_user_fringe_caption = it->right_user_fringe_caption;

   it->left_user_fringe_bitmap = 0;
   it->left_user_fringe_face_id = 0;
+  it->left_user_fringe_caption = Qnil;
+
   it->right_user_fringe_bitmap = 0;
   it->right_user_fringe_face_id = 0;
+  it->right_user_fringe_caption = Qnil;

   /* When they turn off tooltip-mode on a GUI frame, we call 'message'
      with message-truncate-lines bound to non-nil, which produces
@@ -35273,8 +35292,24 @@ 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)) {
+	      int hpos, vpos, area;
+	      x_y_to_hpos_vpos (w, x, y, &hpos, &vpos, 0, 0, &area);
+	      struct glyph_row *r = MATRIX_ROW (w->current_matrix, vpos);
+	      if (part == ON_LEFT_FRINGE
+		  && !NILP(r->left_user_fringe_caption))
+		  help_echo_string = r->left_user_fringe_caption;
+	      else if (part == ON_RIGHT_FRINGE
+		       && !NILP(r->right_user_fringe_caption))
+	          help_echo_string = r->right_user_fringe_caption;
+	  }
+
+      }
+  else if (part == ON_VERTICAL_SCROLL_BAR
 	   || part == ON_HORIZONTAL_SCROLL_BAR)
     cursor = FRAME_OUTPUT_DATA (f)->nontext_cursor;
   else
--
2.34.1

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

end of thread, other threads:[~2024-04-13 15:47 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).