unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Brinkhoff <lars.brinkhoff@gmail.com>
To: 68215@debbugs.gnu.org
Subject: bug#68215: Bug in what-page
Date: Tue, 2 Jan 2024 11:39:22 +0100	[thread overview]
Message-ID: <CANrY3padm4f4M0bL23HpU7A-eBcpw4FbF3aEwi1-AM13hKCYXQ@mail.gmail.com> (raw)

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

Hello,

The Emacs manual says:
  "M-x what-page
   Display the page number of point, and the line number within that page."

I would argue that this is the intended function, since that is what
GNU Emacs did before 2010, and it is the same as "What Page" in the
original TECO Emacs.

Bug https://debbugs.gnu.org/cgi/bugreport.cgi?bug=6825 noted that the
line number was wrong if the cursor was not at the beginning of a
line.  There was a fix for this, but the fix only works for the first
page.  In subsequent pages, the line number is no longer relative to
the current page.

I'm attaching a patch which restores the original function and also
fixes the bug.  The updated test checks this.  I also updated the
what-page doc string to more clearly explain what line numbers are
reported.

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

commit e678a23ee1b0864f76c2d91d4f354866dcd1199f
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..afbc614770e 100644
--- a/lisp/textmodes/page.el
+++ b/lisp/textmodes/page.el
@@ -159,21 +159,25 @@ 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 number of point, and the line number
+within that page."
   (save-restriction
     (widen)
     (save-excursion
       (let ((count 1)
-            (opoint (point)))
+            (opoint (point))
+            (oline (line-number-at-pos (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
+              (1+ (- oline (line-number-at-pos (point)))))))))
 
 (defun what-page ()
-  "Print page and line number of point."
+  "Display the page number of point, 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-02 10:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-02 10:39 Lars Brinkhoff [this message]
2024-01-06  9:38 ` bug#68215: Bug in what-page Eli Zaretskii
2024-01-11 13:49   ` Lars Brinkhoff
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=CANrY3padm4f4M0bL23HpU7A-eBcpw4FbF3aEwi1-AM13hKCYXQ@mail.gmail.com \
    --to=lars.brinkhoff@gmail.com \
    --cc=68215@debbugs.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).