The venerable form feed character
source link: https://www.eigenbahn.com/2021/04/22/form-feed-character
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
The venerable form feed character
April 22, 2021Introduction
The form feed character (aka FF
, ASCII 0x0C
, Unicode \f
, ^L
in caret notation) is an artifact from the past.
A past where printers where simpler beasts and relied on a this special invisible (control) character to be told of page breaks.
At a time when people printed their source codes, those characters were commonly used to delimit code sections, forcing a page break for easier reading.
Comments as section delimiters
It’s quite common, especially with programming languages that don’t enforce code segmentation (non OOP-centric) to split a source file in section delimited by comments.
Your typical Python script usually looks something like:
## ------------------------------------------------------------------------
## CONFIG
#[...]
## ------------------------------------------------------------------------
## HELPER FNS
#[...]
## ------------------------------------------------------------------------
## MAIN
#[...]
See all those delimiters made of dashes?
Those lines are generally 75 characters wide to fit under the 80 character width a lot of editors/terminal windows have by default.
This allows displaying the whole line (with no wrap) under most circumstances.
People generally use extensions / keyboard shortcuts to insert those quickly.
But there might be a better way.
Form feed characters as an alternative
Using a line composed of a single FF
character instead provides many benefits:
- on supported software, it gets displayed as a solid horizontal line taking the whole window width
- it’s detected as a comment so no need to prefix it with a commenting character (e.g.
#
for Python) - it can be typed quickly (
C-q C-l
in Emacs)
In fact form feed characters can be found in many Clojure, Elisp, C and Python source codes.
Form feed delimiter in Emacs
Emacs’ source code features an extensive use of the FF
character.
The output of compilation-mode
uses this character (typically when updating several package).
Strangely, by default, Emacs display those characters in caret notation (^L
), which is not super user-friendly.
Thankfully, either package form-feed or page-break-lines allows displaying them as a proper horizontal delimiter.
Furthermore, Emacs provides commands to navigate between FF
-delimited sections: backward-page
(C-x [
) and forward-page
(C-x ]
).
Form feed delimiter in other editors
UltraEdit render those appropriately natively.
@Alhadis made an package to bring this feature to Atom.
Sadly, nothing seem to exist for IntelliJ IDEA, Sublime Text nor VSCode.
Form feed delimiter on GitHub
GitHub doesn’t style those FF
section delimiters.
Thankfully it was trivial to make a userscript to enable this support.
Introducing: p3r7/gh-userscript-form-feed-line
And here is a screenshot of the result:
The code is small enough to be embedded. The trick is to replace FF
lines with <hr/>
html elements:
$(document).ready(function(){
const form_feed=""; // <- there is a FF between these quotes ...
// ... (even if your web browser doesn't render it)
$("td.js-file-line:contains('" + form_feed + "')").html('<hr/>');
$("td.js-file-line > hr").css('margin', '10px auto auto 0');
});
In Conclusion
Using a form feed character as a section delimiter is an elegant solution.
Sadly, few people seem to know about it and few software support it.
So if you want portability, you’d have to stick with the comment-line-made-of-(dashes|underscores|whatever) solution.
If you work on an ecosystem that fully support those, such as Emacs packages, I encourage you to try it.
In any case, it’s sad that “modern” editors don’t support this “old” yet still relevant feature.
But all hope is not lost!
Open issues / PRs. Create plugins/extensions. Spread the word.
See also
Xah Lee’s take on the subject.
Tagged #emacs.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK