Mercurial > emacs
annotate lisp/emacs-lisp/helper.el @ 789:71d052f72ac1
*** empty log message ***
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Wed, 15 Jul 1992 23:29:10 +0000 |
parents | 08eb386dd0f3 |
children | 4f28bd14272c |
rev | line source |
---|---|
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; helper.el --- utility help package supporting help in electric modes |
36 | 2 |
3 ;; Copyright (C) 1985 Free Software Foundation, Inc. | |
4 ;; Principal author K. Shane Hartman | |
5 | |
6 ;; This file is part of GNU Emacs. | |
7 | |
8 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
9 ;; it under the terms of the GNU General Public License as published by | |
10 ;; the Free Software Foundation; either version 1, or (at your option) | |
11 ;; any later version. | |
12 | |
13 ;; GNU Emacs is distributed in the hope that it will be useful, | |
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 | |
18 ;; You should have received a copy of the GNU General Public License | |
19 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | |
22 | |
584 | 23 ; hey, here's a helping hand. |
36 | 24 |
25 ;; Bind this to a string for <blank> in "... Other keys <blank>". | |
26 ;; Helper-help uses this to construct help string when scrolling. | |
27 ;; Defaults to "return" | |
28 (defvar Helper-return-blurb nil) | |
29 | |
30 ;; Keymap implementation doesn't work too well for non-standard loops. | |
31 ;; But define it anyway for those who can use it. Non-standard loops | |
32 ;; will probably have to use Helper-help. You can't autoload the | |
33 ;; keymap either. | |
34 | |
35 | |
36 (defvar Helper-help-map nil) | |
37 (if Helper-help-map | |
38 nil | |
39 (setq Helper-help-map (make-keymap)) | |
40 ;(fillarray Helper-help-map 'undefined) | |
41 (define-key Helper-help-map "m" 'Helper-describe-mode) | |
42 (define-key Helper-help-map "b" 'Helper-describe-bindings) | |
43 (define-key Helper-help-map "c" 'Helper-describe-key-briefly) | |
44 (define-key Helper-help-map "k" 'Helper-describe-key) | |
45 ;(define-key Helper-help-map "f" 'Helper-describe-function) | |
46 ;(define-key Helper-help-map "v" 'Helper-describe-variable) | |
47 (define-key Helper-help-map "?" 'Helper-help-options) | |
48 (define-key Helper-help-map (char-to-string help-char) 'Helper-help-options) | |
49 (fset 'Helper-help-map Helper-help-map)) | |
50 | |
51 (defun Helper-help-scroller () | |
52 (let ((blurb (or (and (boundp 'Helper-return-blurb) | |
53 Helper-return-blurb) | |
54 "return"))) | |
55 (save-window-excursion | |
56 (goto-char (window-start (selected-window))) | |
57 (if (get-buffer-window "*Help*") | |
58 (pop-to-buffer "*Help*") | |
59 (switch-to-buffer "*Help*")) | |
60 (goto-char (point-min)) | |
61 (let ((continue t) state) | |
62 (while continue | |
63 (setq state (+ (* 2 (if (pos-visible-in-window-p (point-max)) 1 0)) | |
64 (if (pos-visible-in-window-p (point-min)) 1 0))) | |
65 (message | |
66 (nth state | |
67 '("Space forward, Delete back. Other keys %s" | |
68 "Space scrolls forward. Other keys %s" | |
69 "Delete scrolls back. Other keys %s" | |
70 "Type anything to %s")) | |
71 blurb) | |
72 (setq continue (read-char)) | |
73 (cond ((and (memq continue '(?\ ?\C-v)) (< state 2)) | |
74 (scroll-up)) | |
75 ((= continue ?\C-l) | |
76 (recenter)) | |
77 ((and (= continue ?\177) (zerop (% state 2))) | |
78 (scroll-down)) | |
79 (t (setq continue nil)))))))) | |
80 | |
81 (defun Helper-help-options () | |
82 "Describe help options." | |
83 (interactive) | |
84 (message "c (key briefly), m (mode), k (key), b (bindings)") | |
85 ;(message "c (key briefly), m (mode), k (key), v (variable), f (function)") | |
86 (sit-for 4)) | |
87 | |
88 (defun Helper-describe-key-briefly (key) | |
208 | 89 "Briefly describe binding of KEY." |
36 | 90 (interactive "kDescribe key briefly: ") |
91 (describe-key-briefly key) | |
92 (sit-for 4)) | |
93 | |
94 (defun Helper-describe-key (key) | |
208 | 95 "Describe binding of KEY." |
36 | 96 (interactive "kDescribe key: ") |
97 (save-window-excursion (describe-key key)) | |
98 (Helper-help-scroller)) | |
99 | |
100 (defun Helper-describe-function () | |
101 "Describe a function. Name read interactively." | |
102 (interactive) | |
103 (save-window-excursion (call-interactively 'describe-function)) | |
104 (Helper-help-scroller)) | |
105 | |
106 (defun Helper-describe-variable () | |
107 "Describe a variable. Name read interactively." | |
108 (interactive) | |
109 (save-window-excursion (call-interactively 'describe-variable)) | |
110 (Helper-help-scroller)) | |
111 | |
112 (defun Helper-describe-mode () | |
113 "Describe the current mode." | |
114 (interactive) | |
115 (let ((name mode-name) | |
116 (documentation (documentation major-mode))) | |
117 (save-excursion | |
118 (set-buffer (get-buffer-create "*Help*")) | |
119 (erase-buffer) | |
120 (insert name " Mode\n" documentation))) | |
121 (Helper-help-scroller)) | |
122 | |
258 | 123 ;;;###autoload |
36 | 124 (defun Helper-describe-bindings () |
125 "Describe local key bindings of current mode." | |
126 (interactive) | |
127 (message "Making binding list...") | |
128 (save-window-excursion (describe-bindings)) | |
129 (Helper-help-scroller)) | |
130 | |
258 | 131 ;;;###autoload |
36 | 132 (defun Helper-help () |
133 "Provide help for current mode." | |
134 (interactive) | |
135 (let ((continue t) c) | |
136 (while continue | |
137 (message "Help (Type ? for further options)") | |
138 (setq c (char-to-string (downcase (read-char)))) | |
139 (setq c (lookup-key Helper-help-map c)) | |
140 (cond ((eq c 'Helper-help-options) | |
141 (Helper-help-options)) | |
142 ((commandp c) | |
143 (call-interactively c) | |
144 (setq continue nil)) | |
145 (t | |
146 (ding) | |
147 (setq continue nil)))))) | |
148 | |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
149 (provide 'helper) |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
150 |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
151 ;;; helper.el ends here |