Mercurial > emacs
annotate lisp/ehelp.el @ 12696:dbbeba770da4
(vip-overriding-map): new variable.
author | Michael Kifer <kifer@cs.stonybrook.edu> |
---|---|
date | Thu, 27 Jul 1995 19:42:29 +0000 |
parents | ca43eab4d2a6 |
children | 363b0c8f817d |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; ehelp.el --- bindings for electric-help mode |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
11234 | 3 ;; Copyright (C) 1986, 1995 Free Software Foundation, Inc. |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
5 ;; Maintainer: FSF |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
6 ;; Keywords: help, extensions |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
7 |
36 | 8 ;; This file is part of GNU Emacs. |
9 | |
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 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
36 | 13 ;; any later version. |
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 | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2027
diff
changeset
|
24 ;;; Commentary: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2027
diff
changeset
|
25 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2027
diff
changeset
|
26 ;; This package provides a pre-packaged `Electric Help Mode' for |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2027
diff
changeset
|
27 ;; browsing on-line help screens. There is one entry point, |
12601
ca43eab4d2a6
(electric-helpify): Autoload with-electric-help, electric-helpify.
Richard M. Stallman <rms@gnu.org>
parents:
11234
diff
changeset
|
28 ;; `with-electric-help'; all you have to give it is a no-argument |
4479 | 29 ;; function that generates the actual text of the help into the current |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2027
diff
changeset
|
30 ;; buffer. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2027
diff
changeset
|
31 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
32 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
33 |
36 | 34 (require 'electric) |
35 (defvar electric-help-map () | |
200 | 36 "Keymap defining commands available in `electric-help-mode'.") |
36 | 37 |
38 (put 'electric-help-undefined 'suppress-keymap t) | |
39 (if electric-help-map | |
40 () | |
41 (let ((map (make-keymap))) | |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
42 ;; allow all non-self-inserting keys - search, scroll, etc |
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
43 (suppress-keymap map) |
36 | 44 (define-key map (char-to-string help-char) 'electric-help-help) |
45 (define-key map "?" 'electric-help-help) | |
46 (define-key map " " 'scroll-up) | |
47 (define-key map "\^?" 'scroll-down) | |
48 (define-key map "." 'beginning-of-buffer) | |
49 (define-key map "<" 'beginning-of-buffer) | |
50 (define-key map ">" 'end-of-buffer) | |
51 ;(define-key map "\C-g" 'electric-help-exit) | |
52 (define-key map "q" 'electric-help-exit) | |
53 (define-key map "Q" 'electric-help-exit) | |
54 ;;a better key than this? | |
55 (define-key map "r" 'electric-help-retain) | |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
56 (define-key map "R" 'electric-help-retain) |
36 | 57 |
58 (setq electric-help-map map))) | |
59 | |
60 (defun electric-help-mode () | |
200 | 61 "`with-electric-help' temporarily places its buffer in this mode. |
62 \(On exit from `with-electric-help', the buffer is put in `default-major-mode'.)" | |
36 | 63 (setq buffer-read-only t) |
64 (setq mode-name "Help") | |
65 (setq major-mode 'help) | |
66 (setq mode-line-buffer-identification '(" Help: %b")) | |
67 (use-local-map electric-help-map) | |
68 ;; this is done below in with-electric-help | |
69 ;(run-hooks 'electric-help-mode-hook) | |
70 ) | |
71 | |
12601
ca43eab4d2a6
(electric-helpify): Autoload with-electric-help, electric-helpify.
Richard M. Stallman <rms@gnu.org>
parents:
11234
diff
changeset
|
72 ;;;###autoload |
36 | 73 (defun with-electric-help (thunk &optional buffer noerase) |
12601
ca43eab4d2a6
(electric-helpify): Autoload with-electric-help, electric-helpify.
Richard M. Stallman <rms@gnu.org>
parents:
11234
diff
changeset
|
74 "Arguments are THUNK &optional BUFFER NOERASE. BUFFER defaults to `*Help*'. |
200 | 75 THUNK is a function of no arguments which is called to initialize |
76 the contents of BUFFER. BUFFER will be erased before THUNK is called unless | |
77 NOERASE is non-nil. THUNK will be called with `standard-output' bound to | |
78 the buffer specified by BUFFER | |
36 | 79 |
80 After THUNK has been called, this function \"electrically\" pops up a window | |
81 in which BUFFER is displayed and allows the user to scroll through that buffer | |
82 in electric-help-mode. | |
200 | 83 When the user exits (with `electric-help-exit', or otherwise) the help |
84 buffer's window disappears (i.e., we use `save-window-excursion') | |
12601
ca43eab4d2a6
(electric-helpify): Autoload with-electric-help, electric-helpify.
Richard M. Stallman <rms@gnu.org>
parents:
11234
diff
changeset
|
85 BUFFER is put into `default-major-mode' (or `fundamental-mode') when we exit." |
36 | 86 (setq buffer (get-buffer-create (or buffer "*Help*"))) |
87 (let ((one (one-window-p t)) | |
160 | 88 (config (current-window-configuration)) |
89 (bury nil)) | |
90 (unwind-protect | |
91 (save-excursion | |
92 (if one (goto-char (window-start (selected-window)))) | |
93 (let ((pop-up-windows t)) | |
94 (pop-to-buffer buffer)) | |
95 (save-excursion | |
96 (set-buffer buffer) | |
97 (electric-help-mode) | |
98 (setq buffer-read-only nil) | |
99 (or noerase (erase-buffer))) | |
100 (let ((standard-output buffer)) | |
101 (if (not (funcall thunk)) | |
102 (progn | |
103 (set-buffer buffer) | |
104 (set-buffer-modified-p nil) | |
105 (goto-char (point-min)) | |
106 (if one (shrink-window-if-larger-than-buffer (selected-window)))))) | |
107 (set-buffer buffer) | |
108 (run-hooks 'electric-help-mode-hook) | |
109 (if (eq (car-safe (electric-help-command-loop)) | |
110 'retain) | |
111 (setq config (current-window-configuration)) | |
112 (setq bury t))) | |
113 (message "") | |
114 (set-buffer buffer) | |
115 (setq buffer-read-only nil) | |
116 (condition-case () | |
117 (funcall (or default-major-mode 'fundamental-mode)) | |
118 (error nil)) | |
119 (set-window-configuration config) | |
120 (if bury | |
121 (progn | |
122 ;;>> Perhaps this shouldn't be done. | |
123 ;; so that when we say "Press space to bury" we mean it | |
124 (replace-buffer-in-windows buffer) | |
125 ;; must do this outside of save-window-excursion | |
126 (bury-buffer buffer)))))) | |
36 | 127 |
128 (defun electric-help-command-loop () | |
129 (catch 'exit | |
130 (if (pos-visible-in-window-p (point-max)) | |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
131 (progn (message (substitute-command-keys "<<< Press Space to bury the help buffer, Press \\[electric-help-retain] to retain it >>>")) |
3440
bccf04c8a5b6
(electric-help-command-loop): Use equal to compare
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
132 (if (equal (setq unread-command-events (list (read-event))) |
bccf04c8a5b6
(electric-help-command-loop): Use equal to compare
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
133 '(?\ )) |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1608
diff
changeset
|
134 (progn (setq unread-command-events nil) |
36 | 135 (throw 'exit t))))) |
136 (let (up down both neither | |
137 (standard (and (eq (key-binding " ") | |
138 'scroll-up) | |
139 (eq (key-binding "\^?") | |
140 'scroll-down) | |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
141 (eq (key-binding "q") |
36 | 142 'electric-help-exit) |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
143 (eq (key-binding "r") |
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
144 'electric-help-retain)))) |
36 | 145 (Electric-command-loop |
146 'exit | |
147 (function (lambda () | |
148 (let ((min (pos-visible-in-window-p (point-min))) | |
149 (max (pos-visible-in-window-p (point-max)))) | |
150 (cond ((and min max) | |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
151 (cond (standard "Press q to exit, r to retain ") |
36 | 152 (neither) |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
153 (t (setq neither (substitute-command-keys "Press \\[electric-help-exit] to exit, \\[electric-help-retain] to retain "))))) |
36 | 154 (min |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
155 (cond (standard "Press SPC to scroll, q to exit, r to retain ") |
36 | 156 (up) |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
157 (t (setq up (substitute-command-keys "Press \\[scroll-up] to scroll, \\[electric-help-exit] to exit, \\[electric-help-retain] to retain "))))) |
36 | 158 (max |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
159 (cond (standard "Press DEL to scroll back, q to exit ") |
36 | 160 (down) |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
161 (t (setq down (substitute-command-keys "Press \\[scroll-down] to scroll back, \\[electric-help-exit] to exit, \\[electric-help-retain] to retain "))))) |
36 | 162 (t |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
163 (cond (standard "Press SPC to scroll, DEL to scroll back, q to exit ") |
36 | 164 (both) |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
165 (t (setq both (substitute-command-keys "Press \\[scroll-up] to scroll, \\[scroll-down] to scroll back, \\[electric-help-exit] to exit, \\[electric-help-retain] to retain "))))))))) |
36 | 166 t)))) |
167 | |
168 | |
169 | |
170 ;(defun electric-help-scroll-up (arg) | |
171 ; ">>>Doc" | |
172 ; (interactive "P") | |
173 ; (if (and (null arg) (pos-visible-in-window-p (point-max))) | |
174 ; (electric-help-exit) | |
175 ; (scroll-up arg))) | |
176 | |
177 (defun electric-help-exit () | |
178 ">>>Doc" | |
179 (interactive) | |
180 (throw 'exit t)) | |
181 | |
182 (defun electric-help-retain () | |
200 | 183 "Exit `electric-help', retaining the current window/buffer configuration. |
36 | 184 \(The *Help* buffer will not be selected, but \\[switch-to-buffer-other-window] RET |
185 will select it.)" | |
186 (interactive) | |
187 (throw 'exit '(retain))) | |
188 | |
189 | |
190 (defun electric-help-undefined () | |
191 (interactive) | |
192 (error "%s is undefined -- Press %s to exit" | |
193 (mapconcat 'single-key-description (this-command-keys) " ") | |
194 (if (eq (key-binding "Q") 'electric-help-exit) | |
195 "Q" | |
196 (substitute-command-keys "\\[electric-help-exit]")))) | |
197 | |
198 | |
199 ;>>> this needs to be hairified (recursive help, anybody?) | |
200 (defun electric-help-help () | |
201 (interactive) | |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
202 (if (and (eq (key-binding "q") 'electric-help-exit) |
36 | 203 (eq (key-binding " ") 'scroll-up) |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
204 (eq (key-binding "\^?") 'scroll-down) |
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
205 (eq (key-binding "r") 'electric-help-retain)) |
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
206 (message "SPC scrolls up, DEL scrolls down, q exits burying help buffer, r exits") |
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
207 (message "%s" (substitute-command-keys "\\[scroll-up] scrolls up, \\[scroll-down] scrolls down, \\[electric-help-exit] exits burying help buffer, \\[electric-help-retain] exits"))) |
36 | 208 (sit-for 2)) |
209 | |
210 | |
12601
ca43eab4d2a6
(electric-helpify): Autoload with-electric-help, electric-helpify.
Richard M. Stallman <rms@gnu.org>
parents:
11234
diff
changeset
|
211 ;;;###autoload |
36 | 212 (defun electric-helpify (fun) |
213 (let ((name "*Help*")) | |
214 (if (save-window-excursion | |
215 ;; kludge-o-rama | |
216 (let* ((p (symbol-function 'print-help-return-message)) | |
217 (b (get-buffer name)) | |
218 (m (buffer-modified-p b))) | |
219 (and b (not (get-buffer-window b)) | |
220 (setq b nil)) | |
221 (unwind-protect | |
222 (progn | |
223 (message "%s..." (capitalize (symbol-name fun))) | |
224 ;; with-output-to-temp-buffer marks the buffer as unmodified. | |
225 ;; kludging excessively and relying on that as some sort | |
226 ;; of indication leads to the following abomination... | |
227 ;;>> This would be doable without such icky kludges if either | |
228 ;;>> (a) there were a function to read the interactive | |
229 ;;>> args for a command and return a list of those args. | |
230 ;;>> (To which one would then just apply the command) | |
231 ;;>> (The only problem with this is that interactive-p | |
232 ;;>> would break, but that is such a misfeature in | |
233 ;;>> any case that I don't care) | |
234 ;;>> It is easy to do this for emacs-lisp functions; | |
235 ;;>> the only problem is getting the interactive spec | |
236 ;;>> for subrs | |
237 ;;>> (b) there were a function which returned a | |
238 ;;>> modification-tick for a buffer. One could tell | |
239 ;;>> whether a buffer had changed by whether the | |
240 ;;>> modification-tick were different. | |
241 ;;>> (Presumably there would have to be a way to either | |
242 ;;>> restore the tick to some previous value, or to | |
243 ;;>> suspend updating of the tick in order to allow | |
244 ;;>> things like momentary-string-display) | |
245 (and b | |
246 (save-excursion | |
247 (set-buffer b) | |
248 (set-buffer-modified-p t))) | |
249 (fset 'print-help-return-message 'ignore) | |
250 (call-interactively fun) | |
251 (and (get-buffer name) | |
252 (get-buffer-window (get-buffer name)) | |
253 (or (not b) | |
254 (not (eq b (get-buffer name))) | |
255 (not (buffer-modified-p b))))) | |
256 (fset 'print-help-return-message p) | |
257 (and b (buffer-name b) | |
258 (save-excursion | |
259 (set-buffer b) | |
260 (set-buffer-modified-p m)))))) | |
261 (with-electric-help 'ignore name t)))) | |
262 | |
263 | |
264 (defun electric-describe-key () | |
265 (interactive) | |
266 (electric-helpify 'describe-key)) | |
267 | |
268 (defun electric-describe-mode () | |
269 (interactive) | |
270 (electric-helpify 'describe-mode)) | |
271 | |
272 (defun electric-view-lossage () | |
273 (interactive) | |
274 (electric-helpify 'view-lossage)) | |
275 | |
276 ;(defun electric-help-for-help () | |
277 ; "See help-for-help" | |
278 ; (interactive) | |
279 ; ) | |
280 | |
281 (defun electric-describe-function () | |
282 (interactive) | |
283 (electric-helpify 'describe-function)) | |
284 | |
285 (defun electric-describe-variable () | |
286 (interactive) | |
287 (electric-helpify 'describe-variable)) | |
288 | |
289 (defun electric-describe-bindings () | |
290 (interactive) | |
291 (electric-helpify 'describe-bindings)) | |
292 | |
293 (defun electric-describe-syntax () | |
294 (interactive) | |
295 (electric-helpify 'describe-syntax)) | |
296 | |
297 (defun electric-command-apropos () | |
298 (interactive) | |
299 (electric-helpify 'command-apropos)) | |
300 | |
301 ;(define-key help-map "a" 'electric-command-apropos) | |
302 | |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
303 (defun electric-apropos () |
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
304 (interactive) |
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
305 (electric-helpify 'apropos)) |
36 | 306 |
307 | |
308 ;;;; ehelp-map | |
309 | |
310 (defvar ehelp-map ()) | |
311 (if ehelp-map | |
312 nil | |
313 (let ((map (copy-keymap help-map))) | |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
314 (substitute-key-definition 'command-apropos 'electric-command-apropos map) |
36 | 315 (substitute-key-definition 'describe-key 'electric-describe-key map) |
316 (substitute-key-definition 'describe-mode 'electric-describe-mode map) | |
317 (substitute-key-definition 'view-lossage 'electric-view-lossage map) | |
318 (substitute-key-definition 'describe-function 'electric-describe-function map) | |
319 (substitute-key-definition 'describe-variable 'electric-describe-variable map) | |
320 (substitute-key-definition 'describe-bindings 'electric-describe-bindings map) | |
321 (substitute-key-definition 'describe-syntax 'electric-describe-syntax map) | |
322 | |
323 (setq ehelp-map map) | |
324 (fset 'ehelp-command map))) | |
325 | |
326 ;; Do (define-key global-map "\C-h" 'ehelp-command) if you want to win | |
584 | 327 |
328 (provide 'ehelp) | |
329 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
330 ;;; ehelp.el ends here |