annotate lisp/map-ynp.el @ 3301:aaf396661221

(wait_for_termination): Add POSIX_SIGNALS alternative.
author Richard M. Stallman <rms@gnu.org>
date Sun, 30 May 1993 18:34:54 +0000
parents b88e105bdbf7
children cb593618786e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 580
diff changeset
1 ;;; map-ynp.el --- General-purpose boolean question-asker.
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 580
diff changeset
2
840
113281b361ec *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
3 ;;; Copyright (C) 1991, 1992 Free Software Foundation, Inc.
113281b361ec *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
4
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
5 ;; Author: Roland McGrath <roland@gnu.ai.mit.edu>
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
6 ;; Keywords: lisp, extensions
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
7
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
8 ;;; This program is free software; you can redistribute it and/or modify
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
9 ;;; it under the terms of the GNU General Public License as published by
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
10 ;;; the Free Software Foundation; either version 2, or (at your option)
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
11 ;;; any later version.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
12 ;;;
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
13 ;;; This program is distributed in the hope that it will be useful,
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
14 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
16 ;;; GNU General Public License for more details.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
17 ;;;
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
18 ;;; A copy of the GNU General Public License can be obtained from this
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
19 ;;; program's author (send electronic mail to roland@ai.mit.edu) or from
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
20 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
21 ;;; 02139, USA.
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
22
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
23 ;;; Commentary:
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
24
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
25 ;;; map-y-or-n-p is a general-purpose question-asking function.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
26 ;;; It asks a series of y/n questions (a la y-or-n-p), and decides to
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
27 ;;; applies an action to each element of a list based on the answer.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
28 ;;; The nice thing is that you also get some other possible answers
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
29 ;;; to use, reminiscent of query-replace: ! to answer y to all remaining
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
30 ;;; questions; ESC or q to answer n to all remaining questions; . to answer
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
31 ;;; y once and then n for the remainder; and you can get help with C-h.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
32
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
33 ;;; Code:
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
34
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
35 ;;;###autoload
891
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
36 (defun map-y-or-n-p (prompter actor list &optional help action-alist)
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
37 "Ask a series of boolean questions.
891
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
38 Takes args PROMPTER ACTOR LIST, and optional args HELP and ACTION-ALIST.
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
39
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
40 LIST is a list of objects, or a function of no arguments to return the next
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
41 object or nil.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
42
580
c8860f81ccf7 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 572
diff changeset
43 If PROMPTER is a string, the prompt is \(format PROMPTER OBJECT\). If not
572
0c2e4ee42304 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 474
diff changeset
44 a string, PROMPTER is a function of one arg (an object from LIST), which
0c2e4ee42304 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 474
diff changeset
45 returns a string to be used as the prompt for that object. If the return
0c2e4ee42304 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 474
diff changeset
46 value is not a string, it is eval'd to get the answer; it may be nil to
0c2e4ee42304 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 474
diff changeset
47 ignore the object, t to act on the object without asking the user, or a
0c2e4ee42304 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 474
diff changeset
48 form to do a more complex prompt.
0c2e4ee42304 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 474
diff changeset
49
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
50 ACTOR is a function of one arg (an object from LIST),
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
51 which gets called with each object that the user answers `yes' for.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
52
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
53 If HELP is given, it is a list (OBJECT OBJECTS ACTION),
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
54 where OBJECT is a string giving the singular noun for an elt of LIST;
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
55 OBJECTS is the plural noun for elts of LIST, and ACTION is a transitive
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
56 verb describing ACTOR. The default is \(\"object\" \"objects\" \"act on\"\).
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
57
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
58 At the prompts, the user may enter y, Y, or SPC to act on that object;
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
59 n, N, or DEL to skip that object; ! to act on all following objects;
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
60 ESC or q to exit (skip all following objects); . (period) to act on the
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
61 current object and then exit; or \\[help-command] to get help.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
62
891
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
63 If ACTION-ALIST is given, it is an alist (KEY FUNCTION HELP) of extra keys
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
64 that will be accepted. KEY is a character; FUNCTION is a function of one
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
65 arg (an object from LIST); HELP is a string. When the user hits KEY,
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
66 FUNCTION is called. If it returns non-nil, the object is considered
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
67 \"acted upon\", and the next object from LIST is processed. If it returns
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
68 nil, the prompt is repeated for the same object.
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
69
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
70 This function uses `query-replace-map' to define the standard responses,
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
71 but not all of the responses which `query-replace' understands
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
72 are meaningful here.
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
73
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
74 Returns the number of actions taken."
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
75 (let* ((user-keys (if action-alist
1235
a9e3ec19b7d7 Use (function ...) around lambdas, so it works in v18.
Roland McGrath <roland@gnu.org>
parents: 911
diff changeset
76 (concat (mapconcat (function
a9e3ec19b7d7 Use (function ...) around lambdas, so it works in v18.
Roland McGrath <roland@gnu.org>
parents: 911
diff changeset
77 (lambda (elt)
a9e3ec19b7d7 Use (function ...) around lambdas, so it works in v18.
Roland McGrath <roland@gnu.org>
parents: 911
diff changeset
78 (key-description
a9e3ec19b7d7 Use (function ...) around lambdas, so it works in v18.
Roland McGrath <roland@gnu.org>
parents: 911
diff changeset
79 (char-to-string (car elt)))))
891
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
80 action-alist ", ")
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
81 " ")
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
82 ""))
2442
f692546797f9 (map-y-or-n-p): Make bindings of user-defined keys be each a vector
Roland McGrath <roland@gnu.org>
parents: 2082
diff changeset
83 ;; Make a map that defines each user key as a vector containing
f692546797f9 (map-y-or-n-p): Make bindings of user-defined keys be each a vector
Roland McGrath <roland@gnu.org>
parents: 2082
diff changeset
84 ;; its definition.
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
85 (map (cons 'keymap
2442
f692546797f9 (map-y-or-n-p): Make bindings of user-defined keys be each a vector
Roland McGrath <roland@gnu.org>
parents: 2082
diff changeset
86 (append (mapcar (lambda (elt)
f692546797f9 (map-y-or-n-p): Make bindings of user-defined keys be each a vector
Roland McGrath <roland@gnu.org>
parents: 2082
diff changeset
87 (cons (car elt) (vector (nth 1 elt))))
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
88 action-alist)
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
89 query-replace-map)))
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
90 (actions 0)
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
91 prompt char elt tail def
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
92 (next (if (or (symbolp list)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
93 (subrp list)
1821
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1616
diff changeset
94 (byte-code-function-p list)
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
95 (and (consp list)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
96 (eq (car list) 'lambda)))
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
97 (function (lambda ()
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
98 (setq elt (funcall list))))
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
99 (function (lambda ()
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
100 (if list
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
101 (progn
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
102 (setq elt (car list)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
103 list (cdr list))
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
104 t)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
105 nil))))))
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
106
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
107 (if (stringp prompter)
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
108 (setq prompter (` (lambda (object)
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
109 (format (, prompter) object)))))
415
ba116e58de49 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 408
diff changeset
110 (while (funcall next)
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
111 (setq prompt (funcall prompter elt))
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
112 (if (stringp prompt)
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
113 (progn
2082
4b05402f3ac5 (map-y-or-n-p): Handle `quit' as answer.
Richard M. Stallman <rms@gnu.org>
parents: 2081
diff changeset
114 (setq quit-flag nil)
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
115 ;; Prompt the user about this object.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
116 (let ((cursor-in-echo-area t))
909
4c6cdb66c74c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 891
diff changeset
117 (message "%s(y, n, !, ., q, %sor %s) "
891
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
118 prompt user-keys
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
119 (key-description (char-to-string help-char)))
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
120 (setq char (read-event)))
2793
b88e105bdbf7 (map-y-or-n-p): Show the answers in the echo area.
Richard M. Stallman <rms@gnu.org>
parents: 2442
diff changeset
121 ;; Show the answer to the question.
b88e105bdbf7 (map-y-or-n-p): Show the answers in the echo area.
Richard M. Stallman <rms@gnu.org>
parents: 2442
diff changeset
122 (message "%s(y, n, !, ., q, %sor %s) %s"
b88e105bdbf7 (map-y-or-n-p): Show the answers in the echo area.
Richard M. Stallman <rms@gnu.org>
parents: 2442
diff changeset
123 prompt user-keys
b88e105bdbf7 (map-y-or-n-p): Show the answers in the echo area.
Richard M. Stallman <rms@gnu.org>
parents: 2442
diff changeset
124 (key-description (char-to-string help-char))
b88e105bdbf7 (map-y-or-n-p): Show the answers in the echo area.
Richard M. Stallman <rms@gnu.org>
parents: 2442
diff changeset
125 (single-key-description char))
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
126 (setq def (lookup-key map (vector char)))
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
127 (cond ((eq def 'exit)
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
128 (setq next (function (lambda () nil))))
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
129 ((eq def 'act)
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
130 ;; Act on the object.
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
131 (funcall actor elt)
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
132 (setq actions (1+ actions)))
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
133 ((eq def 'skip)
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
134 ;; Skip the object.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
135 )
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
136 ((eq def 'act-and-exit)
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
137 ;; Act on the object and then exit.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
138 (funcall actor elt)
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
139 (setq actions (1+ actions)
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
140 next (function (lambda () nil))))
2082
4b05402f3ac5 (map-y-or-n-p): Handle `quit' as answer.
Richard M. Stallman <rms@gnu.org>
parents: 2081
diff changeset
141 ((eq def 'quit)
4b05402f3ac5 (map-y-or-n-p): Handle `quit' as answer.
Richard M. Stallman <rms@gnu.org>
parents: 2081
diff changeset
142 (setq quit-flag t)
4b05402f3ac5 (map-y-or-n-p): Handle `quit' as answer.
Richard M. Stallman <rms@gnu.org>
parents: 2081
diff changeset
143 (setq next (` (lambda ()
4b05402f3ac5 (map-y-or-n-p): Handle `quit' as answer.
Richard M. Stallman <rms@gnu.org>
parents: 2081
diff changeset
144 (setq next '(, next))
4b05402f3ac5 (map-y-or-n-p): Handle `quit' as answer.
Richard M. Stallman <rms@gnu.org>
parents: 2081
diff changeset
145 '(, elt)))))
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
146 ((eq def 'automatic)
319
828a35833c4a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 308
diff changeset
147 ;; Act on this and all following objects.
828a35833c4a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 308
diff changeset
148 (if (eval (funcall prompter elt))
828a35833c4a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 308
diff changeset
149 (progn
828a35833c4a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 308
diff changeset
150 (funcall actor elt)
828a35833c4a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 308
diff changeset
151 (setq actions (1+ actions))))
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
152 (while (funcall next)
319
828a35833c4a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 308
diff changeset
153 (if (eval (funcall prompter elt))
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
154 (progn
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
155 (funcall actor elt)
308
71090e169ac8 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 304
diff changeset
156 (setq actions (1+ actions))))))
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
157 ((eq def 'help)
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
158 (with-output-to-temp-buffer "*Help*"
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
159 (princ
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
160 (let ((object (if help (nth 0 help) "object"))
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
161 (objects (if help (nth 1 help) "objects"))
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
162 (action (if help (nth 2 help) "act on")))
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
163 (concat (format "Type SPC or `y' to %s the current %s;
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
164 DEL or `n' to skip the current %s;
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
165 ! to %s all remaining %s;
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
166 ESC or `q' to exit;\n"
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
167 action object object action objects)
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
168 (mapconcat (function
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
169 (lambda (elt)
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
170 (format "%c to %s"
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
171 (nth 0 elt)
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
172 (nth 2 elt))))
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
173 action-alist
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
174 ";\n")
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
175 (if action-alist ";\n")
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
176 (format "or . (period) to %s \
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
177 the current %s and exit."
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
178 action object)))))
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
179
319
828a35833c4a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 308
diff changeset
180 (setq next (` (lambda ()
828a35833c4a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 308
diff changeset
181 (setq next '(, next))
828a35833c4a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 308
diff changeset
182 '(, elt)))))
2442
f692546797f9 (map-y-or-n-p): Make bindings of user-defined keys be each a vector
Roland McGrath <roland@gnu.org>
parents: 2082
diff changeset
183 ((vectorp def)
891
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
184 ;; A user-defined key.
2442
f692546797f9 (map-y-or-n-p): Make bindings of user-defined keys be each a vector
Roland McGrath <roland@gnu.org>
parents: 2082
diff changeset
185 (if (funcall (aref def 0) elt) ;Call its function.
891
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
186 ;; The function has eaten this object.
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
187 (setq actions (1+ actions))
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
188 ;; Regurgitated; try again.
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
189 (setq next (` (lambda ()
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
190 (setq next '(, next))
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
191 '(, elt))))))
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
192 (t
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
193 ;; Random char.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
194 (message "Type %s for help."
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
195 (key-description (char-to-string help-char)))
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
196 (beep)
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
197 (sit-for 1)
319
828a35833c4a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 308
diff changeset
198 (setq next (` (lambda ()
828a35833c4a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 308
diff changeset
199 (setq next '(, next))
828a35833c4a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 308
diff changeset
200 '(, elt)))))))
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
201 (if (eval prompt)
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
202 (progn
319
828a35833c4a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 308
diff changeset
203 (funcall actor elt)
828a35833c4a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 308
diff changeset
204 (setq actions (1+ actions))))))
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
205 ;; Clear the last prompt from the minibuffer.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
206 (message "")
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
207 ;; Return the number of actions that were taken.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
208 actions))
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 580
diff changeset
209
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 580
diff changeset
210 ;;; map-ynp.el ends here