Update Functions chapter of Lisp manual; document closures.
[emacs.git] / lisp / makesum.el
blobf19cb4f5a3184497a9b3d2eb53ecb292e062d8be
1 ;;; makesum.el --- generate key binding summary for Emacs
3 ;; Copyright (C) 1985, 2001-2012 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
6 ;; Keywords: help
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; Displays a nice human-readable summary of all keybindings in a
26 ;; two-column format.
28 ;;; Code:
30 ;;;###autoload
31 (defun make-command-summary ()
32 "Make a summary of current key bindings in the buffer *Summary*.
33 Previous contents of that buffer are killed first."
34 (interactive)
35 (message "Making command summary...")
36 ;; This puts a description of bindings in a buffer called *Help*.
37 (save-window-excursion
38 (describe-bindings))
39 (with-output-to-temp-buffer "*Summary*"
40 (save-excursion
41 (let ((cur-mode mode-name))
42 (set-buffer standard-output)
43 (erase-buffer)
44 (insert-buffer-substring "*Help*")
45 (goto-char (point-min))
46 (delete-region (point) (progn (forward-line 1) (point)))
47 (while (search-forward " " nil t)
48 (replace-match " "))
49 (goto-char (point-min))
50 (while (search-forward "-@ " nil t)
51 (replace-match "-SP"))
52 (goto-char (point-min))
53 (while (search-forward " .. ~ " nil t)
54 (replace-match "SP .. ~"))
55 (goto-char (point-min))
56 (while (search-forward "C-?" nil t)
57 (replace-match "DEL"))
58 (goto-char (point-min))
59 (while (search-forward "C-i" nil t)
60 (replace-match "TAB"))
61 (goto-char (point-min))
62 (if (re-search-forward "^Local Bindings:" nil t)
63 (progn
64 (forward-char -1)
65 (insert " for " (format-mode-line cur-mode) " Mode")
66 (while (search-forward "??\n" nil t)
67 (delete-region (point)
68 (progn
69 (forward-line -1)
70 (point))))))
71 (goto-char (point-min))
72 (insert "Emacs command summary, " (substring (current-time-string) 0 10)
73 ".\n")
74 ;; Delete "key binding" and underlining of dashes.
75 (delete-region (point) (progn (forward-line 2) (point)))
76 (forward-line 1) ;Skip blank line
77 (while (not (eobp))
78 (let ((beg (point)))
79 (or (re-search-forward "^$" nil t)
80 (goto-char (point-max)))
81 (double-column beg (point))
82 (forward-line 1)))
83 (goto-char (point-min)))))
84 (message "Making command summary...done"))
86 (defun double-column (start end)
87 (interactive "r")
88 (let (half line lines nlines
89 (from-end (- (point-max) end)))
90 (setq nlines (count-lines start end))
91 (if (<= nlines 1)
92 nil
93 (setq half (/ (1+ nlines) 2))
94 (goto-char start)
95 (save-excursion
96 (forward-line half)
97 (while (< half nlines)
98 (setq half (1+ half))
99 (setq line (buffer-substring (point) (line-end-position)))
100 (setq lines (cons line lines))
101 (delete-region (point) (progn (forward-line 1) (point)))))
102 (setq lines (nreverse lines))
103 (while lines
104 (end-of-line)
105 (indent-to 41)
106 (insert (car lines))
107 (forward-line 1)
108 (setq lines (cdr lines))))
109 (goto-char (- (point-max) from-end))))
111 (provide 'makesum)
113 ;;; makesum.el ends here