annotate lisp/map-ynp.el @ 359:8e84bee8ddd0 r21-1-9

Import from CVS: tag r21-1-9
author cvs
date Mon, 13 Aug 2007 10:57:55 +0200
parents 41ff10fd062f
children 8626e4521993
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1 ;;; map-ynp.el --- General-purpose boolean question-asker.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1991-1995, 1997 Free Software Foundation, Inc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
5 ;; Author: Roland McGrath <roland@gnu.ai.mit.edu>
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
6 ;; Keywords: lisp, extensions, dumped
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
7
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
9
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
13 ;; any later version.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
14
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
18 ;; General Public License for more details.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
19
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
23 ;; 02111-1307, USA.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
24
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
25 ;;; Synched up with: Emacs/Mule zeta.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
26
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
27 ;;; Commentary:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
28
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
29 ;; This file is dumped with XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
30
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
31 ;; map-y-or-n-p is a general-purpose question-asking function.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
32 ;; It asks a series of y/n questions (a la y-or-n-p), and decides to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
33 ;; applies an action to each element of a list based on the answer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
34 ;; The nice thing is that you also get some other possible answers
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
35 ;; to use, reminiscent of query-replace: ! to answer y to all remaining
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
36 ;; questions; ESC or q to answer n to all remaining questions; . to answer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
37 ;; y once and then n for the remainder; and you can get help with C-h.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
38
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
39 ;;; Code:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
40
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
41 (defun map-y-or-n-p (prompter actor list &optional help action-alist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
42 no-cursor-in-echo-area)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
43 "Ask a series of boolean questions.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
44 Takes args PROMPTER ACTOR LIST, and optional args HELP and ACTION-ALIST.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
45
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
46 LIST is a list of objects, or a function of no arguments to return the next
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
47 object or nil.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
48
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
49 If PROMPTER is a string, the prompt is \(format PROMPTER OBJECT\). If not
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
50 a string, PROMPTER is a function of one arg (an object from LIST), which
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
51 returns a string to be used as the prompt for that object. If the return
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
52 value is not a string, it may be nil to ignore the object or non-nil to act
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
53 on the object without asking the user.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
54
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
55 ACTOR is a function of one arg (an object from LIST),
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
56 which gets called with each object that the user answers `yes' for.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58 If HELP is given, it is a list (OBJECT OBJECTS ACTION),
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59 where OBJECT is a string giving the singular noun for an elt of LIST;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60 OBJECTS is the plural noun for elts of LIST, and ACTION is a transitive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 verb describing ACTOR. The default is \(\"object\" \"objects\" \"act on\"\).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63 At the prompts, the user may enter y, Y, or SPC to act on that object;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64 n, N, or DEL to skip that object; ! to act on all following objects;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
65 ESC or q to exit (skip all following objects); . (period) to act on the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66 current object and then exit; or \\[help-command] to get help.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68 If ACTION-ALIST is given, it is an alist (KEY FUNCTION HELP) of extra keys
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69 that will be accepted. KEY is a character; FUNCTION is a function of one
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70 arg (an object from LIST); HELP is a string. When the user hits KEY,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71 FUNCTION is called. If it returns non-nil, the object is considered
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 \"acted upon\", and the next object from LIST is processed. If it returns
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
73 nil, the prompt is repeated for the same object.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
74
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75 Final optional argument NO-CURSOR-IN-ECHO-AREA non-nil says not to set
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76 `cursor-in-echo-area' while prompting.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78 This function uses `query-replace-map' to define the standard responses,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79 but not all of the responses which `query-replace' understands
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80 are meaningful here.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82 Returns the number of actions taken."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83 (let* ((actions 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
84 user-keys mouse-event map prompt char elt def
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
85 ;; Non-nil means we should use mouse menus to ask.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86 ;; use-menus
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87 ;;delayed-switch-frame
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88 (next (if (or (and list (symbolp list))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89 (subrp list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
90 (compiled-function-p list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91 (and (consp list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
92 (eq (car list) 'lambda)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
93 (function (lambda ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
94 (setq elt (funcall list))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95 (function (lambda ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96 (if list
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
97 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
98 (setq elt (car list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
99 list (cdr list))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
100 t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
101 nil))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
102 (if (should-use-dialog-box-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
103 ;; Make a list describing a dialog box.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
104 (let (;; (object (capitalize (or (nth 0 help) "object")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
105 ;; (objects (capitalize (or (nth 1 help) "objects")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
106 ;; (action (capitalize (or (nth 2 help) "act on")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
107 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
108 (setq map `(("Yes" . act) ("No" . skip)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
109 ; bogus crap. --ben
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
110 ; ((, (if help
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
111 ; (capitalize
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
112 ; (or (nth 3 help)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
113 ; (concat action " All " objects)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
114 ; "Do All")) . automatic)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
115 ; ((, (if help
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
116 ; (capitalize
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
117 ; (or (nth 4 help)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
118 ; (concat action " " object " And Quit")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
119 ; "Do it and Quit")) . act-and-exit)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
120 ; ((, (capitalize
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
121 ; (or (and help (nth 5 help)) "Quit")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
122 ; . exit)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
123 ("Yes All" . automatic)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
124 ("No All" . exit)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
125 ("Cancel" . quit)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
126 ,@(mapcar (lambda (elt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
127 (cons (capitalize (nth 2 elt))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
128 (vector (nth 1 elt))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
129 action-alist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
130 mouse-event last-command-event))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
131 (setq user-keys (if action-alist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
132 (concat (mapconcat (function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
133 (lambda (elt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
134 (key-description
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
135 (if (characterp (car elt))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
136 ;; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
137 (char-to-string (car elt))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
138 (car elt)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
139 action-alist ", ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
140 " ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
141 "")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
142 ;; Make a map that defines each user key as a vector containing
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
143 ;; its definition.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
144 ;; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
145 map (let ((foomap (make-sparse-keymap)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
146 (mapcar #'(lambda (elt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
147 (define-key
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
148 foomap
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
149 (if (characterp (car elt))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
150 (char-to-string (car elt))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
151 (car elt))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
152 (vector (nth 1 elt))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
153 action-alist)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
154 (set-keymap-parents foomap (list query-replace-map))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
155 foomap)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
156 (unwind-protect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
157 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
158 (if (stringp prompter)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
159 (setq prompter (` (lambda (object)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
160 (format (, prompter) object)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
161 (while (funcall next)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
162 (setq prompt (funcall prompter elt))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
163 (cond ((stringp prompt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
164 ;; Prompt the user about this object.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
165 (setq quit-flag nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
166 (if mouse-event ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
167 (setq def (or (get-dialog-box-response
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
168 mouse-event
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
169 (cons prompt map))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
170 'quit))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
171 ;; Prompt in the echo area.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
172 (let ((cursor-in-echo-area (not no-cursor-in-echo-area)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
173 (display-message
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
174 'prompt
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
175 (format "%s(y, n, !, ., q, %sor %s) "
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
176 prompt user-keys
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
177 (key-description (vector help-char))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
178 (setq char (next-command-event))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
179 ;; Show the answer to the question.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
180 (display-message
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
181 'prompt
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
182 (format
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
183 "%s(y, n, !, ., q, %sor %s) %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
184 prompt user-keys
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
185 (key-description (vector help-char))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
186 (single-key-description char))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
187 (setq def (lookup-key map (vector char))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
188 (cond ((eq def 'exit)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
189 (setq next (function (lambda () nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
190 ((eq def 'act)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
191 ;; Act on the object.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
192 (funcall actor elt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
193 (setq actions (1+ actions)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
194 ((eq def 'skip)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
195 ;; Skip the object.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
196 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
197 ((eq def 'act-and-exit)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
198 ;; Act on the object and then exit.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
199 (funcall actor elt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
200 (setq actions (1+ actions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
201 next (function (lambda () nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
202 ((or (eq def 'quit) (eq def 'exit-prefix))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
203 (setq quit-flag t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
204 (setq next (` (lambda ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
205 (setq next '(, next))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
206 '(, elt)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
207 ((eq def 'automatic)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
208 ;; Act on this and all following objects.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
209 ;; (if (funcall prompter elt) ; Emacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
210 (if (eval (funcall prompter elt))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
211 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
212 (funcall actor elt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
213 (setq actions (1+ actions))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
214 (while (funcall next)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
215 ;; (funcall prompter elt) ; Emacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
216 (if (eval (funcall prompter elt))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
217 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
218 (funcall actor elt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
219 (setq actions (1+ actions))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
220 ((eq def 'help)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
221 (with-output-to-temp-buffer "*Help*"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
222 (princ
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
223 (let ((object (if help (nth 0 help) "object"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
224 (objects (if help (nth 1 help) "objects"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
225 (action (if help (nth 2 help) "act on")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
226 (concat
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
227 (format "Type SPC or `y' to %s the current %s;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
228 DEL or `n' to skip the current %s;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
229 ! to %s all remaining %s;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
230 ESC or `q' to exit;\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
231 action object object action objects)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
232 (mapconcat (function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
233 (lambda (elt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
234 (format "%c to %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
235 (nth 0 elt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
236 (nth 2 elt))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
237 action-alist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
238 ";\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
239 (if action-alist ";\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
240 (format "or . (period) to %s \
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
241 the current %s and exit."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
242 action object))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
243 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
244 (set-buffer standard-output)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
245 (help-mode)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
246
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
247 (setq next (` (lambda ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
248 (setq next '(, next))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
249 '(, elt)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
250 ((vectorp def)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
251 ;; A user-defined key.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
252 (if (funcall (aref def 0) elt) ;Call its function.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
253 ;; The function has eaten this object.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
254 (setq actions (1+ actions))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
255 ;; Regurgitated; try again.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
256 (setq next (` (lambda ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
257 (setq next '(, next))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
258 '(, elt))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
259 ;((and (consp char) ; Emacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
260 ; (eq (car char) 'switch-frame))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
261 ; ;; switch-frame event. Put it off until we're done.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
262 ; (setq delayed-switch-frame char)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
263 ; (setq next (` (lambda ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
264 ; (setq next '(, next))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
265 ; '(, elt)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
266 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
267 ;; Random char.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
268 (message "Type %s for help."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
269 (key-description (vector help-char)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
270 (beep)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
271 (sit-for 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
272 (setq next (` (lambda ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
273 (setq next '(, next))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
274 '(, elt)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
275 ((eval prompt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
276 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
277 (funcall actor elt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
278 (setq actions (1+ actions)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
279 ;;(if delayed-switch-frame
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
280 ;; (setq unread-command-events
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
281 ;; (cons delayed-switch-frame unread-command-events))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
282 ;; ((eval prompt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
283 ;; (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
284 ;; (funcall actor elt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
285 ;; (setq actions (1+ actions)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
286 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
287 ;; Clear the last prompt from the minibuffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
288 (clear-message 'prompt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
289 ;; Return the number of actions that were taken.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
290 actions))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
291
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
292 ;;; map-ynp.el ends here