all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to record the line number pixel width for each window.
@ 2019-12-05 18:19 Keith David Bershatsky
  2019-12-06  8:10 ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Keith David Bershatsky @ 2019-12-05 18:19 UTC (permalink / raw)
  To: Emacs Devel

I am working on feature requests 22873 (multiple fake cursors) and 17684 (crosshairs and visible fill column, both of which able to vertically intersect characters at any screen X coordinate).  The latest patch is:

    VERSION: 022.005 [11/17/2019]

    https://debbugs.gnu.org/cgi/bugreport.cgi?bug=22873#176

Features 17684/22873 have been purposefully designed to obviate the need to call start_display; i.e., there is no need to move IT in order to obtain any values used in the implementation of 17684/22873.

I do not want to use the built-in function line_number_display_width, which fires up start_display and moves IT to figure out the line number pixel width (among other values).  Instead, I would like to devise a reliable method whereby the display engine records the value (line number pixel width) for each window (wherever features 17684/22873 are active), such that those values are reliably accessible when Emacs calls update_window (located in dispnew.c).

I have been using the snippet below to record the value of the line number pixel width for each window.  This value, however, is unreliable when dealing with a window containing folded/hidden text, such as an org-mode buffer.  When dealing with folded/hidden text (e.g., org-mode), the recorded value sporadically changes while moving the cursor (e.g. pressing the arrow keys) even though the contents of the window do not change.

How can I perfect the recorded value of the line number pixel width, and also avoid expressly firing up a new instance of start_display and moving IT for the sole purpose of determining the value for each window during update_window (in dispnew.c)?

Thanks,

Keith

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


diff --git a/src/xdisp.c b/src/xdisp.c
index 2467b33..dd901da 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -22720,6 +22720,28 @@ maybe_produce_line_number (struct it *it)
 	}
     }
 
+
+/* *************************************************************************** */
+/* MULTIPLE-CURSORS */
+
+  struct buffer *b = XBUFFER (it->w->contents);
+  struct buffer *old_buffer = NULL;
+  /* Needed so that buffer-local values can be determined; e.g., when switching
+  to the minibuffer. */
+  if (b != current_buffer)
+    {
+      old_buffer = current_buffer;
+      set_buffer_internal (b);
+    }
+  it->w->mc.lnum_pixel_width = (!NILP (Vdisplay_line_numbers))
+                               ? tem_it.current_x
+                               : 0;
+  if (old_buffer)
+    set_buffer_internal (old_buffer);
+
+/* *************************************************************************** */
+
+
   /* Record the width in pixels we need for the line number display.  */
   it->lnum_pixel_width = tem_it.current_x;
   /* Copy the produced glyphs into IT's glyph_row.  */



^ permalink raw reply related	[flat|nested] 7+ messages in thread
* Re: How to record the line number pixel width for each window.
@ 2019-12-08  2:57 Keith David Bershatsky
  0 siblings, 0 replies; 7+ messages in thread
From: Keith David Bershatsky @ 2019-12-08  2:57 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Thank you, Eli, for your insight -- greatly appreciated!  Based on your helpful comments and also based upon examining the code for line_number_display_width, I came up with the following conditions to use when setting the window object with the line number pixel width (which is set from within maybe_produce_line_number):

  if (it->area == TEXT_AREA
      && IT_CHARPOS (*it) == wstart.charpos)
    {
      [Set the window object with the line number pixel width.]
    }

The entire snippet is listed below.  I did some limited testing this evening in an org-mode buffer and so far so good.  I will continue to test out the revised code in the coming days to see if any problems arise.


diff --git a/src/xdisp.c b/src/xdisp.c
index 2467b33..dfc9a61 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -22720,6 +22720,34 @@ maybe_produce_line_number (struct it *it)
 	}
     }
 
+
+/* *************************************************************************** */
+/* MULTIPLE-CURSORS */
+
+  struct text_pos wstart;
+  SET_TEXT_POS_FROM_MARKER (wstart, it->w->start);
+  if (it->area == TEXT_AREA
+      && IT_CHARPOS (*it) == wstart.charpos)
+    {
+      struct buffer *b = XBUFFER (it->w->contents);
+      struct buffer *old_buffer = NULL;
+      /* Needed so that buffer-local values can be determined; e.g., when switching
+      to the minibuffer. */
+      if (b != current_buffer)
+        {
+          old_buffer = current_buffer;
+          set_buffer_internal (b);
+        }
+      it->w->mc.lnum_pixel_width = (!NILP (Vdisplay_line_numbers))
+                                   ? tem_it.current_x
+                                   : 0;
+      if (old_buffer)
+        set_buffer_internal (old_buffer);
+    }
+
+/* *************************************************************************** */
+
+
   /* Record the width in pixels we need for the line number display.  */
   it->lnum_pixel_width = tem_it.current_x;
   /* Copy the produced glyphs into IT's glyph_row.  */



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

end of thread, other threads:[~2019-12-08  2:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-05 18:19 How to record the line number pixel width for each window Keith David Bershatsky
2019-12-06  8:10 ` Eli Zaretskii
2019-12-06 17:07   ` Keith David Bershatsky
2019-12-06 18:42     ` Eli Zaretskii
2019-12-06 19:29       ` Keith David Bershatsky
2019-12-07  8:27         ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2019-12-08  2:57 Keith David Bershatsky

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.