unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org, stefankangas@gmail.com, dgutov@yandex.ru
Subject: Re: Tick Reduction
Date: Mon, 22 Nov 2021 09:19:59 +0100	[thread overview]
Message-ID: <87v90khaa8.fsf@gnus.org> (raw)
In-Reply-To: <874k85jlmq.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sun, 21 Nov 2021 21:31:57 +0100")

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

I wondered whether it'd be much work to implement a min-width thing for
a sequence of characters.  So with this

(insert "||" (propertize "foo" 'min-width '(10.0)) "||")

and the proof of concept patch (it needs some more sanity checking)
below I get:


[-- Attachment #2: Type: image/png, Size: 13213 bytes --]

[-- Attachment #3: Type: text/plain, Size: 5097 bytes --]


which seems promising.  However, point movement over the stretch glyph
is very wonky -- Emacs basically refuses to put point after that
stretch glyph.

Anybody got any tips on what I need to do to get point movement working
here?

diff --git a/src/dispextern.h b/src/dispextern.h
index a698f6546b..a78be900db 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -2185,6 +2185,8 @@ #define MAX_FRINGE_BITMAPS (1<<FRINGE_ID_BITS)
   /* Not a property.  Used to indicate changes in overlays.  */
   OVERLAY_PROP_IDX,
 
+  MIN_WIDTH_PROP_IDX,
+
   /* Sentinel.  */
   LAST_PROP_IDX
 };
@@ -2746,6 +2748,12 @@ #define OVERLAY_STRING_CHUNK_SIZE 16
   /* For iterating over bidirectional text.  */
   struct bidi_it bidi_it;
   bidi_dir_t paragraph_embedding;
+
+  /* For handling the :min-width property.  The object is the text
+     property we're testing the `eq' of (nil if none), and the integer
+     is the x position of the start of the run of glyphs. */
+  Lisp_Object min_width_property;
+  int min_width_start;
 };
 
 
diff --git a/src/xdisp.c b/src/xdisp.c
index 8d34b7c4c3..83f1f64fec 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -822,6 +822,10 @@ #define RESTORE_IT(pITORIG, pITCOPY, CACHE)	\
 /* Functions to mark elements as needing redisplay.  */
 enum { REDISPLAY_SOME = 2};	/* Arbitrary choice.  */
 
+static bool
+calc_pixel_width_or_height (double *, struct it *, Lisp_Object,
+			    struct font *, bool, int *);
+
 void
 redisplay_other_windows (void)
 {
@@ -969,6 +973,7 @@ move_trace (char const *fmt, ...)
 static enum prop_handled handle_composition_prop (struct it *);
 static enum prop_handled handle_overlay_change (struct it *);
 static enum prop_handled handle_fontified_prop (struct it *);
+static enum prop_handled handle_min_width_prop (struct it *);
 
 /* Properties handled by iterators.  */
 
@@ -981,6 +986,7 @@ move_trace (char const *fmt, ...)
   {SYMBOL_INDEX (Qdisplay),	DISPLAY_PROP_IDX,	handle_display_prop},
   {SYMBOL_INDEX (Qinvisible),	INVISIBLE_PROP_IDX,	handle_invisible_prop},
   {SYMBOL_INDEX (Qcomposition),	COMPOSITION_PROP_IDX, handle_composition_prop},
+  {SYMBOL_INDEX (Qmin_width),	MIN_WIDTH_PROP_IDX,     handle_min_width_prop},
   {0,				0,			NULL}
 };
 
@@ -5141,6 +5147,81 @@ setup_for_ellipsis (struct it *it, int len)
   it->ellipsis_p = true;
 }
 
+\f
+/***********************************************************************
+			    `min-width' property
+ ***********************************************************************/
+
+/* Set up iterator IT from `min-width' property at its current position.
+   Called from handle_stop.  */
+
+static enum prop_handled
+handle_min_width_prop (struct it *it)
+{
+  if (STRINGP (it->string) || !it->glyph_row)
+    return HANDLED_NORMALLY;
+
+  Lisp_Object buffer = it->w->contents;
+  struct text_pos *position = &it->current.pos;
+  ptrdiff_t bufpos = CHARPOS (*position);
+
+  Lisp_Object propval = Fget_text_property (make_fixnum (bufpos),
+					    Qmin_width, buffer);
+  /* We're being called at the end of the `min-width' sequence,
+     probably. */
+  if (NILP (propval))
+    {
+      /* Check that we're really right after the sequence of
+	 characters covered by this `min-width'.  */
+      if (!NILP (it->min_width_property)
+	  && bufpos > BEGV
+	  && EQ (it->min_width_property,
+		 Fget_text_property (make_fixnum (bufpos - 1),
+				     Qmin_width, buffer)))
+	{
+	  struct font *font = NULL;
+	  double width;
+	  if (FRAME_WINDOW_P (it->f))
+	    {
+#ifdef HAVE_WINDOW_SYSTEM
+	      struct face *face = FACE_FROM_ID (it->f, it->face_id);
+	      font = face->font ? face->font : FRAME_FONT (it->f);
+	      const int stretch_ascent =
+		(((it->ascent + it->descent)
+		  * FONT_BASE (font)) / FONT_HEIGHT (font));
+	      prepare_face_for_display (it->f, face);
+#else
+	      struct face *face = NULL;
+#endif
+	      calc_pixel_width_or_height (&width, it,
+					  XCAR (it->min_width_property),
+					  font, true, NULL);
+	      width -= it->current_x - it->min_width_start;
+	      append_stretch_glyph (it, Qnil,
+				    (int)width,
+				    it->ascent + it->descent,
+				    stretch_ascent);
+	      it->min_width_property = Qnil;
+	    }
+	}
+    }
+  /* We're at the start of a `min-width' sequence -- record the
+     position and the property, so that we can later see if we're at
+     the end.  */
+  else if (CONSP (propval) && NUMBERP (XCAR (propval)))
+    {
+      if (bufpos == BEGV
+	  || (bufpos > BEGV
+	      && !EQ (propval, Fget_text_property (make_fixnum (bufpos - 1),
+						   Qmin_width, buffer))))
+	{
+	  it->min_width_property = propval;
+	  it->min_width_start = it->current_x;
+	}
+    }
+  return HANDLED_NORMALLY;
+}
+
 
 \f
 /***********************************************************************
@@ -7186,6 +7267,7 @@ reseat_1 (struct it *it, struct text_pos pos, bool set_stop_p)
     }
   /* This make the information stored in it->cmp_it invalidate.  */
   it->cmp_it.id = -1;
+  it->min_width_property = Qnil;
 }
 
 

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no


  reply	other threads:[~2021-11-22  8:19 UTC|newest]

Thread overview: 167+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-18 20:37 Tick Reduction Lars Ingebrigtsen
2021-11-18 21:01 ` Perry E. Metzger
2021-11-19  5:25   ` Lars Ingebrigtsen
2021-11-18 21:23 ` Dmitry Gutov
2021-11-19  5:27   ` Lars Ingebrigtsen
2021-11-19  6:31     ` Michael Welsh Duggan
2021-11-19  6:50     ` Stefan Kangas
2021-11-19  7:05       ` Lars Ingebrigtsen
2021-11-19  8:19         ` Eli Zaretskii
2021-11-19  8:30           ` Lars Ingebrigtsen
2021-11-20  8:01             ` Eli Zaretskii
2021-11-20  9:07               ` Lars Ingebrigtsen
2021-11-21 15:11             ` Lars Ingebrigtsen
2021-11-21 17:16               ` Eli Zaretskii
2021-11-21 17:24                 ` Lars Ingebrigtsen
2021-11-21 17:39                   ` Eli Zaretskii
2021-11-21 18:00                     ` Lars Ingebrigtsen
2021-11-21 18:15                       ` Eli Zaretskii
2021-11-21 18:25                         ` Lars Ingebrigtsen
2021-11-21 18:33                           ` Lars Ingebrigtsen
2021-11-21 19:31                           ` Eli Zaretskii
2021-11-21 19:34                             ` Lars Ingebrigtsen
2021-11-21 19:36                               ` Lars Ingebrigtsen
2021-11-21 19:41                                 ` Lars Ingebrigtsen
2021-11-21 19:49                               ` Eli Zaretskii
2021-11-21 19:53                                 ` Lars Ingebrigtsen
2021-11-21 20:07                                   ` Eli Zaretskii
2021-11-21 20:17                                     ` Lars Ingebrigtsen
2021-11-21 20:26                                       ` Eli Zaretskii
2021-11-21 20:30                                         ` Lars Ingebrigtsen
2021-11-21 20:31                                           ` Lars Ingebrigtsen
2021-11-22  8:19                                             ` Lars Ingebrigtsen [this message]
2021-11-22 14:45                                               ` Eli Zaretskii
2021-11-22 14:50                                                 ` Lars Ingebrigtsen
2021-11-22 17:21                                                   ` Eli Zaretskii
2021-11-22 18:35                                                     ` Stefan Monnier
2021-11-23 10:15                                                     ` Lars Ingebrigtsen
2021-11-23 13:41                                                       ` Eli Zaretskii
2021-11-23 13:49                                                         ` Lars Ingebrigtsen
2021-11-23 14:19                                                           ` Eli Zaretskii
2021-11-23 14:32                                                             ` Lars Ingebrigtsen
2021-11-23 14:43                                                               ` Eli Zaretskii
2021-11-24 11:07                                                                 ` Lars Ingebrigtsen
2021-11-24 14:20                                                                   ` Eli Zaretskii
2021-11-24 16:28                                                                     ` Lars Ingebrigtsen
2021-11-24 17:05                                                                       ` Eli Zaretskii
2021-11-24 17:10                                                                         ` Lars Ingebrigtsen
2021-11-24 17:41                                                                           ` Eli Zaretskii
2021-11-24 17:50                                                                             ` Lars Ingebrigtsen
2021-11-24 18:39                                                                               ` Eli Zaretskii
2021-11-24 18:44                                                                                 ` Lars Ingebrigtsen
2021-11-24 19:00                                                                                   ` Eli Zaretskii
2021-11-25 13:02                                                                                     ` Lars Ingebrigtsen
2021-11-25 12:58                                                                                 ` Lars Ingebrigtsen
2021-11-25 13:28                                                                                   ` Eli Zaretskii
2021-11-25 14:29                                                                                     ` Lars Ingebrigtsen
2021-11-25 15:10                                                                                       ` Eli Zaretskii
2021-11-26 12:12                                                                                         ` Lars Ingebrigtsen
2021-11-26 12:43                                                                                           ` Eli Zaretskii
2021-11-24 18:41                                                                             ` Lars Ingebrigtsen
2021-11-24 18:53                                                                               ` Eli Zaretskii
2021-11-24 22:32                                                                                 ` Yuan Fu
2021-11-25  7:34                                                                                   ` Eli Zaretskii
2021-11-26 17:03                                                                                     ` Yuan Fu
2021-11-26 18:41                                                                                       ` Eli Zaretskii
2021-11-26 18:54                                                                                         ` Yuan Fu
2021-11-26 18:57                                                                                           ` Eli Zaretskii
2021-11-25 13:06                                                                                 ` Lars Ingebrigtsen
2021-11-25 14:02                                                                                   ` Eli Zaretskii
2021-11-25 14:07                                                                                     ` Lars Ingebrigtsen
2021-11-25 14:12                                                                                       ` Eli Zaretskii
2021-11-25 14:16                                                                                         ` Lars Ingebrigtsen
2021-11-25 15:04                                                                                           ` Eli Zaretskii
2021-11-26 12:09                                                                                             ` Lars Ingebrigtsen
2021-11-26 12:56                                                                                               ` Eli Zaretskii
2021-11-27 14:15                                                                                                 ` Lars Ingebrigtsen
2021-11-27 14:51                                                                                                   ` Eli Zaretskii
2021-11-29 13:40                                                                                                     ` Lars Ingebrigtsen
2021-11-29 13:53                                                                                                       ` Eli Zaretskii
2021-11-29 14:00                                                                                                         ` Lars Ingebrigtsen
2021-11-29 14:06                                                                                                           ` Eli Zaretskii
2021-11-29 14:15                                                                                                             ` Lars Ingebrigtsen
2021-11-29 14:17                                                                                                             ` Eli Zaretskii
2021-11-29 14:35                                                                                                               ` Eli Zaretskii
2021-11-29 15:06                                                                                                                 ` Lars Ingebrigtsen
2021-11-24 23:10                                               ` Feng Shu
2021-11-25  7:42                                                 ` Eli Zaretskii
2021-11-25 11:52                                                 ` Lars Ingebrigtsen
2021-11-22 23:26                                       ` chad
2021-11-21 20:10                                   ` Lars Ingebrigtsen
2021-11-21 20:22                                     ` Eli Zaretskii
2021-11-21 20:28                                       ` Lars Ingebrigtsen
2021-11-21 20:41                                         ` Lars Ingebrigtsen
2021-11-21 21:13                                           ` Eli Zaretskii
2021-11-21 20:42                                         ` Eli Zaretskii
2021-11-21 21:12                                           ` Eli Zaretskii
2021-11-22 11:22                                             ` Lars Ingebrigtsen
2021-11-22 14:52                                               ` Eli Zaretskii
2021-11-22 14:55                                                 ` Lars Ingebrigtsen
2021-11-22 18:04                                             ` Eli Zaretskii
2021-11-19  8:33         ` Stefan Kangas
2021-11-19  8:39           ` Lars Ingebrigtsen
2021-11-19  8:48             ` Eli Zaretskii
2021-11-19 10:00               ` Lars Ingebrigtsen
2021-11-19 10:28               ` Stefan Kangas
2021-11-19 12:41                 ` Eli Zaretskii
2021-11-19 13:04                   ` Stefan Kangas
2021-11-19 13:18                     ` Eli Zaretskii
2021-11-19 13:41                       ` Stefan Kangas
2021-11-19 13:48                         ` Eli Zaretskii
2021-11-21 13:35                           ` Stefan Kangas
2021-11-19 10:28             ` Stefan Kangas
2021-11-20  8:43               ` Lars Ingebrigtsen
2021-11-20  9:03                 ` Eli Zaretskii
2021-11-20  9:26                   ` Lars Ingebrigtsen
2021-11-20  9:51                     ` Eli Zaretskii
2021-11-20  9:56                       ` Lars Ingebrigtsen
2021-11-20 10:11                         ` Eli Zaretskii
2021-11-21  8:57               ` Lars Ingebrigtsen
2021-11-21  9:02                 ` Lars Ingebrigtsen
2021-11-21 13:36                   ` Stefan Kangas
2021-11-21 19:26                     ` Lars Ingebrigtsen
2021-11-21 13:54             ` Stefan Kangas
2021-11-21 15:25               ` Lars Ingebrigtsen
2021-11-21 19:28                 ` Stefan Kangas
2021-11-21 19:31                   ` Lars Ingebrigtsen
2021-11-22 14:57         ` Use variable-pitch face in more places Stefan Kangas
2021-11-22 15:05           ` Stefan Kangas
2021-11-22 17:22           ` Juri Linkov
2021-11-22 18:10             ` Stefan Kangas
2021-11-22 18:40               ` Juri Linkov
2021-11-23  9:56               ` Lars Ingebrigtsen
2021-11-24  9:12                 ` Juri Linkov
2021-11-24 16:52                   ` Lars Ingebrigtsen
2021-11-24 17:59                     ` Juri Linkov
2021-11-19  7:48       ` Tick Reduction Eli Zaretskii
2021-11-19 13:41         ` Stefan Kangas
2021-11-19 11:58     ` Dmitry Gutov
2021-11-18 22:18 ` [External] : " Drew Adams
2021-11-21 10:17   ` Phil Sainty
2021-11-19  5:48 ` Lars Ingebrigtsen
2021-11-19  7:24   ` Eli Zaretskii
2021-11-19  7:28     ` Lars Ingebrigtsen
2021-11-19  8:26       ` Eli Zaretskii
2021-11-19  8:33         ` Lars Ingebrigtsen
2021-11-19  6:42 ` Eric S Fraga
2021-11-19  7:30   ` Lars Ingebrigtsen
2021-11-19  6:52 ` Stefan Kangas
2021-11-19  7:26   ` Lars Ingebrigtsen
2021-11-19  7:59     ` Stefan Kangas
2021-11-19  8:17       ` Lars Ingebrigtsen
2021-11-19  8:09   ` Eli Zaretskii
2021-11-19  8:34     ` Stefan Kangas
2021-11-19 13:58 ` Stefan Monnier
2021-11-19 14:46   ` Eli Zaretskii
2021-11-19 18:22     ` Stefan Monnier
2021-11-19 18:53       ` Eli Zaretskii
2021-11-19 19:24         ` Stefan Monnier
2021-11-19 19:50           ` Eli Zaretskii
2021-11-19 21:09             ` Stefan Monnier
2021-11-20  6:34               ` Eli Zaretskii
2021-11-20 13:11                 ` Stefan Monnier
2021-11-20 13:32                   ` Eli Zaretskii
2021-11-20 14:06                     ` Stefan Monnier
2021-11-20 14:35                       ` Eli Zaretskii
2021-11-20 15:01                         ` Stefan Monnier
2021-11-20  9:00   ` 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=87v90khaa8.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=dgutov@yandex.ru \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=stefankangas@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 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).