Download
(if (fboundp 'make-glyph-code)
(defalias 'pp^L-make-glyph-code 'make-glyph-code)
(defun pp^L-make-glyph-code (char &optional face)
"Return a glyph code representing char CHAR with face FACE."
(if face
(logior char (lsh (face-id face) 19))
char)))
(defgroup Pretty-Control-L nil
"Options to define pretty display of Control-l (`^L') characters."
:prefix "pp^L-" :group 'convenience :group 'wp
:link `(url-link :tag "Send Bug Report"
,(concat "mailto:" "drew.adams" "@" "oracle" ".com?subject=pp-c-l.el bug: \
&body=Describe bug here, starting with `emacs -q'. \
Don't forget to mention your Emacs and library versions."))
:link '(url-link :tag "Other Libraries by Drew"
"http://www.emacswiki.org/cgi-bin/wiki/DrewsElispLibraries")
:link '(url-link :tag "Download" "http://www.emacswiki.org/cgi-bin/wiki/pp-c-l.el")
:link '(url-link :tag "Description"
"http://www.emacswiki.org/cgi-bin/wiki/PrettyControlL")
:link '(emacs-commentary-link :tag "Commentary" "pp-c-l"))
(defface pp^L-highlight
(if (> emacs-major-version 21)
'((((type x w32 mac graphic) (class color))
(:box (:line-width 3 :style pressed-button)))
(t (:inverse-video t)))
'((((type x w32 mac graphic) (class color))
(:foreground "Blue" :background "DarkSeaGreen1"))
(t (:inverse-video t))))
"*Face used to highlight `pp^L-^L-vector'."
:group 'Pretty-Control-L :group 'faces)
(defcustom pp^L-^L-string " Section (Printable Page) "
"*Highlighted string displayed in place of each Control-l (^L) character.
If `pp^L-^L-string-function' is non-nil, then the string that function
returns is used instead of `pp^L-^L-string'."
:type 'string :group 'Pretty-Control-L)
(defcustom pp^L-^L-string-function nil
"*Function to produce string displayed in place of a Control-l (^L) char.
The function accepts as argument the window where the ^L is displayed.
If the option value is non-nil, option `pp^L-^L-string' is not used.
You can use this option to have a dynamically defined display string.
For example, this value displays a window-width horizontal line:
(lambda (win) (make-string (1- (window-width win)) ?_))"
:type '(choice (const :tag "None" nil) function) :group 'Pretty-Control-L)
(defcustom pp^L-^L-string-pre (if (> emacs-major-version 21) "\n" "")
"*String displayed just before `pp^L-^L-string'.
This text is not highlighted."
:type 'string :group 'Pretty-Control-L)
(defcustom pp^L-^L-string-post ""
"*String displayed just after `pp^L-^L-string'.
This text is not highlighted."
:type 'string :group 'convenience :group 'wp)
(unless (fboundp 'define-minor-mode)
(defcustom pretty-control-l-mode nil
"*Toggle pretty display of Control-l (`^L') characters.
Setting this variable directly does not take effect;
use either \\[customize] or command `pretty-control-l-mode'."
:set (lambda (symbol value) (pretty-control-l-mode (if value 1 -1)))
:initialize 'custom-initialize-default
:type 'boolean :group 'Pretty-Control-L))
(defun pp^L-^L-display-table-entry (window)
"Returns the display-table entry for Control-l (`^L') char in WINDOW.
A vector determining how a Control-l character is displayed in WINDOW.
Either a vector of characters or nil. The characters are displayed in
place of the Control-l character. nil means `^L' is displayed.
In effect, this concatenates `pp^L-^L-string-pre', `pp^L-^L-string',
and `pp^L-^L-string-post'."
(vconcat (mapconcat (lambda (c) (list c)) pp^L-^L-string-pre "")
(mapcar (lambda (c) (pp^L-make-glyph-code c 'pp^L-highlight))
(if pp^L-^L-string-function
(funcall pp^L-^L-string-function window)
pp^L-^L-string))
(mapconcat (lambda (c) (list c)) pp^L-^L-string-post "")))
(defalias 'pp^l 'pretty-control-l-mode)
(if (fboundp 'define-minor-mode)
(eval '(define-minor-mode pretty-control-l-mode
"Toggle pretty display of Control-l (`^L') characters.
With ARG, turn pretty display of `^L' on if and only if ARG is positive."
:init-value nil :global t :group 'Pretty-Control-L
:link `(url-link :tag "Send Bug Report"
,(concat "mailto:" "drew.adams" "@" "oracle" ".com?subject=\
pp-c-l.el bug: \
&body=Describe bug here, starting with `emacs -q'. \
Don't forget to mention your Emacs and library versions."))
:link '(url-link :tag "Other Libraries by Drew"
"http://www.emacswiki.org/cgi-bin/wiki/DrewsElispLibraries")
:link '(url-link :tag "Download"
"http://www.emacswiki.org/cgi-bin/wiki/pp-c-l.el")
:link '(url-link :tag "Description"
"http://www.emacswiki.org/cgi-bin/wiki/PrettyControlL")
:link '(emacs-commentary-link :tag "Commentary" "pp-c-l")
(if pretty-control-l-mode
(add-hook 'window-configuration-change-hook 'refresh-pretty-control-l)
(remove-hook 'window-configuration-change-hook 'refresh-pretty-control-l))
(walk-windows
(lambda (window)
(let ((display-table (or (window-display-table window)
(make-display-table))))
(aset display-table ?\014 (and pretty-control-l-mode
(pp^L-^L-display-table-entry window)))
(set-window-display-table window display-table)))
'no-minibuf
'visible)))
(defun pretty-control-l-mode (&optional arg)
"Toggle pretty display of Control-l (`^L') characters.
With ARG, turn pretty display of `^L' on if and only if ARG is positive."
(interactive "P")
(setq pretty-control-l-mode
(if arg (> (prefix-numeric-value arg) 0) (not pretty-control-l-mode)))
(if pretty-control-l-mode
(add-hook 'window-configuration-change-hook 'refresh-pretty-control-l)
(remove-hook 'window-configuration-change-hook 'refresh-pretty-control-l))
(walk-windows
(lambda (window)
(let ((display-table (or (window-display-table window) (make-display-table))))
(aset display-table ?\014 (and pretty-control-l-mode
(pp^L-^L-display-table-entry window)))
(set-window-display-table window display-table)))
'no-minibuf
'visible)))
(defun refresh-pretty-control-l ()
"Reinitialize `pretty-control-l-mode', if on, to update the display."
(interactive)
(when pretty-control-l-mode (pretty-control-l-mode t)))
(provide 'pp-c-l)