Commit | Line | Data |
---|---|---|
6594deb0 ER |
1 | ;;; makesum.el --- generate key binding summary for Emacs |
2 | ||
acaf905b | 3 | ;; Copyright (C) 1985, 2001-2012 Free Software Foundation, Inc. |
9750e079 | 4 | |
84176303 | 5 | ;; Maintainer: FSF |
fd7fa35a | 6 | ;; Keywords: help |
84176303 | 7 | |
a2535589 JA |
8 | ;; This file is part of GNU Emacs. |
9 | ||
eb3fa2cf | 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
a2535589 | 11 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
12 | ;; the Free Software Foundation, either version 3 of the License, or |
13 | ;; (at your option) any later version. | |
a2535589 JA |
14 | |
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. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
a2535589 | 22 | |
e41b2db1 ER |
23 | ;;; Commentary: |
24 | ||
25 | ;; Displays a nice human-readable summary of all keybindings in a | |
26 | ;; two-column format. | |
27 | ||
84176303 | 28 | ;;; Code: |
a2535589 | 29 | |
f9f9507e | 30 | ;;;###autoload |
a2535589 JA |
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) | |
48d33090 | 65 | (insert " for " (format-mode-line cur-mode) " Mode") |
a2535589 JA |
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")) | |
85 | ||
86 | (defun double-column (start end) | |
87 | (interactive "r") | |
06b60517 | 88 | (let (half line lines nlines |
a2535589 JA |
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)) | |
5ed619e0 | 99 | (setq line (buffer-substring (point) (line-end-position))) |
a2535589 JA |
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)))) | |
6594deb0 | 110 | |
896546cd RS |
111 | (provide 'makesum) |
112 | ||
6594deb0 | 113 | ;;; makesum.el ends here |