makesum.el 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ;; Generate key binding summary for Emacs
  2. ;; Copyright (C) 1985 Free Software Foundation, Inc.
  3. ;; This file is part of GNU Emacs.
  4. ;; GNU Emacs is distributed in the hope that it will be useful,
  5. ;; but WITHOUT ANY WARRANTY. No author or distributor
  6. ;; accepts responsibility to anyone for the consequences of using it
  7. ;; or for whether it serves any particular purpose or works at all,
  8. ;; unless he says so in writing. Refer to the GNU Emacs General Public
  9. ;; License for full details.
  10. ;; Everyone is granted permission to copy, modify and redistribute
  11. ;; GNU Emacs, but only under the conditions described in the
  12. ;; GNU Emacs General Public License. A copy of this license is
  13. ;; supposed to have been given to you along with GNU Emacs so you
  14. ;; can know your rights and responsibilities. It should be in a
  15. ;; file named COPYING. Among other things, the copyright notice
  16. ;; and this notice must be preserved on all copies.
  17. (defun make-command-summary ()
  18. "Make a summary of current key bindings in the buffer *Summary*.
  19. Previous contents of that buffer are killed first."
  20. (interactive)
  21. (message "Making command summary...")
  22. ;; This puts a description of bindings in a buffer called *Help*.
  23. (save-window-excursion
  24. (describe-bindings))
  25. (with-output-to-temp-buffer "*Summary*"
  26. (save-excursion
  27. (let ((cur-mode mode-name))
  28. (set-buffer standard-output)
  29. (erase-buffer)
  30. (insert-buffer-substring "*Help*")
  31. (goto-char (point-min))
  32. (delete-region (point) (progn (forward-line 1) (point)))
  33. (while (search-forward " " nil t)
  34. (replace-match " "))
  35. (goto-char (point-min))
  36. (while (search-forward "-@ " nil t)
  37. (replace-match "-SP"))
  38. (goto-char (point-min))
  39. (while (search-forward " .. ~ " nil t)
  40. (replace-match "SP .. ~"))
  41. (goto-char (point-min))
  42. (while (search-forward "C-?" nil t)
  43. (replace-match "DEL"))
  44. (goto-char (point-min))
  45. (while (search-forward "C-i" nil t)
  46. (replace-match "TAB"))
  47. (goto-char (point-min))
  48. (if (re-search-forward "^Local Bindings:" nil t)
  49. (progn
  50. (forward-char -1)
  51. (insert " for " cur-mode " Mode")
  52. (while (search-forward "??\n" nil t)
  53. (delete-region (point)
  54. (progn
  55. (forward-line -1)
  56. (point))))))
  57. (goto-char (point-min))
  58. (insert "Emacs command summary, " (substring (current-time-string) 0 10)
  59. ".\n")
  60. ;; Delete "key binding" and underlining of dashes.
  61. (delete-region (point) (progn (forward-line 2) (point)))
  62. (forward-line 1) ;Skip blank line
  63. (while (not (eobp))
  64. (let ((beg (point)))
  65. (or (re-search-forward "^$" nil t)
  66. (goto-char (point-max)))
  67. (double-column beg (point))
  68. (forward-line 1)))
  69. (goto-char (point-min)))))
  70. (message "Making command summary...done"))
  71. (defun double-column (start end)
  72. (interactive "r")
  73. (let (half cnt
  74. line lines nlines
  75. (from-end (- (point-max) end)))
  76. (setq nlines (count-lines start end))
  77. (if (<= nlines 1)
  78. nil
  79. (setq half (/ (1+ nlines) 2))
  80. (goto-char start)
  81. (save-excursion
  82. (forward-line half)
  83. (while (< half nlines)
  84. (setq half (1+ half))
  85. (setq line (buffer-substring (point) (save-excursion (end-of-line) (point))))
  86. (setq lines (cons line lines))
  87. (delete-region (point) (progn (forward-line 1) (point)))))
  88. (setq lines (nreverse lines))
  89. (while lines
  90. (end-of-line)
  91. (indent-to 41)
  92. (insert (car lines))
  93. (forward-line 1)
  94. (setq lines (cdr lines))))
  95. (goto-char (- (point-max) from-end))))