annotate lisp/utils/map-ynp.el @ 70:131b0175ea99 r20-0b30

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