unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Brinkhoff <lars.brinkhoff@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 68215@debbugs.gnu.org
Subject: bug#68215: Bug in what-page
Date: Thu, 11 Jan 2024 14:49:58 +0100	[thread overview]
Message-ID: <CANrY3pbrZ0JJhHNEFT1k-KkdR=EHb2JQ=ZuJaHziGTAz=5saBg@mail.gmail.com> (raw)
In-Reply-To: <83il46u7he.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1019 bytes --]

Eli Zaretskii <eliz@gnu.org> wrote:
> It should be a simple matter to countermand this special-casing in
> what-page, while still using count-lines.  Or am I missing something?

That's probably better.  I'm attaching an updated patch which uses
count-lines instead.  It countermands the special case by checking
(bolp) and then doing the opposite adjustment.

However, there's one more case to consider: when point starts out
right after a page delimiter (i.e. the very first positon on a page),
the page--what-page while loop will leave the final point there too,
and then count-lines will return 0.  The line number should be 1, so
an adjustment is needed there too.

The updated test is the same as the previous round, and they still
pass with the new patch.

> > +  "Return a list of the page number of point, and the line number
> > +within that page."
>
> Our convention is to have the first line of a doc string be a single
> complete sentence.

Fixed by moving info to a second line, or rephrasing to one line.

[-- Attachment #2: what-line-2.patch --]
[-- Type: text/x-patch, Size: 2016 bytes --]

commit 746013e179735673b2ad535ea46d54bae3f38d50
Author: Lars Brinkhoff <lars@nocrew.org>
Date:   Tue Jan 2 09:06:13 2024 +0100

    Fix what-page.

diff --git a/lisp/textmodes/page.el b/lisp/textmodes/page.el
index e8621ee0383..1c7561d71c6 100644
--- a/lisp/textmodes/page.el
+++ b/lisp/textmodes/page.el
@@ -159,21 +159,23 @@ count-lines-page
              total before after)))
 
 (defun page--what-page ()
-  "Return a list of the page and line number of point."
+  "Return a list of the page and line number of point.
+The line number is relative to the start of the page."
   (save-restriction
     (widen)
     (save-excursion
       (let ((count 1)
+            (adjust (if (or (bolp) (looking-back page-delimiter)) 1 0))
             (opoint (point)))
         (goto-char (point-min))
         (while (re-search-forward page-delimiter opoint t)
           (when (= (match-beginning 0) (match-end 0))
             (forward-char))
           (setq count (1+ count)))
-        (list count (line-number-at-pos opoint))))))
+        (list count (+ adjust (count-lines (point) opoint)))))))
 
 (defun what-page ()
-  "Print page and line number of point."
+  "Display the page number, and the line number within that page."
   (interactive)
   (apply #'message (cons "Page %d, line %d" (page--what-page))))
 
diff --git a/test/lisp/textmodes/page-tests.el b/test/lisp/textmodes/page-tests.el
index f3a2c5fbe00..617b59a54fb 100644
--- a/test/lisp/textmodes/page-tests.el
+++ b/test/lisp/textmodes/page-tests.el
@@ -106,10 +106,14 @@ page-tests-what-page
     (insert "foo\n\f\nbar\n\f\nbaz")
     (goto-char (point-min))
     (should (equal (page--what-page) '(1 1)))
+    (forward-char)
+    (should (equal (page--what-page) '(1 1)))
     (forward-page)
+    (should (equal (page--what-page) '(2 1)))
+    (next-line)
     (should (equal (page--what-page) '(2 2)))
     (forward-page)
-    (should (equal (page--what-page) '(3 4)))))
+    (should (equal (page--what-page) '(3 1)))))
 
 
 ;;; page-tests.el ends here

  reply	other threads:[~2024-01-11 13:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-02 10:39 bug#68215: Bug in what-page Lars Brinkhoff
2024-01-06  9:38 ` Eli Zaretskii
2024-01-11 13:49   ` Lars Brinkhoff [this message]
2024-01-13 10:10     ` Eli Zaretskii

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CANrY3pbrZ0JJhHNEFT1k-KkdR=EHb2JQ=ZuJaHziGTAz=5saBg@mail.gmail.com' \
    --to=lars.brinkhoff@gmail.com \
    --cc=68215@debbugs.gnu.org \
    --cc=eliz@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 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).