Problem
There is an issue with the current value of POS
in helm-pages-get-pages
. According to the documentation, POS
is the beginning of a page. However, except for the first page, the value of POS
is actually the position before the page-delimiter
.
Example
For example, suppose that ^L
is the page-delimiter, and we have a buffer as follows:
First page
Foo
^L
Second page
Bar
^L
Third page
Baz
Let (n)
be the position of the beginning of the nth page. Then I would expect:
(1)First page
Foo
^L
(2)Second page
Bar
^L
(3)Third page
Baz
Instead, we currently have:
(1)First page
Foo
(2)^L
Second page
Bar
(3)^L
Third page
Baz
Consequence
The consequence of this inconsistency is that the helm-pages-goto-page
and helm-pages-narrow-to-page
functions have to call forward-line
to position the cursor as the the user would expect, but this causes the cursor for the first page to be positioned on the second line, not the first.
Try it: call helm-pages-goto-page
on First page
in the above example while using helm-pages
. Let (|)
indicate the cursor. Then I would expect:
(|)First page
Foo
^L
Second page
Bar
^L
Third page
Baz
Instead, we currently have:
First page
(|)Foo
^L
Second page
Bar
^L
Third page
Baz
Solution
- Change
helm-pages-get-pages
to:
(defun helm-pages-get-pages ()
"Get a list of (POS . HEADER) pairs, where POS denotes the
beginning of a page and HEADER is the contents of the first
non-blank line in that page."
(with-helm-current-buffer
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(let ((pages (list (cons (point)
(helm-pages-get-next-header)))))
(while (re-search-forward page-delimiter nil t)
(forward-line)
(push (cons (point)
(helm-pages-get-next-header))
pages))
(nreverse pages))))))
- Remove
forward-line
from helm-pages-goto-page
and helm-pages-narrow-to-page
.