Emacs Form Feed (^L) Display Suggestion and Tips

X

Xah Lee

• Emacs Form Feed (^L) Display Suggestion and Tips
http://xahlee.org/emacs/modernization_formfeed.html

plain text version follows
----------------------------------

Emacs Form Feed (^L) Display Suggestion and Tips

Xah Lee, 2010-06-24

This page discusses some problems involving the Form feed character
(^L) in emacs, and gives you some tips for better solution.

In emacs lisp source code, sometimes you'll see “^Lâ€. That's the “form
feed†character, ascii 12. For example, type “Alt+x describe-
functionâ€, then dired, then click on the “dired.el†link to view the
source code. Scroll around and you'll see it.

--------------------------------------------------
Problem

The form feed char is used in 1990s or earlier to cause printer to
start with a new page. Printers today no longer use that in their
protocol. However, sometimes it is also used by programer as a section
marker. Many emacs lisp source code still have it. It is also
sometimes seen in Python source code.

The displaying of ^L is hard to read, and is mysterious to modern
programers.

--------------------------------------------------
Solution

You can make emacs display a horizontal line instead. You need to
install Pretty Control-L minor mode, by Drew Adams. Download at:
emacswiki.org PrettyControlL.

To install, place the file in your “~/.emacs.d/†dir, then put the
following in your emacs init file (“~/.emacsâ€):

;; add the dir to load path
(add-to-list 'load-path "~/.emacs.d/")

;; display horizontal line for the Form Feed char (ASCII 12, ^L) The
;; Form Feed char is often used in elisp source code for marking
;; sections. The command forward-page (and backward-page) moves to the
;; next form feed char.
(require 'pp-c-l)
(setq pp^L-^L-string
" ")
(pretty-control-l-mode 1)

By default, it'll display a line, but also with the annoying text
“Section (Printable Page)â€.

The line “(setq pp^L-^L-string ...)†above solves that problem.

--------------------------------------------------
Hotkey to Jump to Form Feed

Also, emacs support a hotkey to jump to the form feed char. By
default, the key is “C-x [†and “C-x ]â€. Very hard to use and hard to
remember. You can set a more convenient key. For example:

;; shortcut for moving to prev/next form feed
(global-set-key (kbd "<M-S-next>") 'forward-page) ; Alt+Shift
+PageDown
(global-set-key (kbd "<M-S-prior>") 'backward-page) ; Alt+Shift+PageUp

Note that emacs already uses Ctrl+Page up/down for scrolling left/
right, and Meta+page up/down for paging up/down the next pane, and
Shift+Page up/down selects text. You should not use Ctrl+Shift combo
because Ctrl+Shift+‹letter› is avoided because text based terminals
have problems distinguishing the key from non-shifted letters.

If you have Hyper key set, you can use the following more easier keys:

(global-set-key (kbd "<H-next>") 'forward-page)
(global-set-key (kbd "<H-prior>") 'backward-page)

If you don't use the number pad keys, you can set it to those keys,
like this:

(global-set-key (kbd "<kp-9>") 'backward-page) ; keypad 9
(global-set-key (kbd "<kp-6>") 'forward-page) ; keypad 6

For how to set up hyper key and others, see: How to Define Keyboard
Shortcuts in Emacs.

--------------------------------------------------
Typing the Form Feed Char

In emacs, you can type the char by pressing “Ctrl+q†then “Ctrl+lâ€.

(For explanation of this, see: The Confusion of Emacs's Keystroke
Representation.)

--------------------------------------------------
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:

;--------------------------------------------------

#__________________________________________________

###################################################

///////////////////////////////////////////////////

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 “C-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:

##############################
# functions #
##############################

All these variations makes 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 single
^L char as a delimiter, and it's meaning is basically universal.

--------------------------------------------------
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. Though, make
sure that if you use the char, your language will have no problem with
it. You could also insert one comment char in front of it.

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: The Confusion
of Emacs's Keystroke Representation.

Xah
∑ http://xahlee.org/

☄
 
X

Xah Lee

• Emacs Form Feed (^L) Display Suggestion and Tips
http://xahlee.org/emacs/modernization_formfeed.html

a follow up question.

when i was learning python in ~2005, i remember seeing it in python
code, but i haven't done much python since. Does python source code
still have that now and then? Is there some official guide on marking
sections?

also, besides emacs elisp, does anyone see the form feed char in other
lang source code?

thanks.

Xah
∑ http://xahlee.org/

☄
 
T

Tassilo Horn

Hi Xah,
also, besides emacs elisp, does anyone see the form feed char in other
lang source code?

It's quite often used in messages in newsgroups and mailing lists. The
Gnus news- and mailreader creates nice "Next/Previous page" buttons from
them and hides the next/previous part. Really good for posting fun
questions, so that you don't see the answer directly.

Why did the chicken cross the road?



To show the raccoon it could be done!!

Bye,
Tassilo
 
T

Thomas Jollans

a follow up question.

when i was learning python in ~2005, i remember seeing it in python
code, but i haven't done much python since. Does python source code
still have that now and then? Is there some official guide on marking
sections?

also, besides emacs elisp, does anyone see the form feed char in other
lang source code?

The GNU source code is full of them, I think.
 
X

Xah Lee

Hi Xah,


It's quite often used in messages in newsgroups and mailing lists.  The
Gnus news- and mailreader creates nice "Next/Previous page" buttons from
them and hides the next/previous part.  Really good for posting fun
questions, so that you don't see the answer directly.

Why did the chicken cross the road?    

To show the raccoon it could be done!!

Tassilo, i use google groups to read news, so i don't see any form
feed. Don't think i can see them in any or most web based interface.
Just checked gmane.org it also doesn't show. With google group, if you
view the message raw, it's still there though...

Xah
 
T

Tassilo Horn

Xah Lee said:
Tassilo, i use google groups to read news, so i don't see any form
feed. Don't think i can see them in any or most web based interface.

Real men don't use web interfaces. ;-)
Just checked gmane.org it also doesn't show. With google group, if you
view the message raw, it's still there though...

Yes, I guess adding formfeeds to messages is mostly common in emacs and
lisp related groups, where most readers use emacs with Gnus or
Wanderlust. But also classic newsreaders like slrn treat formfeed as
page divider.

Bye,
Tassilo
 
?

.

Hello Xah,

With your background and the time you spend with emacs/computers, I
cannot explain to myself how you can read the news via a web interface
like google news (google groups was a little better years ago, but now
it is complete rubish). There are so many dedicated readers:
emacs-gnus, tin, slrn, pan...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top