emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: count-lines-page


From: Stephen Berman
Subject: Re: count-lines-page
Date: Wed, 25 Aug 2010 00:56:03 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

On Sun, 22 Aug 2010 15:38:44 -0400 Glenn Morris <address@hidden> 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 ()




reply via email to

[Prev in Thread] Current Thread [Next in Thread]