From: Stephen Berman <stephen.berman@gmx.net>
To: emacs-devel@gnu.org
Subject: Re: count-lines-page
Date: Wed, 25 Aug 2010 00:56:03 +0200 [thread overview]
Message-ID: <874oejoc1o.fsf@escher.home> (raw)
In-Reply-To: dyvd72l9ob.fsf@fencepost.gnu.org
On Sun, 22 Aug 2010 15:38:44 -0400 Glenn Morris <rgm@gnu.org> wrote:
> Christoph wrote:
>
>> Bug #6825 (http://debbugs.gnu.org/cgi/bugreport.cgi?bug=6825) points
>> out some peculiar behavior of what-page. This is actually caused by
>> the count-lines-page function.
>
> I thought it was caused by the 2009-09-16 change to what-page, but I
> didn't check properly.
>
>> Does this make sense? There is only 1 line in the buffer. How can
>> there be 1 before and 1 after?
>
> The doc of count-lines says such behaviour is to be expected.
> I guess it's an implementation detail.
I think the best fix for what-page is simply to use line-number-at-pos
instead of count lines (I submitted a patch to bug#6825 to this effect).
(Checking the ChangeLogs, what-page predates line-number-at-pos by many
years, so I guess no one noticed, or at least bothered to report, the
problem before Christoph.)
It's not clear to me what the best fix for count-lines-page is, because
it's not clear to me what the output should be: if point is at bol it
may make sense to say the entire line is after it (but what if it is
empty?), but if point is between bol and eol, it seems strange to say
the line is both before and after it, as in the current implementation,
but also strange to pick one or the other. Intuitively, I think the
line point is on is neither before nor after point: so if the page has
three lines and point is anywhere on line 2, there is one line before
and after, if it is on line 1, there are no lines before and two after,
if it is on line 3, there are two before and none after. The following
patch implements this behavior (and changes the doc string accordingly;
the original doc string is in any case too long and also uses "or" where
"and" is meant).
Steve Berman
*** /data/steve/bzr/emacs/trunk/lisp/textmodes/page.el 2010-01-13 10:56:56.000000000 +0100
--- /data/steve/bzr/emacs/quickfixes/lisp/textmodes/page.el 2010-08-25 00:47:30.000000000 +0200
***************
*** 126,132 ****
(put 'narrow-to-page 'disabled t)
(defun count-lines-page ()
! "Report number of lines on current page, and how many are before or after point."
(interactive)
(save-excursion
(let ((opoint (point)) beg end
--- 126,133 ----
(put 'narrow-to-page 'disabled t)
(defun count-lines-page ()
! "Return the number of lines on the current page.
! Also show how many lines precede and follow the line point is on."
(interactive)
(save-excursion
(let ((opoint (point)) beg end
***************
*** 139,146 ****
(backward-page)
(setq beg (point))
(setq total (count-lines beg end)
! before (count-lines beg opoint)
! after (count-lines opoint end))
(message "Page has %d lines (%d + %d)" total before after))))
(defun what-page ()
--- 140,149 ----
(backward-page)
(setq beg (point))
(setq total (count-lines beg end)
! before (- (line-number-at-pos opoint)
! (line-number-at-pos (point-min)))
! after (- (line-number-at-pos (point-max))
! (line-number-at-pos opoint)))
(message "Page has %d lines (%d + %d)" total before after))))
(defun what-page ()
next prev parent reply other threads:[~2010-08-24 22:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-22 18:31 count-lines-page Christoph
2010-08-22 19:38 ` count-lines-page Glenn Morris
2010-08-24 22:56 ` Stephen Berman [this message]
2010-08-24 23:18 ` count-lines-page Stephen Berman
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=874oejoc1o.fsf@escher.home \
--to=stephen.berman@gmx.net \
--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.