PageBreaks

A page break, or form feed character (ASCII ^L, which is decimal 12, octal 14, and hex c) causes many printers to break documents into pages, especially when printing plain-text files. See WikiPedia:Page break.

To insert ^L in an Emacs buffer, hit ‘C-q C-l’. In EmacsLisp, the form-feed character is written `?\f’, and `\f’ represents it in strings. (`\f’ is also used in C.)

A page break can also be used for a logical separation of source-code sections. Emacs has commands and key bindings that use page breaks, such as ‘forward-page’ (`C-x ]’ or `C-]’), ‘backward-page’ (`C-x [’ or `C-[’), and `narrow-to-page (‘C-x n p’). Other functions, such as ‘mark-page’, operate on the content of a page. See also PageMode.

Display Page Breaks in Alternative Ways

You can show page breaks other than as the text ^L.

Display as a horizontal line, using a display table

(defvar page-break-display-table
  (let ((table (make-display-table)))
    (aset table ?\^L "-------------------------------------------------------------------------------")
    table)
  "Create a display-table that displays page-breaks prettily (kinda. Heh.)")

(defun toggle-page-break-mode ()
  "Toggle the use of pretty page-break displays for the current buffer."
  (interactive)
  (let ((dt (specifier-instance current-display-table
                                (selected-window))))
    (set-specifier current-display-table
                   (if (equal dt page-break-display-table)
                       nil
                     page-break-display-table)
                   (current-buffer))))

This won’t work on Emacs as is because speficier-instance is not defined. It should only work for XEmacs users. – XavierMaillard

Display as a horizontal line, using a face

This computes the display table at run time, so that the horizontal line is always as wide as the current window.

(defvar page-break-face 'bold)
(defvar page-break-string-char ?-)

(defun page-break-display-table ()
  "Create a display-table that displays page-breaks prettily."
  (let ((table (or (copy-sequence standard-display-table)
                   (make-display-table))))
    (aset table ?\^L
          (let ((face-offset (lsh (face-id page-break-face) 19)))
            (vconcat (mapcar (lambda (c) (+ face-offset c)) (make-string (1- (window-width))
                                                                         page-break-string-char)))))
    table))

(define-minor-mode page-break-mode
    "Toggle Page Break mode.

In Page Break mode, page breaks (^L characters) are displayed as a
horizontal line of `page-break-string-char' characters."
  nil " Pgbrk" nil
  (setq buffer-display-table (if page-break-mode
                                 (page-break-display-table)
                                 nil)))

(defun turn-on-page-break-mode ()
  (page-break-mode 1))

(defun turn-off-page-break-mode ()
  (page-break-mode -1))

You can even have a global page-break-mode which computes the length of the line automatically whenever you change of window configurations: – MatthieuLemerre

(defvar page-break-face 'bold)
(defvar page-break-string-char ?-)

(defun page-break-display-table (window)
  "Create a display-table that displays page-breaks prettily."
  (let ((table (or (copy-sequence (window-display-table window))
                   (make-display-table))))
    (aset table ?\^L
          (let ((face-offset (lsh (face-id page-break-face) 19)))
            (vconcat (mapcar (lambda (c) (+ face-offset c)) 
			     (make-string (1- (window-width window))
					  page-break-string-char)))))
    table))


(defun page-break-mode-hook-function  ()
  "Function called for updating display table"
  (mapcar (lambda (window) 
	    (set-window-display-table window 
				      (page-break-display-table window)))
	  (window-list nil 'no-minibuffer)))

(define-minor-mode page-break-mode
  "Toggle Page Break mode.

In Page Break mode, page breaks (^L characters) are displayed as a
horizontal line of `page-break-string-char' characters."
  :global t 
  :lighter " Pgbrk" 
  (if page-break-mode
      (add-hook 'window-configuration-change-hook 
		'page-break-mode-hook-function )
    (remove-hook 'window-configuration-change-hook 
		 'page-break-mode-hook-function)))

(defun turn-on-page-break-mode ()
  (page-break-mode 1))

(defun turn-off-page-break-mode ()
  (page-break-mode -1))

(turn-on-page-break-mode)

TinyTools also contains a PageMode. – MarkusKnittig


CategoryDisplay