GNU bug report logs - #80023
31.0.50; possible to get height and width of the block cursor?

Previous Next

Package: emacs;

Reported by: Huang Jing <rne.kou <at> icloud.com>

Date: Wed, 17 Dec 2025 15:03:02 UTC

Severity: normal

Found in version 31.0.50

To reply to this bug, email your comments to 80023 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#80023; Package emacs. (Wed, 17 Dec 2025 15:03:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Huang Jing <rne.kou <at> icloud.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 17 Dec 2025 15:03:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Huang Jing <rne.kou <at> icloud.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 31.0.50; possible to get height and width of the block cursor?
Date: Wed, 17 Dec 2025 23:01:34 +0800
Hi,

I would like to ask if it's possible to get the height and width of
the Emacs rendered block cursor.  I am implementing shared module
based cursor animation, and for this I need to know the information of
the `native' cursor rendered by Emacs.

My current approach is to get its width and height using:

    | (if-let* ((cursor (point))
    |           (glyph (and (< cursor (point-max))
    |                       (aref (font-get-glyphs
    |                              (font-at cursor)
    |                              cursor
    |                              (1+ cursor)) 0))))
    |     (aref glyph 4)
    |   (frame-char-width))
    |
    | (line-pixel-height)

however the height of the cursor does not always equal to
(line-pixel-height), and it also does not equals the value of ascent +
descent.

This dimensions for the cursor is crucial since existing function to
get the position of the cursor returns different y-positions for
content in a single line with glyphs of different height:

    | あ A
    | ^   ^

executing `(window-absolute-pixel-position)' with cursor placed above
the marked positions (on `あ' and at the end of that line with C-e)
will give you different y-coordinates, so without knowing the height
of the cursor, the cursor as well as the animation of the cursor I
draw will be misplaced.


In GNU Emacs 31.0.50 (build 1, aarch64-apple-darwin24.6.0, NS
 appkit-2575.70 Version 15.7.2 (Build 24G325)) of 2025-12-14 built on
 sjc22-bt152-a920b187-934f-4007-ae20-7e0a252b26e4-1A7E858BCAFB.local
Repository revision: 699fb56b4e26aa2cffeec3292bf01c4ac5b11c44
Repository branch: master
Windowing system distributor 'Apple', version 10.3.2575
System Description:  macOS 15.7.2

Configured using:
 'configure 'CFLAGS=-g0 -O2 -flto=thin' 'PKG_CONFIG=pkg-config
 -static' --disable-gc-mark-trace --without-all
 --with-compress-install --with-gmp --with-gnutls --with-modules
 --with-native-image-api --with-ns --with-small-ja-dic --with-threads
 --with-toolkit-scroll-bars --with-tree-sitter --with-xml2
 --with-zlib'

Configured features:
GMP GNUTLS LIBXML2 MODULES NS PDUMPER THREADS TOOLKIT_SCROLL_BARS
TREE_SITTER ZLIB




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#80023; Package emacs. (Wed, 17 Dec 2025 15:24:02 GMT) Full text and rfc822 format available.

Message #8 received at 80023 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Huang Jing <rne.kou <at> icloud.com>
Cc: 80023 <at> debbugs.gnu.org
Subject: Re: bug#80023: 31.0.50;
 possible to get height and width of the block cursor?
Date: Wed, 17 Dec 2025 17:23:05 +0200
> Date: Wed, 17 Dec 2025 23:01:34 +0800
> From:  Huang Jing via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
> I would like to ask if it's possible to get the height and width of
> the Emacs rendered block cursor.  I am implementing shared module
> based cursor animation, and for this I need to know the information of
> the `native' cursor rendered by Emacs.
> 
> My current approach is to get its width and height using:
> 
>     | (if-let* ((cursor (point))
>     |           (glyph (and (< cursor (point-max))
>     |                       (aref (font-get-glyphs
>     |                              (font-at cursor)
>     |                              cursor
>     |                              (1+ cursor)) 0))))
>     |     (aref glyph 4)
>     |   (frame-char-width))
>     |
>     | (line-pixel-height)
> 
> however the height of the cursor does not always equal to
> (line-pixel-height), and it also does not equals the value of ascent +
> descent.

The Emacs "block cursor" is just the character at point drawn with
inverse video, so the dimensions of the cursor are exactly the metrics
of the character glyph at point.

Please show an example which led you to the conclusion that the glyph
information returned by font-get-glyphs does not provide what you
want.  I suggest that you use some specific font that is widely
available, so that others could reproduce your results on their
systems.

> 
> This dimensions for the cursor is crucial since existing function to
> get the position of the cursor returns different y-positions for
> content in a single line with glyphs of different height:
> 
>     | あ A
>     | ^   ^
> 
> executing `(window-absolute-pixel-position)' with cursor placed above
> the marked positions (on `あ' and at the end of that line with C-e)
> will give you different y-coordinates, so without knowing the height
> of the cursor, the cursor as well as the animation of the cursor I
> draw will be misplaced.

On my system, with the above two character glyphs (which are displayed
using two different fonts here), the y-coordinate is the same.  So I
guess this might be specific to the fonts.  Or maybe this is a
macOS-specific issue?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#80023; Package emacs. (Wed, 17 Dec 2025 15:43:01 GMT) Full text and rfc822 format available.

Message #11 received at 80023 <at> debbugs.gnu.org (full text, mbox):

From: Huang Jing <rne.kou <at> icloud.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 80023 <at> debbugs.gnu.org, Huang Jing <rne.kou <at> icloud.com>
Subject: Re: bug#80023: 31.0.50;
 possible to get height and width of the block cursor?
Date: Wed, 17 Dec 2025 23:42:09 +0800
On Wed, 17 Dec 2025 23:23:05 +0800,
Eli Zaretskii wrote:
> 
> > Date: Wed, 17 Dec 2025 23:01:34 +0800
> > From:  Huang Jing via "Bug reports for GNU Emacs,
> >  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> > 
> > I would like to ask if it's possible to get the height and width of
> > the Emacs rendered block cursor.  I am implementing shared module
> > based cursor animation, and for this I need to know the information of
> > the `native' cursor rendered by Emacs.
> > 
> > My current approach is to get its width and height using:
> > 
> >     | (if-let* ((cursor (point))
> >     |           (glyph (and (< cursor (point-max))
> >     |                       (aref (font-get-glyphs
> >     |                              (font-at cursor)
> >     |                              cursor
> >     |                              (1+ cursor)) 0))))
> >     |     (aref glyph 4)
> >     |   (frame-char-width))
> >     |
> >     | (line-pixel-height)
> > 
> > however the height of the cursor does not always equal to
> > (line-pixel-height), and it also does not equals the value of ascent +
> > descent.
> 
> The Emacs "block cursor" is just the character at point drawn with
> inverse video, so the dimensions of the cursor are exactly the metrics
> of the character glyph at point.
> 
> Please show an example which led you to the conclusion that the glyph
> information returned by font-get-glyphs does not provide what you
> want.  I suggest that you use some specific font that is widely
> available, so that others could reproduce your results on their
> systems.

Sure, so for glyph semicolon `:' and <eof> (maybe space?), the glyph I
got using:

   | (when-let* ((cursor (point))
   |             (glyph (and (< cursor (point-max))
   |                         (aref (font-get-glyphs
   |                                (font-at cursor)
   |                                cursor
   |                                (1+ cursor)) 0))))
   |   (message "glyph info = %s" glyph))

is respectively:

   | glyph info = [0 0 58 1147 7 2 6 7 1 nil]
   | glyph info = [0 0 10 3 7 0 0 0 0 nil]

while the cursor height which is equal to `line-pixel-height' in this
case is 14, and cannot be consrtucted using values of glyph info.

> > 
> > This dimensions for the cursor is crucial since existing function to
> > get the position of the cursor returns different y-positions for
> > content in a single line with glyphs of different height:
> > 
> >     | あ A
> >     | ^   ^
> > 
> > executing `(window-absolute-pixel-position)' with cursor placed above
> > the marked positions (on `あ' and at the end of that line with C-e)
> > will give you different y-coordinates, so without knowing the height
> > of the cursor, the cursor as well as the animation of the cursor I
> > draw will be misplaced.
> 
> On my system, with the above two character glyphs (which are displayed
> using two different fonts here), the y-coordinate is the same.  So I
> guess this might be specific to the fonts.  Or maybe this is a
> macOS-specific issue?

I have no idea if this is anothe macOS-specific issue. Using the
default font (emacs -Q), with this log function:

   | (defun debug-cursor ()
   |   (interactive)
   |   (when-let* ((cursor (point))
   |               (glyph (and (< cursor (point-max))
   |                           (aref (font-get-glyphs
   |                                  (font-at cursor)
   |                                  cursor
   |                                  (1+ cursor)) 0))))
   |     (message "glyph info        = %s" glyph)
   |     (message "line-pixel-height = %s" (line-pixel-height))
   |     (message "position info     = %s" (window-absolute-pixel-position))))

and the test line:

   | あ A
   | ^   ^
   | 1   2

the result I get is:

   | glyph info        = [0 0 12354 843 12 0 12 10 1 nil]
   | line-pixel-height = 15
   | position info     = (787 . 548)
   | glyph info        = [0 0 10 3 7 0 0 0 0 nil]
   | line-pixel-height = 15
   | position info     = (813 . 549)

which the position info shows the differnet y-coordinates.

Thanks for investigating!




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#80023; Package emacs. (Wed, 17 Dec 2025 16:45:01 GMT) Full text and rfc822 format available.

Message #14 received at 80023 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Huang Jing <rne.kou <at> icloud.com>
Cc: 80023 <at> debbugs.gnu.org
Subject: Re: bug#80023: 31.0.50;
 possible to get height and width of the block cursor?
Date: Wed, 17 Dec 2025 18:44:28 +0200
> Date: Wed, 17 Dec 2025 23:42:09 +0800
> From: Huang Jing <rne.kou <at> icloud.com>
> Cc: Huang Jing <rne.kou <at> icloud.com>,
> 	80023 <at> debbugs.gnu.org
> 
> > The Emacs "block cursor" is just the character at point drawn with
> > inverse video, so the dimensions of the cursor are exactly the metrics
> > of the character glyph at point.
> > 
> > Please show an example which led you to the conclusion that the glyph
> > information returned by font-get-glyphs does not provide what you
> > want.  I suggest that you use some specific font that is widely
> > available, so that others could reproduce your results on their
> > systems.
> 
> Sure, so for glyph semicolon `:' and <eof> (maybe space?), the glyph I
> got using:
> 
>    | (when-let* ((cursor (point))
>    |             (glyph (and (< cursor (point-max))
>    |                         (aref (font-get-glyphs
>    |                                (font-at cursor)
>    |                                cursor
>    |                                (1+ cursor)) 0))))
>    |   (message "glyph info = %s" glyph))
> 
> is respectively:
> 
>    | glyph info = [0 0 58 1147 7 2 6 7 1 nil]
>    | glyph info = [0 0 10 3 7 0 0 0 0 nil]
> 
> while the cursor height which is equal to `line-pixel-height' in this
> case is 14, and cannot be consrtucted using values of glyph info.

You are looking at the case where the cursor is displayed on something
that is not a character.  There are no characters at EOB and at end of
each line.  So font-get-glyphs cannot tell you anything useful because
there's no font glyph at those points.

What I meant to ask was whether the information for the colon ':'
glyph is incorrect, and if so, please show what is incorrect.  In your
case, the colon glyph has ascent of 7 pixels and descent of 1 pixel,
so the height of the cursor displayed on ':' should be 8 pixels.  Its
width should also be 7 pixels.  If this is not so, please tell what
are the dimensions of the block cursor shown on ':' in your case.

The block cursor shown at the end of each line has the same height as
the value as what line-pixel-height returns.
> > On my system, with the above two character glyphs (which are displayed
> > using two different fonts here), the y-coordinate is the same.  So I
> > guess this might be specific to the fonts.  Or maybe this is a
> > macOS-specific issue?
> 
> I have no idea if this is anothe macOS-specific issue. Using the
> default font (emacs -Q), with this log function:
> 
>    | (defun debug-cursor ()
>    |   (interactive)
>    |   (when-let* ((cursor (point))
>    |               (glyph (and (< cursor (point-max))
>    |                           (aref (font-get-glyphs
>    |                                  (font-at cursor)
>    |                                  cursor
>    |                                  (1+ cursor)) 0))))
>    |     (message "glyph info        = %s" glyph)
>    |     (message "line-pixel-height = %s" (line-pixel-height))
>    |     (message "position info     = %s" (window-absolute-pixel-position))))
> 
> and the test line:
> 
>    | あ A
>    | ^   ^
>    | 1   2
> 
> the result I get is:
> 
>    | glyph info        = [0 0 12354 843 12 0 12 10 1 nil]

This is a character glyph of a character whose codepoint is #x3042
(12354 decimal).

>    | line-pixel-height = 15
>    | position info     = (787 . 548)
>    | glyph info        = [0 0 10 3 7 0 0 0 0 nil]

This is a glyph shown at the end of the line, where there's no
character, so font-get-glyphs doesn't produce any useful information.

>    | line-pixel-height = 15
>    | position info     = (813 . 549)
> 
> which the position info shows the differnet y-coordinates.

I don't really understand what do you intend to do in the general
case.  What do you do when a character is displayed via a
display-table? font-at can only provide information about characters
from buffer text or from a string, but display-table tells Emacs to
show a completely different glyph instead.  And what do you do for
images shown in a window? or for stretches of whitespace (such as
produced by '(space :width N)' display specs)?  And there are other
tricky situation where font-get-glyphs cannot provide you what you
need.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#80023; Package emacs. (Thu, 18 Dec 2025 04:42:02 GMT) Full text and rfc822 format available.

Message #17 received at 80023 <at> debbugs.gnu.org (full text, mbox):

From: Huang Jing <rne.kou <at> icloud.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 80023 <at> debbugs.gnu.org, Huang Jing <rne.kou <at> icloud.com>
Subject: Re: bug#80023: 31.0.50;
 possible to get height and width of the block cursor?
Date: Thu, 18 Dec 2025 12:41:42 +0800
On Thu, 18 Dec 2025 00:44:28 +0800,
Eli Zaretskii wrote:
> 
> > Date: Wed, 17 Dec 2025 23:42:09 +0800
> > From: Huang Jing <rne.kou <at> icloud.com>
> > Cc: Huang Jing <rne.kou <at> icloud.com>,
> > 	80023 <at> debbugs.gnu.org
> > 
> > > The Emacs "block cursor" is just the character at point drawn with
> > > inverse video, so the dimensions of the cursor are exactly the metrics
> > > of the character glyph at point.
> > > 
> > > Please show an example which led you to the conclusion that the glyph
> > > information returned by font-get-glyphs does not provide what you
> > > want.  I suggest that you use some specific font that is widely
> > > available, so that others could reproduce your results on their
> > > systems.
> > 
> > Sure, so for glyph semicolon `:' and <eof> (maybe space?), the glyph I
> > got using:
> > 
> >    | (when-let* ((cursor (point))
> >    |             (glyph (and (< cursor (point-max))
> >    |                         (aref (font-get-glyphs
> >    |                                (font-at cursor)
> >    |                                cursor
> >    |                                (1+ cursor)) 0))))
> >    |   (message "glyph info = %s" glyph))
> > 
> > is respectively:
> > 
> >    | glyph info = [0 0 58 1147 7 2 6 7 1 nil]
> >    | glyph info = [0 0 10 3 7 0 0 0 0 nil]
> > 
> > while the cursor height which is equal to `line-pixel-height' in this
> > case is 14, and cannot be consrtucted using values of glyph info.
> 
> You are looking at the case where the cursor is displayed on something
> that is not a character.  There are no characters at EOB and at end of
> each line.  So font-get-glyphs cannot tell you anything useful because
> there's no font glyph at those points.
>
> What I meant to ask was whether the information for the colon ':'
> glyph is incorrect, and if so, please show what is incorrect.  In your
> case, the colon glyph has ascent of 7 pixels and descent of 1 pixel,
> so the height of the cursor displayed on ':' should be 8 pixels.  Its
> width should also be 7 pixels.  If this is not so, please tell what
> are the dimensions of the block cursor shown on ':' in your case.

You mentioned that for a colon, the cursor height should be 8 pixels.
However my observations contradict this.  When the cursor is on the
colon, its height matches the cursor at the EOL, which is 14 according
to `line-pixel-height'.  If its height is really only 8 pixels high,
it would appear nearly half as tall as it actually is.

And if the block cursor's height (when placed on a valid character) is
strickly determined by the sum of the character's ascent and descent,
the cursor's height will vary as it moves through text.  For instance,
the glyph height for `A' (9 pixel) differs from `a' (8 pixels), and
both is different from `line-pixel-height'.

> The block cursor shown at the end of each line has the same height as
> the value as what line-pixel-height returns.
>
> > > On my system, with the above two character glyphs (which are displayed
> > > using two different fonts here), the y-coordinate is the same.  So I
> > > guess this might be specific to the fonts.  Or maybe this is a
> > > macOS-specific issue?
> > 
> > I have no idea if this is anothe macOS-specific issue. Using the
> > default font (emacs -Q), with this log function:
> > 
> >    | (defun debug-cursor ()
> >    |   (interactive)
> >    |   (when-let* ((cursor (point))
> >    |               (glyph (and (< cursor (point-max))
> >    |                           (aref (font-get-glyphs
> >    |                                  (font-at cursor)
> >    |                                  cursor
> >    |                                  (1+ cursor)) 0))))
> >    |     (message "glyph info        = %s" glyph)
> >    |     (message "line-pixel-height = %s" (line-pixel-height))
> >    |     (message "position info     = %s" (window-absolute-pixel-position))))
> > 
> > and the test line:
> > 
> >    | あ A
> >    | ^   ^
> >    | 1   2
> > 
> > the result I get is:
> > 
> >    | glyph info        = [0 0 12354 843 12 0 12 10 1 nil]
> 
> This is a character glyph of a character whose codepoint is #x3042
> (12354 decimal).
> 
> >    | line-pixel-height = 15
> >    | position info     = (787 . 548)
> >    | glyph info        = [0 0 10 3 7 0 0 0 0 nil]
> 
> This is a glyph shown at the end of the line, where there's no
> character, so font-get-glyphs doesn't produce any useful information.
> 
> >    | line-pixel-height = 15
> >    | position info     = (813 . 549)
> > 
> > which the position info shows the differnet y-coordinates.
> 
> I don't really understand what do you intend to do in the general
> case.  What do you do when a character is displayed via a
> display-table? font-at can only provide information about characters
> from buffer text or from a string, but display-table tells Emacs to
> show a completely different glyph instead.  And what do you do for
> images shown in a window? or for stretches of whitespace (such as
> produced by '(space :width N)' display specs)?  And there are other
> tricky situation where font-get-glyphs cannot provide you what you
> need.

That's exactly why I am asking if it is possible to directly access
the calculated cursor height and width, and if not, would it possible
to expose them so they could be accessed using elisp :)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#80023; Package emacs. (Thu, 18 Dec 2025 07:40:02 GMT) Full text and rfc822 format available.

Message #20 received at 80023 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Huang Jing <rne.kou <at> icloud.com>
Cc: 80023 <at> debbugs.gnu.org, rne.kou <at> icloud.com
Subject: Re: bug#80023: 31.0.50;
 possible to get height and width of the block cursor?
Date: Thu, 18 Dec 2025 09:39:47 +0200
> Date: Thu, 18 Dec 2025 12:41:42 +0800
> From: Huang Jing <rne.kou <at> icloud.com>
> Cc: Huang Jing <rne.kou <at> icloud.com>,
> 	80023 <at> debbugs.gnu.org
> 
> You mentioned that for a colon, the cursor height should be 8 pixels.
> However my observations contradict this.  When the cursor is on the
> colon, its height matches the cursor at the EOL, which is 14 according
> to `line-pixel-height'.  If its height is really only 8 pixels high,
> it would appear nearly half as tall as it actually is.
> 
> And if the block cursor's height (when placed on a valid character) is
> strickly determined by the sum of the character's ascent and descent,
> the cursor's height will vary as it moves through text.  For instance,
> the glyph height for `A' (9 pixel) differs from `a' (8 pixels), and
> both is different from `line-pixel-height'.

You are right, we actually use the font's metrics in this case, not
the metrics of the character's glyph.  So you need to use font-info,
as in

  (font-info (font-at POSITION))

to get the font's values of ascent and descent.  And that is, of
course, still limited to places where the display shows a character
from the buffer; places like end of line and EOB still have the
problem I mentioned in my previous message.

Does this match your measurements?

> > I don't really understand what do you intend to do in the general
> > case.  What do you do when a character is displayed via a
> > display-table? font-at can only provide information about characters
> > from buffer text or from a string, but display-table tells Emacs to
> > show a completely different glyph instead.  And what do you do for
> > images shown in a window? or for stretches of whitespace (such as
> > produced by '(space :width N)' display specs)?  And there are other
> > tricky situation where font-get-glyphs cannot provide you what you
> > need.
> 
> That's exactly why I am asking if it is possible to directly access
> the calculated cursor height and width,

I think, given the complications I mentioned, the answer is NO.

> and if not, would it possible to expose them so they could be
> accessed using elisp :)

Well, we do record the cursor geometry in the window object.  But that
information is only valid after a successful redisplay, because only
then do we update the cursor.  Using this information from a Lisp
program, especially a program that modifies the buffer or affects the
display in some way, would be unreliable, since the information will
either be unavailable or incorrect.  If these restrictions are
acceptable, we could add a primitive to return the cursor geometry
information for a window.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#80023; Package emacs. (Thu, 18 Dec 2025 11:34:02 GMT) Full text and rfc822 format available.

Message #23 received at 80023 <at> debbugs.gnu.org (full text, mbox):

From: Huang Jing <rne.kou <at> icloud.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 80023 <at> debbugs.gnu.org, Huang Jing <rne.kou <at> icloud.com>
Subject: Re: bug#80023: 31.0.50;
 possible to get height and width of the block cursor?
Date: Thu, 18 Dec 2025 19:33:35 +0800
On Thu, 18 Dec 2025 15:39:47 +0800,
Eli Zaretskii wrote:
> 
> > Date: Thu, 18 Dec 2025 12:41:42 +0800
> > From: Huang Jing <rne.kou <at> icloud.com>
> > Cc: Huang Jing <rne.kou <at> icloud.com>,
> > 	80023 <at> debbugs.gnu.org
> > 
> > You mentioned that for a colon, the cursor height should be 8 pixels.
> > However my observations contradict this.  When the cursor is on the
> > colon, its height matches the cursor at the EOL, which is 14 according
> > to `line-pixel-height'.  If its height is really only 8 pixels high,
> > it would appear nearly half as tall as it actually is.
> > 
> > And if the block cursor's height (when placed on a valid character) is
> > strickly determined by the sum of the character's ascent and descent,
> > the cursor's height will vary as it moves through text.  For instance,
> > the glyph height for `A' (9 pixel) differs from `a' (8 pixels), and
> > both is different from `line-pixel-height'.
> 
> You are right, we actually use the font's metrics in this case, not
> the metrics of the character's glyph.  So you need to use font-info,
> as in
> 
>   (font-info (font-at POSITION))
> 
> to get the font's values of ascent and descent.  And that is, of
> course, still limited to places where the display shows a character
> from the buffer; places like end of line and EOB still have the
> problem I mentioned in my previous message.
> 
> Does this match your measurements?

Yes, now it does.  The `it' refers to the HEIGHT returned from
`font-info', using for example:

   | (aref (font-info (font-at (point))) 3)

> > > I don't really understand what do you intend to do in the general
> > > case.  What do you do when a character is displayed via a
> > > display-table? font-at can only provide information about characters
> > > from buffer text or from a string, but display-table tells Emacs to
> > > show a completely different glyph instead.  And what do you do for
> > > images shown in a window? or for stretches of whitespace (such as
> > > produced by '(space :width N)' display specs)?  And there are other
> > > tricky situation where font-get-glyphs cannot provide you what you
> > > need.
> > 
> > That's exactly why I am asking if it is possible to directly access
> > the calculated cursor height and width,
> 
> I think, given the complications I mentioned, the answer is NO.
> 
> > and if not, would it possible to expose them so they could be
> > accessed using elisp :)
> 
> Well, we do record the cursor geometry in the window object.  But that
> information is only valid after a successful redisplay, because only
> then do we update the cursor.  Using this information from a Lisp
> program, especially a program that modifies the buffer or affects the
> display in some way, would be unreliable, since the information will
> either be unavailable or incorrect.  If these restrictions are
> acceptable, we could add a primitive to return the cursor geometry
> information for a window.

That would be really helpful.  I would be happy to help implement it
by the way.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#80023; Package emacs. (Thu, 18 Dec 2025 14:08:01 GMT) Full text and rfc822 format available.

Message #26 received at 80023 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Huang Jing <rne.kou <at> icloud.com>
Cc: 80023 <at> debbugs.gnu.org, rne.kou <at> icloud.com
Subject: Re: bug#80023: 31.0.50;
 possible to get height and width of the block cursor?
Date: Thu, 18 Dec 2025 16:07:32 +0200
> Date: Thu, 18 Dec 2025 19:33:35 +0800
> From: Huang Jing <rne.kou <at> icloud.com>
> Cc: Huang Jing <rne.kou <at> icloud.com>,
> 	80023 <at> debbugs.gnu.org
> 
> > Well, we do record the cursor geometry in the window object.  But that
> > information is only valid after a successful redisplay, because only
> > then do we update the cursor.  Using this information from a Lisp
> > program, especially a program that modifies the buffer or affects the
> > display in some way, would be unreliable, since the information will
> > either be unavailable or incorrect.  If these restrictions are
> > acceptable, we could add a primitive to return the cursor geometry
> > information for a window.
> 
> That would be really helpful.  I would be happy to help implement it
> by the way.

See get_phys_cursor_geometry and get_phys_cursor_glyph.  They should
be the basis for the implementation, IMO.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#80023; Package emacs. (Thu, 18 Dec 2025 14:48:02 GMT) Full text and rfc822 format available.

Message #29 received at 80023 <at> debbugs.gnu.org (full text, mbox):

From: Huang Jing <rne.kou <at> icloud.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 80023 <at> debbugs.gnu.org, Huang Jing <rne.kou <at> icloud.com>
Subject: Re: bug#80023: 31.0.50;
 possible to get height and width of the block cursor?
Date: Thu, 18 Dec 2025 22:47:12 +0800
On Thu, 18 Dec 2025 22:07:32 +0800,
Eli Zaretskii wrote:
> 
> > Date: Thu, 18 Dec 2025 19:33:35 +0800
> > From: Huang Jing <rne.kou <at> icloud.com>
> > Cc: Huang Jing <rne.kou <at> icloud.com>,
> > 	80023 <at> debbugs.gnu.org
> > 
> > > Well, we do record the cursor geometry in the window object.  But that
> > > information is only valid after a successful redisplay, because only
> > > then do we update the cursor.  Using this information from a Lisp
> > > program, especially a program that modifies the buffer or affects the
> > > display in some way, would be unreliable, since the information will
> > > either be unavailable or incorrect.  If these restrictions are
> > > acceptable, we could add a primitive to return the cursor geometry
> > > information for a window.
> > 
> > That would be really helpful.  I would be happy to help implement it
> > by the way.
> 
> See get_phys_cursor_geometry and get_phys_cursor_glyph.  They should
> be the basis for the implementation, IMO.

Thanks for the pointer!




This bug report was last modified 1 day ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.