annotate lisp/map-ynp.el @ 4843:715b15990d0a

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