annotate lisp/utils/map-ynp.el @ 159:3bb7ccffb0c0 r20-3b6

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