makesum.el 3.6 KB

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