annotate lisp/help-macro.el @ 219:262b8bb4a523 r20-4b8

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