From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Bastien Newsgroups: gmane.emacs.devel Subject: Re: line-start? Date: Fri, 07 Feb 2020 11:11:15 +0100 Message-ID: <87lfpe7lmk.fsf@bzg.fr> References: <87ftfof1xl.fsf@gnu.org> <877e0zrhud.fsf@gnu.org> <83o8ubfu9l.fsf@gnu.org> <87v9oiucdn.fsf@bzg.fr> <838sleg3d6.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="28189"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Feb 07 11:11:49 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j00c1-0007F7-Ho for ged-emacs-devel@m.gmane-mx.org; Fri, 07 Feb 2020 11:11:49 +0100 Original-Received: from localhost ([::1]:53284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j00c0-0001ll-L0 for ged-emacs-devel@m.gmane-mx.org; Fri, 07 Feb 2020 05:11:48 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45401) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j00bY-0001Iu-CY for emacs-devel@gnu.org; Fri, 07 Feb 2020 05:11:21 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:38079) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1j00bY-0005ze-9C for emacs-devel@gnu.org; Fri, 07 Feb 2020 05:11:20 -0500 Original-Received: from [185.24.184.132] (port=45927 helo=guerry) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1j00bX-0000Pa-GO; Fri, 07 Feb 2020 05:11:19 -0500 Original-Received: by guerry (Postfix, from userid 1000) id C2A0A1A6030E; Fri, 7 Feb 2020 11:11:15 +0100 (CET) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:244889 Archived-At: Eli Zaretskii 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