bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#31061: 27.0.50; next-page of page-ext non-functional in dired


From: Marco Wahl
Subject: bug#31061: 27.0.50; next-page of page-ext non-functional in dired
Date: Fri, 27 Apr 2018 13:50:08 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Noam Postavsky <address@hidden> writes:

> Marco Wahl <address@hidden> writes:
>
>> Precondition:
>>
>> - Have a dired with several subdirectories open.
>
> Also, M-x load-lib RET page-ext RET

Yes, thanks.

>> Action:
>>
>> - C-x C-p C-n
>>
>> Expectation:
>>
>> - The dired buffer narrows to the next subdirectory.
>>
>> Observation:
>>
>> - The dired buffer narrows to the current subdirectory.
>
>> * lisp/textmodes/page-ext.el (next-page): Jump ahead page-delimiter if
>>   at such before narrow.  This fixes the command for dired.
>
> I think the problem is rather that next-page is going an extra page
> backwards even when COUNT was positive, so the fix should be more like
> this (inline version with whitespace changes ignored, full version
> attached):
>
> --- a/lisp/textmodes/page-ext.el
> +++ b/lisp/textmodes/page-ext.el
> @@ -304,6 +304,7 @@ next-page
>    (or count (setq count 1))
>    (widen)
>    ;; Cannot use forward-page because of problems at page boundaries.
> +  (if (>= count 0)
>        (while (and (> count 0) (not (eobp)))
>          (if (re-search-forward page-delimiter nil t)
>              nil
> @@ -316,7 +317,7 @@ next-page
>        (if (re-search-backward page-delimiter nil t)
>            (goto-char (match-beginning 0))
>          (goto-char (point-min)))
> -    (setq count (1+ count)))
> +      (setq count (1+ count))))
>    (narrow-to-page)
>    (goto-char (point-min))
>    (recenter 0))

I think this is a good idea to separate the cases clearly.

I found that with your suggestion next-page with negative argument goes
back one page too much in a dired buffer, though.

I further think that the core of the irritation is that `narrow-to-page'
does not narrow to the following page when on the start of the '\n\n'
page-separator (unlike for the usual '^^L' separator).

Starting with your fix I propose this modification of the else part:

    (while (and (< count 1) (not (bobp)))
      (if (re-search-backward page-delimiter nil t)
          (when (= count 0)
              (goto-char (match-end 0)))
        (goto-char (point-min)))
      (setq count (1+ count)))

This is: go to the end of the delimiter when the final page has been
reached.

Below a diff to make the suggested change perfectly clear, hopefully.

diff --git a/lisp/textmodes/page-ext.el b/lisp/textmodes/page-ext.el
index fbdae5892a..4990fde65a 100644
--- a/lisp/textmodes/page-ext.el
+++ b/lisp/textmodes/page-ext.el
@@ -304,19 +304,21 @@ next-page
   (or count (setq count 1))
   (widen)
   ;; Cannot use forward-page because of problems at page boundaries.
-  (while (and (> count 0) (not (eobp)))
-    (if (re-search-forward page-delimiter nil t)
-        nil
-      (goto-char (point-max)))
-    (setq count (1- count)))
-  ;; If COUNT is negative, we want to go back -COUNT + 1 page boundaries.
-  ;; The first page boundary we reach is the top of the current page,
-  ;; which doesn't count.
-  (while (and (< count 1) (not (bobp)))
-    (if (re-search-backward page-delimiter nil t)
-       (goto-char (match-beginning 0))
-      (goto-char (point-min)))
-    (setq count (1+ count)))
+  (if (>= count 0)
+      (while (and (> count 0) (not (eobp)))
+        (if (re-search-forward page-delimiter nil t)
+            nil
+          (goto-char (point-max)))
+        (setq count (1- count)))
+   ;; If COUNT is negative, we want to go back -COUNT + 1 page boundaries.
+   ;; The first page boundary we reach is the top of the current page,
+   ;; which doesn't count.
+    (while (and (< count 1) (not (bobp)))
+      (if (re-search-backward page-delimiter nil t)
+          (when (= count 0)
+              (goto-char (match-end 0)))
+        (goto-char (point-min)))
+      (setq count (1+ count))))
   (narrow-to-page)
   (goto-char (point-min))
   (recenter 0))






reply via email to

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