Mercurial > emacs
annotate lisp/ehelp.el @ 11161:3e309e3f0ad5
(Fx_store_cut_buffer_internal): Use the flag in the
frame's x_display_info, not a global flag.
(Fx_rotate_cut_buffers_internal): Likewise.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Fri, 31 Mar 1995 03:40:01 +0000 |
parents | 45c4759f286e |
children | 4d2a2fe1d8d7 |
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 |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
3 ;; Copyright (C) 1986 Free Software Foundation, Inc. |
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, |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2027
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 | |
72 (defun with-electric-help (thunk &optional buffer noerase) | |
200 | 73 "Arguments are THUNK &optional BUFFER NOERASE. BUFFER defaults to \"*Help*\" |
74 THUNK is a function of no arguments which is called to initialize | |
75 the contents of BUFFER. BUFFER will be erased before THUNK is called unless | |
76 NOERASE is non-nil. THUNK will be called with `standard-output' bound to | |
77 the buffer specified by BUFFER | |
36 | 78 |
79 After THUNK has been called, this function \"electrically\" pops up a window | |
80 in which BUFFER is displayed and allows the user to scroll through that buffer | |
81 in electric-help-mode. | |
200 | 82 When the user exits (with `electric-help-exit', or otherwise) the help |
83 buffer's window disappears (i.e., we use `save-window-excursion') | |
84 BUFFER is put into `default-major-mode' (or `fundamental-mode') when we exit" | |
36 | 85 (setq buffer (get-buffer-create (or buffer "*Help*"))) |
86 (let ((one (one-window-p t)) | |
160 | 87 (config (current-window-configuration)) |
88 (bury nil)) | |
89 (unwind-protect | |
90 (save-excursion | |
91 (if one (goto-char (window-start (selected-window)))) | |
92 (let ((pop-up-windows t)) | |
93 (pop-to-buffer buffer)) | |
94 (save-excursion | |
95 (set-buffer buffer) | |
96 (electric-help-mode) | |
97 (setq buffer-read-only nil) | |
98 (or noerase (erase-buffer))) | |
99 (let ((standard-output buffer)) | |
100 (if (not (funcall thunk)) | |
101 (progn | |
102 (set-buffer buffer) | |
103 (set-buffer-modified-p nil) | |
104 (goto-char (point-min)) | |
105 (if one (shrink-window-if-larger-than-buffer (selected-window)))))) | |
106 (set-buffer buffer) | |
107 (run-hooks 'electric-help-mode-hook) | |
108 (if (eq (car-safe (electric-help-command-loop)) | |
109 'retain) | |
110 (setq config (current-window-configuration)) | |
111 (setq bury t))) | |
112 (message "") | |
113 (set-buffer buffer) | |
114 (setq buffer-read-only nil) | |
115 (condition-case () | |
116 (funcall (or default-major-mode 'fundamental-mode)) | |
117 (error nil)) | |
118 (set-window-configuration config) | |
119 (if bury | |
120 (progn | |
121 ;;>> Perhaps this shouldn't be done. | |
122 ;; so that when we say "Press space to bury" we mean it | |
123 (replace-buffer-in-windows buffer) | |
124 ;; must do this outside of save-window-excursion | |
125 (bury-buffer buffer)))))) | |
36 | 126 |
127 (defun electric-help-command-loop () | |
128 (catch 'exit | |
129 (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
|
130 (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
|
131 (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
|
132 '(?\ )) |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1608
diff
changeset
|
133 (progn (setq unread-command-events nil) |
36 | 134 (throw 'exit t))))) |
135 (let (up down both neither | |
136 (standard (and (eq (key-binding " ") | |
137 'scroll-up) | |
138 (eq (key-binding "\^?") | |
139 'scroll-down) | |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
140 (eq (key-binding "q") |
36 | 141 'electric-help-exit) |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
142 (eq (key-binding "r") |
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
143 'electric-help-retain)))) |
36 | 144 (Electric-command-loop |
145 'exit | |
146 (function (lambda () | |
147 (let ((min (pos-visible-in-window-p (point-min))) | |
148 (max (pos-visible-in-window-p (point-max)))) | |
149 (cond ((and min max) | |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
150 (cond (standard "Press q to exit, r to retain ") |
36 | 151 (neither) |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
152 (t (setq neither (substitute-command-keys "Press \\[electric-help-exit] to exit, \\[electric-help-retain] to retain "))))) |
36 | 153 (min |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
154 (cond (standard "Press SPC to scroll, q to exit, r to retain ") |
36 | 155 (up) |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
156 (t (setq up (substitute-command-keys "Press \\[scroll-up] to scroll, \\[electric-help-exit] to exit, \\[electric-help-retain] to retain "))))) |
36 | 157 (max |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
158 (cond (standard "Press DEL to scroll back, q to exit ") |
36 | 159 (down) |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
160 (t (setq down (substitute-command-keys "Press \\[scroll-down] to scroll back, \\[electric-help-exit] to exit, \\[electric-help-retain] to retain "))))) |
36 | 161 (t |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
162 (cond (standard "Press SPC to scroll, DEL to scroll back, q to exit ") |
36 | 163 (both) |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
164 (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 | 165 t)))) |
166 | |
167 | |
168 | |
169 ;(defun electric-help-scroll-up (arg) | |
170 ; ">>>Doc" | |
171 ; (interactive "P") | |
172 ; (if (and (null arg) (pos-visible-in-window-p (point-max))) | |
173 ; (electric-help-exit) | |
174 ; (scroll-up arg))) | |
175 | |
176 (defun electric-help-exit () | |
177 ">>>Doc" | |
178 (interactive) | |
179 (throw 'exit t)) | |
180 | |
181 (defun electric-help-retain () | |
200 | 182 "Exit `electric-help', retaining the current window/buffer configuration. |
36 | 183 \(The *Help* buffer will not be selected, but \\[switch-to-buffer-other-window] RET |
184 will select it.)" | |
185 (interactive) | |
186 (throw 'exit '(retain))) | |
187 | |
188 | |
189 (defun electric-help-undefined () | |
190 (interactive) | |
191 (error "%s is undefined -- Press %s to exit" | |
192 (mapconcat 'single-key-description (this-command-keys) " ") | |
193 (if (eq (key-binding "Q") 'electric-help-exit) | |
194 "Q" | |
195 (substitute-command-keys "\\[electric-help-exit]")))) | |
196 | |
197 | |
198 ;>>> this needs to be hairified (recursive help, anybody?) | |
199 (defun electric-help-help () | |
200 (interactive) | |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
201 (if (and (eq (key-binding "q") 'electric-help-exit) |
36 | 202 (eq (key-binding " ") 'scroll-up) |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
203 (eq (key-binding "\^?") 'scroll-down) |
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
204 (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
|
205 (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
|
206 (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 | 207 (sit-for 2)) |
208 | |
209 | |
210 (defun electric-helpify (fun) | |
211 (let ((name "*Help*")) | |
212 (if (save-window-excursion | |
213 ;; kludge-o-rama | |
214 (let* ((p (symbol-function 'print-help-return-message)) | |
215 (b (get-buffer name)) | |
216 (m (buffer-modified-p b))) | |
217 (and b (not (get-buffer-window b)) | |
218 (setq b nil)) | |
219 (unwind-protect | |
220 (progn | |
221 (message "%s..." (capitalize (symbol-name fun))) | |
222 ;; with-output-to-temp-buffer marks the buffer as unmodified. | |
223 ;; kludging excessively and relying on that as some sort | |
224 ;; of indication leads to the following abomination... | |
225 ;;>> This would be doable without such icky kludges if either | |
226 ;;>> (a) there were a function to read the interactive | |
227 ;;>> args for a command and return a list of those args. | |
228 ;;>> (To which one would then just apply the command) | |
229 ;;>> (The only problem with this is that interactive-p | |
230 ;;>> would break, but that is such a misfeature in | |
231 ;;>> any case that I don't care) | |
232 ;;>> It is easy to do this for emacs-lisp functions; | |
233 ;;>> the only problem is getting the interactive spec | |
234 ;;>> for subrs | |
235 ;;>> (b) there were a function which returned a | |
236 ;;>> modification-tick for a buffer. One could tell | |
237 ;;>> whether a buffer had changed by whether the | |
238 ;;>> modification-tick were different. | |
239 ;;>> (Presumably there would have to be a way to either | |
240 ;;>> restore the tick to some previous value, or to | |
241 ;;>> suspend updating of the tick in order to allow | |
242 ;;>> things like momentary-string-display) | |
243 (and b | |
244 (save-excursion | |
245 (set-buffer b) | |
246 (set-buffer-modified-p t))) | |
247 (fset 'print-help-return-message 'ignore) | |
248 (call-interactively fun) | |
249 (and (get-buffer name) | |
250 (get-buffer-window (get-buffer name)) | |
251 (or (not b) | |
252 (not (eq b (get-buffer name))) | |
253 (not (buffer-modified-p b))))) | |
254 (fset 'print-help-return-message p) | |
255 (and b (buffer-name b) | |
256 (save-excursion | |
257 (set-buffer b) | |
258 (set-buffer-modified-p m)))))) | |
259 (with-electric-help 'ignore name t)))) | |
260 | |
261 | |
262 (defun electric-describe-key () | |
263 (interactive) | |
264 (electric-helpify 'describe-key)) | |
265 | |
266 (defun electric-describe-mode () | |
267 (interactive) | |
268 (electric-helpify 'describe-mode)) | |
269 | |
270 (defun electric-view-lossage () | |
271 (interactive) | |
272 (electric-helpify 'view-lossage)) | |
273 | |
274 ;(defun electric-help-for-help () | |
275 ; "See help-for-help" | |
276 ; (interactive) | |
277 ; ) | |
278 | |
279 (defun electric-describe-function () | |
280 (interactive) | |
281 (electric-helpify 'describe-function)) | |
282 | |
283 (defun electric-describe-variable () | |
284 (interactive) | |
285 (electric-helpify 'describe-variable)) | |
286 | |
287 (defun electric-describe-bindings () | |
288 (interactive) | |
289 (electric-helpify 'describe-bindings)) | |
290 | |
291 (defun electric-describe-syntax () | |
292 (interactive) | |
293 (electric-helpify 'describe-syntax)) | |
294 | |
295 (defun electric-command-apropos () | |
296 (interactive) | |
297 (electric-helpify 'command-apropos)) | |
298 | |
299 ;(define-key help-map "a" 'electric-command-apropos) | |
300 | |
10740
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
301 (defun electric-apropos () |
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
302 (interactive) |
45c4759f286e
(electric-help-help, electric-help-command-loop):
Richard M. Stallman <rms@gnu.org>
parents:
4479
diff
changeset
|
303 (electric-helpify 'apropos)) |
36 | 304 |
305 | |
306 ;;;; ehelp-map | |
307 | |
308 (defvar ehelp-map ()) | |
309 (if ehelp-map | |
310 nil | |
311 (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
|
312 (substitute-key-definition 'command-apropos 'electric-command-apropos map) |
36 | 313 (substitute-key-definition 'describe-key 'electric-describe-key map) |
314 (substitute-key-definition 'describe-mode 'electric-describe-mode map) | |
315 (substitute-key-definition 'view-lossage 'electric-view-lossage map) | |
316 (substitute-key-definition 'describe-function 'electric-describe-function map) | |
317 (substitute-key-definition 'describe-variable 'electric-describe-variable map) | |
318 (substitute-key-definition 'describe-bindings 'electric-describe-bindings map) | |
319 (substitute-key-definition 'describe-syntax 'electric-describe-syntax map) | |
320 | |
321 (setq ehelp-map map) | |
322 (fset 'ehelp-command map))) | |
323 | |
324 ;; Do (define-key global-map "\C-h" 'ehelp-command) if you want to win | |
584 | 325 |
326 (provide 'ehelp) | |
327 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
328 ;;; ehelp.el ends here |