Emacs Form Feed ^L

By Xah Lee. Date: . Last updated: .

This page discusses the problems of the Form feed character (^L) used in emacs as source code section marker.

emacs page break lines mode screenshot 2012-11-15
Emacs, the top pane shows the Form Feed ^L as is, the bottom displays it as line.

If you just want practical tips, see: Emacs: Show Formfeed ^L as Line.

In emacs lisp source code, sometimes you'll see “^L”. That's the “Form Feed” character (ASCII 12).

In Emacs Lisp source code, the Form Feed is used as a section marker. For example, Alt+x describe-functionCtrl+h f】, then dired, then click on the “dired.el” link to view the source code. Scroll around and you'll see it.

It is also used in C source code from GNU projects, or old Python source code. In general, most code after 2000 no longer follow this convention.

The Form Feed character is used in 1990s or earlier to cause printer to start a new page. Printers today no longer use that in their protocol.

In emacs, there's a built-in command backward-pageCtrl+x [】 and forward-pageCtrl+x ]】 to page thru sections.

You can insert the Form Feed character by pressing 【Ctrl+q Ctrl+l】.

Problems of Form Feed as Section Marker in Emacs Lisp

The convention of using Form Feed character as code section marker has several problems:

So, in the end, using the Form Feed as section indicator has 2 problems. One is technical.

Suggested Solution

Emacs should display the Form Feed character as a horizontal line. For example, bundle and turn on the package page-break-lines.el. [see Emacs: Show Formfeed ^L as Line]

Problems of Section Navigation Key in Emacs

Emacs has keys to jump to the Form Feed char. By default, the keys are:

It's hard to use. For example, you cannot hold on a key to keep paging.

Suggested Solution

Emacs should make the keys 【Ctrl+Alt+Page Up】 and 【Ctrl+Alt+Page Down】 as default. These would be compatible with lisp code navigation keys, all use【Ctrl+Alt】. [see Emacs: How to Edit Lisp Code]

;; keys for moving to prev/next code section (Form Feed; ^L)
(global-set-key (kbd "<C-M-prior>") 'backward-page) ; Ctrl+Alt+PageUp
(global-set-key (kbd "<C-M-next>") 'forward-page)   ; Ctrl+Alt+PageDown

Design Analysis of Using Form Feed Character as Code Section Marker

A single specialized character as a universal markup for source code section break, is quite elegant and useful.

Advantages of Using Form Feed as Section Marker in Source Code

Normally, programer mark section in source code with lots of comment chars. For example:

; emacs lisp
# perl, ruby, python, bash, …
# perl, ruby, python, bash, …
// C, C++, Java, …

These are not as elegant or convenient as the Form Feed char. First problem is typing them. Even if your editor provide a easy way to type the char repeatedly, such as emacs's 【Ctrl+u 50】 prefix, that's still 4 or 5 extra keys to press.

It is also hard to search. Because the style varies, some source code repeat the comment chars such as “##########”, some start with a comment char then followed by dashes “#----------”, some uses underline, some draws a ASCII art box, like this:

#         PRETTY!            #

All these variations make it hard to jump to the section. Typically, you search the string, for example, search a sequence of 5 #, but because the line has more than 5, your search will linger on the same line. Instead, you have to search almost the exact the number of chars used for this, and it is common that the number of chars for such line is not consistent. Or, you may use regex, but again, much more typing and the result is not precise.

The Form Feed char has several advantages over this. If you use it for section mark, it makes it precise, easy to locate, and easy to navigate to all different sections. All this because there's a unique single character as a delimiter, and its meaning is basically universal.

The fundamental reason of the Form Feed char as section marker advantage over ASCII text, is due to the semantic vs presentation issue. For discussion of various common issues on this, see:

Problems of Using Form Feed as Section Marker

In lisp, the Form Feed char is ignored by the compiler. This is probably true for vast majority of languages today still. However, it causes problems in some languages.

Cygwin Bash

Cygwin Bash will generate this error if your shell script contains the Form Feed char that's not in comment.

bash: $'\f': command not found


AutoHotkey scripting language generates compiler error if you have a uncommented Form Feed char in source code.


PHP would print a warning about it: “Warning: Unexpected character in the input: '^L' (ASCII=12)”. This is in PHP bug database php.net bug#5912.

Emacs: Form Feed Must be on a Line by Itself

If your language does not allow uncomment Form Feed char, and if you put a comment character in front, but emacs's {forward-page, backward-page} commands won't recognize Form Feed char as section break if they are not the only char in a line.

Other Issues

A major problem of using Form Feed char for section break is simply the visibility. Almost no editors display the Form Feed as a line. So, for vast majority of coders, a sequence of dash “----------” is simply the more practical solution. Also, today, few programers know how to insert a Form Feed character in their editor.

For reasons of why it is displayed in emacs as ^L, see: Emacs's Key Syntax Explained.

A Universal Source Code Section Markup

Unfortunately, there's no good or standard replacement. Usually, people just add a bunch of hyphen like this ----- or equal sing ===== or underscore _____ or just a sequence of comment char. These are hackish. The problem with these approach is you cannot have a key to do paging because the page marker is not standardized.

So, a workaround i came up is to use the Unicode SECTION SIGN §, followed by the Unicode BOX DRAWINGS LIGHT HORIZONTAL (U+2500) . Like this:

; § ────────── ────────── ────────── ────────── ──────────

This approach is designed for all source code. It doesn't have the invisible character problem, nor the compiler choke problem. The disadvantage is the requirement of Unicode, and some inconvenience of input. (the inconvenience of input can be easily solved by editor.) [see Unicode Popularity on Web by Google]


For inputting the section marker, you can define a abbrev, like this:

("ss" "§ ────────── ────────── ────────── ────────── ──────────")

[see Emacs: Abbrev Mode Tutorial]


Here's lisp code that lets you navigate the new section marker.

(defun forward-section ()
  "Move cursor forward to next occurrence of the SECTION SIGN § character."
  (when (not (search-forward "§" nil t))
    (goto-char (point-max)) ) )

(defun backward-section ()
  "Move cursor backward to previous occurrence of the SECTION SIGN § character."
  (when (not (search-backward "§" nil t))
    (goto-char (point-min)) ) )

Here's the keys:

(global-set-key (kbd "<s-prior>") 'backward-section) ; Win+PageUp
(global-set-key (kbd "<s-next>") 'forward-section) ; Win+PageDown

(global-set-key (kbd "<C-M-prior>") 'backward-page) ; Ctrl+Alt+PageUp
(global-set-key (kbd "<C-M-next>") 'forward-page) ; Ctrl+Alt+PageDown

Note: I have tried to use this section marker for all my code. I used it for about a year. I'm not sure it can ever be popular. There are many obstacles in adopting this:

(thanks to Miura Masahiro for the tip on inputting §. 【Ctrl+x 8 S】 [see Emacs: Unicode Tutorial] )

Emacs Modernization

  1. Simple Changes Emacs Should Adopt
  2. Why Emacs Keys are Painful
  3. Problems of the Scratch Buffer
  4. M-key Notation vs Alt+key Notation
  5. Menu Problem
  6. Mode Line Problem
  7. cua-mode Problems
  8. kill-buffer Induces Buffer Accumulation
  9. Emacs Form Feed ^L
  10. Inconsistency of Search Features
  11. Single Key to Delete Whole Line
  12. Emacs HTML Mode Sucks
  13. Emacs Does Not Support Viewing Images Files In Windows
  14. Emacs Spell Checker Problems
  15. Adopt HTML as Texinfo Replacement
  16. Support HTML Mail
  17. Problems of “man” Command
  18. Emacs Lisp Mode Syntax Coloring Problem
  19. Emacs Ahk Mode Problems
  20. Problems of Emacs's Manual
  21. Problems of Emacs's Manual; Examples
  22. Emacs: Have You Read Emacs Manual?
  23. Elisp: Ban Syntax Table
  24. Emacs: Make elisp-index-search use Current Symbol
  25. Emacs: Usability Problems of Mode Documentation
  26. Problems of Emacswiki
  27. Emacs GNU Texinfo Problems; Invalid HTML
  28. A Record of Frustration in IT Industry; Disappearing FSF URLs, 2006
  29. Emacs Manual Node Persistency Issues
  30. Emacs: dired-do-query-replace-regex Replace ALL (fixed)
  31. Problems of Emacs Supporting Obsolete Systems
  32. Elisp: Function to Copy/Delete a Dir Recursively (fixed)
  33. Thoughts on Common Lisp Scheme Lisp Based Emacs
  34. Text Editors Popularity and Market Research
  35. Text Editor's Cursor Movement Behavior (emacs, vi, Notepad++)
  36. GNU Emacs Development Inefficiency
  37. Emacs Dev Inefficiency and Emacs Web 2.0?
  38. Letter-Case Commands Usability Problems
  39. Emacs: Select Line, between Quotes, Extend Selection
  40. Emacs: isearch Current Word
  41. Suggestions on Line Wrap Commands
  42. Emacs: Single Key to Delete Whole Line
  43. Emacs Cult Problem: Emacs vs Windows Notepad
  44. Emacs Undo and Emacs Cult Problem

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs


Emacs Lisp