From: Xah Lee on 24 Jun 2010 08:41 ⢠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/ â
From: Xah Lee on 24 Jun 2010 09:14 On Jun 24, 5:41 am, Xah Lee <xah...(a)gmail.com> wrote: > ⢠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/ â
From: Tassilo Horn on 24 Jun 2010 14:12 Xah Lee <xahlee(a)gmail.com> writes: 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
From: Thomas Jollans on 24 Jun 2010 14:27 On 06/24/2010 03:14 PM, Xah Lee wrote: > On Jun 24, 5:41 am, Xah Lee <xah...(a)gmail.com> wrote: >> • 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? The GNU source code is full of them, I think. > > thanks. > > Xah > ∑ http://xahlee.org/ > > ☄
From: Xah Lee on 25 Jun 2010 16:34
On Jun 24, 11:12 am, Tassilo Horn <tass...(a)member.fsf.org> wrote: > Xah Lee <xah...(a)gmail.com> writes: > > 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!! 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 |