From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.devel Subject: Re: count-lines-page Date: Wed, 25 Aug 2010 00:56:03 +0200 Message-ID: <874oejoc1o.fsf@escher.home> References: <4C716D18.8090006@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1282690590 25937 80.91.229.12 (24 Aug 2010 22:56:30 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 24 Aug 2010 22:56:30 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Aug 25 00:56:28 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Oo2Pq-0004Tm-P5 for ged-emacs-devel@m.gmane.org; Wed, 25 Aug 2010 00:56:27 +0200 Original-Received: from localhost ([127.0.0.1]:57504 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oo2Pq-0001G7-4c for ged-emacs-devel@m.gmane.org; Tue, 24 Aug 2010 18:56:26 -0400 Original-Received: from [140.186.70.92] (port=53200 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oo2Ph-0001E2-3n for emacs-devel@gnu.org; Tue, 24 Aug 2010 18:56:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oo2Pf-0001WA-MZ for emacs-devel@gnu.org; Tue, 24 Aug 2010 18:56:16 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:46124) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oo2Pf-0001Vz-C3 for emacs-devel@gnu.org; Tue, 24 Aug 2010 18:56:15 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Oo2Pc-0004Dr-4r for emacs-devel@gnu.org; Wed, 25 Aug 2010 00:56:12 +0200 Original-Received: from i59f577fd.versanet.de ([89.245.119.253]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 25 Aug 2010 00:56:12 +0200 Original-Received: from stephen.berman by i59f577fd.versanet.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 25 Aug 2010 00:56:12 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 81 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: i59f577fd.versanet.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:129177 Archived-At: On Sun, 22 Aug 2010 15:38:44 -0400 Glenn Morris 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 ()