Pretty Control-L: Library pp-c-l.el

This page describes library pp-c-l.el, which displays Control-l (`^L’) characters in a pretty way.

Control-l is also called the “form feed” character. In many programming languages it is written as `\f’. The name “form feed” comes from printers that interpret the character as a page break signal, feeding another form (page). Here’s what Wikipedia says about it:

“The form feed character is sometimes used in plain text files of source code as a delimiter for a page break, or as marker for sections of code. Some editors, in particular emacs, has built-in commands to page up/down on the form feed character. This convention is predominantly used in lisp code, and is also seen in Python source code.”

A Control-l character in an Emacs text buffer (e.g. code) appears normally as `^L’, if option ‘ctl-arrow’ is non-‘nil’, or as `\014’ (octal 14) if that option is ‘nil’. It serves as a page-break character for many printers, and, by convention, in code it serves to distinguish sections of code. The Emacs commands for navigating among pages (e.g. ‘forward-page’, bound to `C-x ]’) simply look for Control-l characters. You can also just use ‘C-s C-q C-l’ to search for them. See PageCommands for more.

While Control-l is useful as a section or page separator, `^L’ or `\014’ is a bit ugly, and it doesn’t really let users know that if they print the text a page break will occur at that position.

In Emacs, you can give any character a different display appearance, by redefining its entry in the current display table. Library pp-c-l.el does this to give Control-l a better appearance. You can easily customize this appearance, without fiddling with the display table yourself.

This screenshot shows the default appearance:


Everything between the commented lines corresponds to a single Control-l character. It is (by default) the equivalent of a newline followed by 10 spaces, the text “Section (Printable Page)” and 10 more spaces.

You can toggle the pretty display on and off, using minor mode ‘pretty-control-l-mode’.

See Also: OverlayControlL for an alternative approach, which uses an overlay.


Hey Drew,

This library would be even awesomer if by default it put the string that page-ext.el chooses for its titles (see ‘pages-directory’) into the highlighted boxes. – DaveAbrahams

Thanks for your suggestion. I wasn’t even aware of (standard library) page-ext.el. However, IIUC, I don’t see how pp-c-l.el could do what you suggest. It uses the syntax table to change the display appearance of ^L chars generally (i.e. everywhere). I think what you’re asking for is to visually replace ^L by different page “headers” — i.e., different appearance for different pages. I don’t see how that would be possible. But patches and more info are welcome. – DrewAdams

problem with whitespace-mode?

i have a problem with whitespace-mode. My setup is this:

 (require 'pp-c-l)
 (setq pp^L-^L-string
       "                                                           ")
 (pretty-control-l-mode 1)


;; Make whitespace-mode with very basic background coloring for whitespaces
(setq whitespace-style
      '(spaces tabs newline space-mark tab-mark newline-mark))
;; Make whitespace-mode and whitespace-newline-mode
;; use “¶” for end of line char and ▷ for tab.
(setq whitespace-display-mappings
      '((space-mark 32 [183] [46]) ; normal space, MIDDLE DOT, FULL STOP.
        (space-mark 160 [164] [95]) 
        (space-mark 2208 [2212] [95]) 
        (space-mark 2336 [2340] [95]) 
        (space-mark 3616 [3620] [95]) 
        (space-mark 3872 [3876] [95]) 
        (newline-mark 10 [182 10]) ; newlne
        (tab-mark 9 [9655 9] [92 9]))) ; tab

this should make it look like this (second screenshot): however, it seems when pretty print is loaded, all those triangle and middle dot doesn’t show. – XahLee

Maybe someone else can help, here. I don’t use ‘whitespace-mode’. I confirm that there is a problem. If I follow your instructions minus loading pp-c-l.el, and I turn on ‘global-whitespace-mode’, then I see what you expect (your screenshot). If I then load pp-c-l.el the whitespace effect is gone — even if I then turn off ‘pretty-control-l-mode’.

AFAICT, the only thing ‘pretty-control-l-mode’ does is change the display-table entry for one character (form-feed, aka ^L). Dunno why that would louse things up so much.

Perhaps someone familiar with ‘whitespace-mode’ (Vinicius?) can look into this. From your mail to ([1]), the same problem seems to exist with at least some other libraries, besides pp-c-l.el. If you do make progress debugging this and can point to a problem in the pp-c-l.el code I’ll try to take a look. Sorry. – DrewAdams

PageBreaks CategoryHideStuff CategoryDisplay

Libraries referenced here: Lisp:pp-c-l.el