* count-lines-page @ 2010-08-22 18:31 Christoph 2010-08-22 19:38 ` count-lines-page Glenn Morris 0 siblings, 1 reply; 4+ messages in thread From: Christoph @ 2010-08-22 18:31 UTC (permalink / raw) To: emacs-devel 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 am wondering if this behavior is intended or a bug itself. emacs -Q open a buffer, type test C-a i.e. test ^ point M-x count-lines-page Output: Page has 1 lines (0 + 1) (means: 0 before, 1 after) C-f i.e. test ^ point M-x count-lines-page Output: Page has 1 lines (1 + 1) (means: 1 before, 1 after) Does this make sense? There is only 1 line in the buffer. How can there be 1 before and 1 after? Christoph ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: count-lines-page 2010-08-22 18:31 count-lines-page Christoph @ 2010-08-22 19:38 ` Glenn Morris 2010-08-24 22:56 ` count-lines-page Stephen Berman 0 siblings, 1 reply; 4+ messages in thread From: Glenn Morris @ 2010-08-22 19:38 UTC (permalink / raw) To: Christoph; +Cc: emacs-devel 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. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: count-lines-page 2010-08-22 19:38 ` count-lines-page Glenn Morris @ 2010-08-24 22:56 ` Stephen Berman 2010-08-24 23:18 ` count-lines-page Stephen Berman 0 siblings, 1 reply; 4+ messages in thread From: Stephen Berman @ 2010-08-24 22:56 UTC (permalink / raw) To: emacs-devel 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 () ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: count-lines-page 2010-08-24 22:56 ` count-lines-page Stephen Berman @ 2010-08-24 23:18 ` Stephen Berman 0 siblings, 0 replies; 4+ messages in thread From: Stephen Berman @ 2010-08-24 23:18 UTC (permalink / raw) To: emacs-devel On Wed, 25 Aug 2010 00:56:03 +0200 Stephen Berman <stephen.berman@gmx.net> wrote: > 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). On second thought, I guess "or" was right after all -- and should be used in my patch instead of "and". But the clearest formulation is with "and": "Also show how many lines precede and how many follow the line point is on." > 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 () ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-08-24 23:18 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-08-22 18:31 count-lines-page Christoph 2010-08-22 19:38 ` count-lines-page Glenn Morris 2010-08-24 22:56 ` count-lines-page Stephen Berman 2010-08-24 23:18 ` count-lines-page Stephen Berman
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).