26.4 Pages

Within some text files, text is divided into pages delimited by the formfeed character (ASCII code 12, also denoted as ‘control-L’), which is displayed in Emacs as the escape sequence ‘^L’ (see How Text Is Displayed). Traditionally, when such text files are printed to hardcopy, each formfeed character forces a page break. Most Emacs commands treat it just like any other character, so you can insert it with C-q C-l, delete it with DEL, etc. In addition, Emacs provides commands to move over pages and operate on them.

M-x what-page

Display the page number of point, and the line number within that page.

C-x [

Move point to previous page boundary (backward-page).

C-x ]

Move point to next page boundary (forward-page).

C-x C-p

Put point and mark around this page (or another page) (mark-page).

C-x l

Count the lines in this page (count-lines-page).

M-x what-page counts pages from the beginning of the file, and counts lines within the page, showing both numbers in the echo area.

The C-x [ (backward-page) command moves point to immediately after the previous page delimiter. If point is already right after a page delimiter, it skips that one and stops at the previous one. A numeric argument serves as a repeat count. The C-x ] (forward-page) command moves forward past the next page delimiter.

The C-x C-p command (mark-page) puts point at the beginning of the current page (after that page delimiter at the front), and the mark at the end of the page (after the page delimiter at the end).

C-x C-p C-w is a handy way to kill a page to move it elsewhere. If you move to another page delimiter with C-x [ and C-x ], then yank the killed page, all the pages will be properly delimited once again. Making sure this works as expected is the reason C-x C-p includes only the following page delimiter in the region.

A numeric argument to C-x C-p specifies which page to go to, relative to the current one. Zero means the current page, one means the next page, and −1 means the previous one.

The C-x l command (count-lines-page) is good for deciding where to break a page in two. It displays in the echo area the total number of lines in the current page, and then divides it up into those preceding the current line and those following, as in

Page has 96 (72+25) lines

Notice that the sum is off by one; this is correct if point is not at the beginning of a line.

The variable page-delimiter controls where pages begin. Its value is a regular expression that matches the beginning of a line that separates pages (see Syntax of Regular Expressions). The normal value of this variable is "^\f", which matches a formfeed character at the beginning of a line.