From: Bastien <bzg@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: line-start?
Date: Fri, 07 Feb 2020 11:11:15 +0100 [thread overview]
Message-ID: <87lfpe7lmk.fsf@bzg.fr> (raw)
In-Reply-To: 838sleg3d6.fsf@gnu.org
Eli Zaretskii <eliz@gnu.org> writes:
> Once again, window-hscroll just returns the number of columns by which
> the window is hscrolled, it doesn't return the buffer position. For
> example, window-hscroll will return the same value for each line in
> the window, although the buffer position of the beginning of each line
> is different. Are you looking for columns or for buffer positions?
I was looking for columns.
The use case was this one: given a line, display the content of this
line in the header line. When horizontally scrolled, the header has
to display a substring of the line under the cursor, something like
(substring (current-line-string) offset-in-columns).
When the text is not scaled, (window-hscroll) does the job of giving
me the columns for the offset.
When the text is scaled, your function does a better job at finding
the position of the first visible char in the current line, from which
I get the offset: (- first-visible-char-in-current-line (point-at-bol))
> Yes, you need to correct the Y coordinate returned by posn-at-point
> when the window has a header line. The correction can be calculated
> like this:
>
> (- (nth 1 (window-edges nil t nil t))
> (nth 1 (window-edges nil nil nil t)))
Nice! My initial use-case is gone, but I like this function:
(defun window-line-start (&optional pos window)
"Return the position of the visual start of the line.
POS defaults to point in WINDOW; WINDOW defaults to the current window."
(nth 1 (posn-at-x-y
0 (+ (cdr (posn-x-y (posn-at-point pos window)))
(- (nth 1 (window-edges nil t nil t))
(nth 1 (window-edges nil nil nil t)))))))
My use-case is gone, I went with overlays instead of the header line.
But I guess `window-line-start' could perhaps be useful to others.
--
Bastien
next prev parent reply other threads:[~2020-02-07 10:11 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-06 10:24 line-start? Bastien
2020-02-06 13:00 ` line-start? Bastien
2020-02-06 18:25 ` line-start? Eli Zaretskii
2020-02-07 6:42 ` line-start? Bastien
2020-02-07 9:20 ` line-start? Eli Zaretskii
2020-02-07 10:11 ` Bastien [this message]
2020-02-07 10:24 ` line-start? Eli Zaretskii
2020-02-07 10:48 ` line-start? Bastien
2020-02-07 13:43 ` line-start? Eli Zaretskii
2020-02-07 14:46 ` line-start? Bastien
2020-02-07 15:56 ` line-start? Eli Zaretskii
2020-02-07 17:42 ` line-start? Bastien
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=87lfpe7lmk.fsf@bzg.fr \
--to=bzg@gnu.org \
--cc=eliz@gnu.org \
--cc=emacs-devel@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 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.