Published 2025-09-07
tag(s): #emacs #programming
I've seen some Emacs commands that operate on "pages" before, one that comes to mind
is narrow-to-page
, but I never paid too much attention to them.
A few days ago I found online a mention to the built-in page-ext
package, from
its header:
The page commands are helpful in several different contexts. For
example, programmers often divide source files into sections using the
`page-delimiter'; you can use the `pages-directory' command to list
the sections.
The package documentation then explains that it adds a few navigation commands to jump around
a buffer per page, add and remove pages, and list all the pages (mentioned above).
So, what is the page-delimiter
? By default it is the
regexp "^^L"
, which matches any line beginning with the form feed
character (Wikipedia).
But of course you can change it to any other regexp, to match whatever you
are writing currently describes as a page.
After finding out about these "page extensions", I searched a bit online about using form
feeds to separate sections. It seems other than Elisp, it is also used in Python code. But it
is not very common.
I wish C# would have used them to delimit regions instead of #region
.
I thought earlier "it would be nice if the .NET world used ^L instead of #region"...but it wasn't until typing this that I realized, it doesn't matter, you still can use the page commands.
If I set page-delimiter
to " *<h[[:digit:]]>"
in this
very buffer (and add a few fake headers for display), listing all pages in the buffer results
in:
==== Pages Directory: use RET to go to page under cursor. ====
<!DOCTYPE html>
Digression: You could use page navigation in C# </h2>
A section</h2>
Sub section 1</h3>
Another section</h2>
Sub section 1</h3>
Sub section 2</h3>
Footnotes</h6>
Awesome. Back to the main content...
In a lot of my Elisp packages, I used the same separator format: A bunch of hyphens, and then in the column 20, the section name. For example, from Sharper:
{more code before}
;;------------------Customization options-----------------------------------------
(defgroup sharper nil
"dotnet CLI wrapper, using Transient."
:group 'extensions)
{more code after}
Then I would use occur
, to list all lines with the text
;;------------------
. But instead, I could use form feeds, which I think are much
cleaner. Just now I made a couple of changes to my publishing tools[1]
and while I was at it I added form feed page delimiters, like so:
{more code before}
^L
;;; Creating posts
(defun site-start-post (&optional alternative-template)
{more code after}
And now I get the benefit of listing pages and moving between them.
I don't necessarily have to change my older packages, since I can modify the delimiter as I
did earlier for this very buffer. But I think the single "invisible" character is an
improvement.
Time will tell.
One, I will never stop finding out about features included in Emacs.
Two, that through Emacs I end up finding out about how things were done "in the good old
days", which is interesting, and sometimes useful.
Third...there's no third.