211
|
1 ;;; help-macro.el --- Makes command line help such as help-for-help
|
|
2
|
|
3 ;; Copyright (C) 1993, 1994, 1997 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Lynn Slater <lrs@indetech.com>
|
|
6 ;; Maintainer: FSF
|
|
7 ;; Created: : Mon Oct 1 11:42:39 1990
|
|
8 ;; Adapted-By: ESR
|
|
9
|
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify
|
|
13 ;; it under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; XEmacs is distributed in the hope that it will be useful,
|
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 ;; GNU General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
25 ;; Boston, MA 02111-1307, USA.
|
|
26
|
|
27 ;;; Commentary:
|
|
28
|
|
29 ;;; Synched up with: FSF 20.2.
|
|
30
|
|
31 ;; This file supplies the macro make-help-screen which constructs
|
|
32 ;; single character dispatching with browsable help such as that provided
|
|
33 ;; by help-for-help. This can be used to make many modes easier to use; for
|
|
34 ;; example, the Gnu Emacs Empire Tool uses this for every "nested" mode map
|
|
35 ;; called from the main mode map.
|
|
36
|
|
37 ;; The name of this package was changed from help-screen.el to
|
|
38 ;; help-macro.el in order to fit in a 14-character limit.
|
|
39
|
|
40 ;;-> *********************** Example of use *********************************
|
|
41
|
|
42 ;;->(make-help-screen help-for-empire-redistribute-map
|
|
43 ;;-> "c:civ m:mil p:population f:food ?"
|
|
44 ;;-> "You have discovered the GEET redistribution commands
|
|
45 ;;-> From here, you can use the following options:
|
|
46 ;;->
|
|
47 ;;->c Redistribute civs from overfull sectors into connected underfull ones
|
|
48 ;;-> The functions typically named by empire-ideal-civ-fcn control
|
|
49 ;;-> based in part on empire-sector-civ-threshold
|
|
50 ;;->m Redistribute military using levels given by empire-ideal-mil-fcn
|
|
51 ;;->p Redistribute excess population to highways for max pop growth
|
|
52 ;;-> Excess is any sector so full babies will not be born.
|
|
53 ;;->f Even out food on highways to highway min and leave levels
|
|
54 ;;-> This is good to pump max food to all warehouses/dist pts
|
|
55 ;;->
|
|
56 ;;->
|
|
57 ;;->Use \\[help-for-empire-redistribute-map] for help on redistribution.
|
|
58 ;;->Use \\[help-for-empire-extract-map] for help on data extraction.
|
|
59 ;;->Please use \\[describe-key] to find out more about any of the other keys."
|
|
60 ;;-> empire-shell-redistribute-map)
|
|
61
|
|
62 ;;-> (define-key c-mp "\C-h" 'help-for-empire-redistribute-map)
|
|
63 ;;-> (define-key c-mp help-character 'help-for-empire-redistribute-map)
|
|
64
|
|
65 ;;; Code:
|
|
66
|
|
67 (provide 'help-macro)
|
|
68
|
|
69 ;;;###autoload
|
|
70 (defcustom three-step-help t
|
|
71 "*Non-nil means give more info about Help command in three steps.
|
|
72 The three steps are simple prompt, prompt with all options,
|
|
73 and window listing and describing the options.
|
|
74 A value of nil means skip the middle step, so that
|
|
75 \\[help-command] \\[help-command] gives the window that lists the options."
|
|
76 :type 'boolean
|
|
77 :group 'help-appearance)
|
|
78
|
|
79 (defmacro make-help-screen (fname help-line help-text helped-map)
|
|
80 "Construct help-menu function name FNAME.
|
|
81 When invoked, FNAME shows HELP-LINE and reads a command using HELPED-MAP.
|
|
82 If the command is the help character, FNAME displays HELP-TEXT
|
|
83 and continues trying to read a command using HELPED-MAP.
|
|
84 When FNAME finally does get a command, it executes that command
|
|
85 and then returns."
|
|
86 `(defun ,fname ()
|
|
87 ,help-text
|
|
88 (interactive)
|
245
|
89 (flet ((help-read-key (prompt)
|
|
90 ;; This is in `flet' to avoid problems with autoloading.
|
|
91 ;; #### The function is ill-conceived -- there should be
|
|
92 ;; a way to do it without all the hassle!
|
|
93 (let (events)
|
|
94 (while (not (key-press-event-p
|
|
95 (aref (setq events (read-key-sequence prompt)) 0)))
|
|
96 ;; Mouse clicks are not part of the help feature, so
|
|
97 ;; reexecute them in the standard environment.
|
|
98 (mapc 'dispatch-event events))
|
|
99 (let ((key (nconc (event-modifiers (aref events 0))
|
|
100 (list (event-key (aref events 0))))))
|
|
101 ;; Make the HELP key translate to C-h.
|
|
102 (when (lookup-key function-key-map key)
|
|
103 (setq key (lookup-key function-key-map key)))
|
|
104 (if (eq (length key) 1)
|
|
105 (car key)
|
|
106 key)))))
|
|
107 (let ((line-prompt
|
|
108 (substitute-command-keys ,help-line)))
|
|
109 (when three-step-help
|
|
110 (message "%s" line-prompt))
|
|
111 (let* ((help-screen (documentation (quote ,fname)))
|
|
112 ;; We bind overriding-local-map for very small
|
|
113 ;; sections, *excluding* where we switch buffers and
|
|
114 ;; where we execute the chosen help command.
|
|
115 (local-map (make-sparse-keymap))
|
|
116 (minor-mode-map-alist nil)
|
|
117 (prev-frame (selected-frame))
|
|
118 config new-frame key)
|
|
119 (unwind-protect
|
|
120 (progn
|
|
121 (set-keymap-parents local-map (list ,helped-map))
|
|
122 (cond (three-step-help
|
|
123 (let* ((overriding-local-map local-map))
|
|
124 (setq key (help-read-key nil))))
|
211
|
125 (t
|
245
|
126 (setq key ??)))
|
|
127 (when (or (equal key ??)
|
|
128 (equal key (list help-char)))
|
|
129 (setq config (current-window-configuration))
|
|
130 (switch-to-buffer-other-window "*Help*")
|
|
131 (and (not (eq (window-frame (selected-window))
|
|
132 prev-frame))
|
|
133 (setq new-frame (window-frame (selected-window))
|
|
134 config nil))
|
|
135 (setq buffer-read-only nil)
|
|
136 (erase-buffer)
|
|
137 (insert help-screen)
|
|
138 (help-mode)
|
|
139 (goto-char (point-min))
|
|
140 (while (member key `((,help-char) ?? (control v) space ?\177
|
|
141 delete backspace (meta v)))
|
|
142 (ignore-errors
|
|
143 (cond ((member key '((control v) space))
|
|
144 (scroll-up))
|
|
145 ((member key '(?\177 delete (meta v) backspace))
|
|
146 (scroll-down))))
|
|
147 (let ((cursor-in-echo-area t)
|
|
148 (overriding-local-map local-map))
|
|
149 (setq key (help-read-key
|
|
150 (format "Type one of the options listed%s: "
|
|
151 (if (pos-visible-in-window-p
|
|
152 (point-max))
|
|
153 "" " or Space to scroll")))))))
|
|
154 ;; We don't need the prompt any more.
|
|
155 (message nil)
|
|
156 (let ((defn (lookup-key local-map key)))
|
|
157 (cond (defn
|
|
158 (when config
|
|
159 (set-window-configuration config)
|
|
160 (setq config nil))
|
|
161 (when new-frame
|
|
162 (iconify-frame new-frame)
|
|
163 (setq new-frame nil))
|
|
164 (call-interactively defn))
|
|
165 (t
|
|
166 (ding)))))
|
|
167 (and (get-buffer "*Help*")
|
|
168 (bury-buffer "*Help*"))
|
|
169 (and new-frame (iconify-frame new-frame))
|
|
170 (and config
|
|
171 (set-window-configuration config))))))))
|
211
|
172
|
|
173 ;;; help-macro.el
|
|
174
|