unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 18385@debbugs.gnu.org
Subject: bug#18385: 24.3.93; posn-at-point doesn't account for tab-width
Date: Thu, 04 Sep 2014 02:10:42 +0400	[thread overview]
Message-ID: <540791E2.5070706@yandex.ru> (raw)
In-Reply-To: <8338c8fzt1.fsf@gnu.org>

On 09/03/2014 08:12 PM, Eli Zaretskii wrote:

> If you want a more accurate description of what happens, it is this:
> Glyphs collected for each display line are stored in an array of
> structures which specify how to display each glyph (and that includes
> the calculated pixel width of the glyphs).  What posn-actual-col-row
> gives you is the _index_ of the corresponding glyph structure in that
> array.

Thank you.

>> I believe this value wouldn't be properly correct in most contexts,
>> even in tty, where the major pitfalls you described can't happen.
>
> First, ':align-to' display properties are supported on a TTY as well,
> as are TABs (of course).  But this is actually one more subtle issue
> with posn-actual-col-row, because if you try your recipe in a
> text-mode frame, you will see that there posn-actual-col-row counts
> the TAB as 7 columns, and your recipe works as you expected!

Looks like yet another reason not to use this from Lisp code. :)

> generates, so it knows what is there.  In addition, the "column"
> returned by posn-actual-col-row is used there to index into the
> header-line string, so again, a pure character count is TRT.

Ah, indeed. It's a different application from what I had in mind.

> But every complex data structure should have accessor functions to its
> parts, and the event structure is no exception.

I guess its docstring was that tripped me up. "Actual column" sounds too 
close to the name of `current-column', which does count character widths.

Do you think something like this change would make sense?

Or, also, instead of "contain", maybe use "correspond to" (unrelated to 
the present discussion).

=== modified file 'lisp/subr.el'
--- lisp/subr.el	2014-09-02 15:16:42 +0000
+++ lisp/subr.el	2014-09-03 22:09:02 +0000
@@ -1149,10 +1149,13 @@
  	      (/ (cdr pair) (+ (frame-char-height frame) spacing))))))))

  (defun posn-actual-col-row (position)
-  "Return the actual column and row in POSITION, measured in characters.
-These are the actual row number in the window and character number in 
that row.
-Return nil if POSITION does not contain the actual position; in that case
+  "Return the actual row character number and row number in POSITION.
+Return nil if POSITION does not contain an actual position; in that case
  `posn-col-row' can be used to get approximate values.
+
+Consider using `posn-col-row' instead either way, because this
+function doesn't take character widths into account.
+
  POSITION should be a list of the form returned by the `event-start'
  and `event-end' functions."
    (nth 6 position))







  reply	other threads:[~2014-09-03 22:10 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
2014-09-02 23:30   ` Dmitry Gutov
2014-09-03 16:12     ` Eli Zaretskii
2014-09-03 22:10       ` Dmitry Gutov [this message]
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

  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=540791E2.5070706@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=18385@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /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).