From: Eli Zaretskii <eliz@gnu.org>
To: Dmitry <dgutov@yandex.ru>
Cc: 18385-done@debbugs.gnu.org
Subject: bug#18385: 24.3.93; posn-at-point doesn't account for tab-width
Date: Tue, 02 Sep 2014 18:24:12 +0300 [thread overview]
Message-ID: <83k35mf3kz.fsf@gnu.org> (raw)
In-Reply-To: <86ppffuhx3.fsf@yandex.ru>
> From: Dmitry <dgutov@yandex.ru>
> Date: Tue, 02 Sep 2014 01:53:12 +0400
>
> 1. New, empty buffer.
> 2. (insert "a\tb")
> 3. (posn-actual-col-row (posn-at-point))
> => (3 . 0)
>
> It should probably return (9 . 0).
No, it should return (3 . 0), as it does. You misunderstand the
contract of this function (which is not surprising, since the issue is
a subtle one, and the documentation, while it tries to be accurate,
has a hard time communicating its intent due to inherent ambiguity of
the related terminology).
This sentence from the doc string of posn-actual-col-row says it all:
These are the actual row number in the window and character number
in that row.
"Character number in that row". IOW, it counts characters, not visual
columns. This function, and the data in its POSITION argument which
it accesses, are designed to make it easy to find the glyph (or
"display element") in a screen line, so it simply provides the ordinal
number of the "thing at point" on its screen line, disregarding the
screen dimensions of that thing.
So this is not a bug, but intended, if obscure, behavior.
> I'm not 100% this is actually a bug, but (posn-actual-col-row
> (posn-at-point)) returns the "visually" correct column values in the
> more complex cases (after text with `display' or `compose-region' called
> on it), so not accounting for tab-width looks surprising.
As long as posn-actual-col-row deals with characters of the same
dimensions (i.e. the same font), it will always produce seemingly
accurate "column" counts, no matter whether these characters come from
a buffer, a display property, or an overlay string. (It counts
characters on display, so the source from which they came is
irrelevant.) But as soon as you have something in the line whose
glyph is larger or smaller than the other characters in that line, the
"column" produced by the function will be skewed, because it's
actually not a visual column, but a count of "display elements" from
the beginning of the screen line. E.g., try insert-image or put a
display property which uses ':align-to' or ':width', and you will see
that the image and the stretch of whitespace produced by those are
counted as a single "column", no matter what are their actual
dimensions.
IOW, posn-actual-col-row is not reliable when you want screen
coordinates in row/column units.
> Originally: https://github.com/company-mode/company-mode/issues/175
And you were right to resolve that by using posn-col-row instead.
That function translates pixel coordinates into row/column units,
which is much closer to what you want.
(Yes, it's not easy to do the job of the display engine.)
next prev parent reply other threads:[~2014-09-02 15:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-01 21:53 bug#18385: 24.3.93; posn-at-point doesn't account for tab-width Dmitry
2014-09-02 15:24 ` Eli Zaretskii [this message]
2014-09-02 23:30 ` Dmitry Gutov
2014-09-03 16:12 ` Eli Zaretskii
2014-09-03 22:10 ` Dmitry Gutov
2014-09-04 15:23 ` Eli Zaretskii
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=83k35mf3kz.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=18385-done@debbugs.gnu.org \
--cc=dgutov@yandex.ru \
/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 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.