annotate lisp/map-ynp.el @ 5582:873d7425c1ad

Change integer to fixnum in a few places where it wasn't possible mechanically. src/ChangeLog addition: 2011-10-09 Aidan Kehoe <kehoea@parhasard.net> Do a couple of non-mechanical things that would otherwise have been included in the last change. * data.c: * data.c (Ftype_of): Return Qfixnum for fixnums, not Qinteger. * lisp.h (MOST_POSITIVE_FIXNUM): Delete an obsolete comment here. man/ChangeLog addition: 2011-10-09 Aidan Kehoe <kehoea@parhasard.net> * internals/internals.texi (Top): * internals/internals.texi (Authorship of XEmacs): * internals/internals.texi (Modules for Other Aspects of the Lisp Interpreter and Object System): * internals/internals.texi (Introduction to Writing C Code): * internals/internals.texi (Working with Lisp Objects): * internals/internals.texi (Adding Global Lisp Variables): * internals/internals.texi (The XEmacs Object System (Abstractly Speaking)): * internals/internals.texi (How Lisp Objects Are Represented in C): * internals/internals.texi (Allocation of Objects in XEmacs Lisp): * internals/internals.texi (Introduction to Allocation): * internals/internals.texi (GCPROing): * internals/internals.texi (mark_object): * internals/internals.texi (sweep_bit_vectors_1): * internals/internals.texi (Fixnums and Characters): * internals/internals.texi (Future Work -- Unicode): Say fixnum rather than integer when specifically talking about fixed-width Lisp integers.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 09 Oct 2011 10:39:09 +0100
parents 308d34e9f07d
children
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
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4783
diff changeset
10 ;; XEmacs is free software: you can redistribute it and/or modify it
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4783
diff changeset
11 ;; under the terms of the GNU General Public License as published by the
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4783
diff changeset
12 ;; Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4783
diff changeset
13 ;; option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4783
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4783
diff changeset
16 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4783
diff changeset
17 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4783
diff changeset
18 ;; for more details.
428
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
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 4783
diff changeset
21 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;;; Synched up with: Emacs/Mule zeta.
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 ;;; Commentary:
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 ;; This file is dumped with XEmacs.
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 ;; map-y-or-n-p is a general-purpose question-asking function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;; 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
31 ;; 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
32 ;; The nice thing is that you also get some other possible answers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;; to use, reminiscent of query-replace: ! to answer y to all remaining
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;; 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
35 ;; 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
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 ;;; Code:
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 (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
40 no-cursor-in-echo-area)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 "Ask a series of boolean questions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 Takes args PROMPTER ACTOR LIST, and optional args HELP and ACTION-ALIST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 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
45 object or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 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
48 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
49 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
50 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
51 on the object without asking the user.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 ACTOR is a function of one arg (an object from LIST),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 which gets called with each object that the user answers `yes' for.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 If HELP is given, it is a list (OBJECT OBJECTS ACTION),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 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
58 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
59 verb describing ACTOR. The default is \(\"object\" \"objects\" \"act on\"\).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 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
62 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
63 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
64 current object and then exit; or \\[help-command] to get help.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 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
67 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
68 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
69 FUNCTION is called. If it returns non-nil, the object is considered
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 \"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
71 nil, the prompt is repeated for the same object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 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
74 `cursor-in-echo-area' while prompting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 This function uses `query-replace-map' to define the standard responses,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 but not all of the responses which `query-replace' understands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 are meaningful here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 Returns the number of actions taken."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 (let* ((actions 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 user-keys mouse-event map prompt char elt def
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 ;; Non-nil means we should use mouse menus to ask.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 ;; use-menus
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 ;;delayed-switch-frame
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 (next (if (or (and list (symbolp list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 (subrp list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 (compiled-function-p list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 (and (consp list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 (eq (car list) 'lambda)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 #'(lambda () (setq elt (funcall list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 #'(lambda ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 (if list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 (setq elt (car list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 list (cdr list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 (if (should-use-dialog-box-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 ;; Make a list describing a dialog box.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 (let (;; (object (capitalize (or (nth 0 help) "object")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 ;; (objects (capitalize (or (nth 1 help) "objects")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 ;; (action (capitalize (or (nth 2 help) "act on")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 )
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
105 (setq map `(("%_Yes" . act) ("%_No" . skip)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 ; bogus crap. --ben
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 ; ((, (if help
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 ; (capitalize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 ; (or (nth 3 help)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 ; (concat action " All " objects)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 ; "Do All")) . automatic)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 ; ((, (if help
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 ; (capitalize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 ; (or (nth 4 help)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 ; (concat action " " object " And Quit")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 ; "Do it and Quit")) . act-and-exit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 ; ((, (capitalize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 ; (or (and help (nth 5 help)) "Quit")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 ; . exit)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
120 ("Yes %_All" . automatic)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
121 ("No A%_ll" . exit)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
122 ("%_Cancel" . quit)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 ,@(mapcar #'(lambda (elt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 (cons (capitalize (nth 2 elt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 (vector (nth 1 elt))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 action-alist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 mouse-event last-command-event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 (setq user-keys (if action-alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 (concat (mapconcat #'(lambda (elt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 (key-description
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 (if (characterp (car elt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 (char-to-string (car elt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 (car elt))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 action-alist ", ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 " ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 ;; Make a map that defines each user key as a vector containing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 ;; its definition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 map (let ((foomap (make-sparse-keymap)))
4783
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4222
diff changeset
142 (mapc #'(lambda (elt)
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4222
diff changeset
143 (define-key
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4222
diff changeset
144 foomap
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4222
diff changeset
145 (if (characterp (car elt))
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4222
diff changeset
146 (char-to-string (car elt))
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4222
diff changeset
147 (car elt))
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4222
diff changeset
148 (vector (nth 1 elt))))
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4222
diff changeset
149 action-alist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 (set-keymap-parents foomap (list query-replace-map))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 foomap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 (if (stringp prompter)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 (setq prompter `(lambda (object)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 (format ,prompter object))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 (while (funcall next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 (setq prompt (funcall prompter elt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 (cond ((stringp prompt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 ;; Prompt the user about this object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 (setq quit-flag nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (if mouse-event ; XEmacs
4222
38ef5a6da799 [xemacs-hg @ 2007-10-13 14:08:26 by aidan]
aidan
parents: 2757
diff changeset
163 (setq def (or (and-fboundp
38ef5a6da799 [xemacs-hg @ 2007-10-13 14:08:26 by aidan]
aidan
parents: 2757
diff changeset
164 #'get-dialog-box-response
38ef5a6da799 [xemacs-hg @ 2007-10-13 14:08:26 by aidan]
aidan
parents: 2757
diff changeset
165 (get-dialog-box-response
38ef5a6da799 [xemacs-hg @ 2007-10-13 14:08:26 by aidan]
aidan
parents: 2757
diff changeset
166 mouse-event
38ef5a6da799 [xemacs-hg @ 2007-10-13 14:08:26 by aidan]
aidan
parents: 2757
diff changeset
167 (cons prompt map)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 'quit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 ;; Prompt in the echo area.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 (let ((cursor-in-echo-area (not no-cursor-in-echo-area)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 (display-message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 'prompt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 (format "%s(y, n, !, ., q, %sor %s) "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 prompt user-keys
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 (key-description (vector help-char))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 (setq char (next-command-event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 ;; Show the answer to the question.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 (display-message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 'prompt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 (format
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 "%s(y, n, !, ., q, %sor %s) %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 prompt user-keys
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 (key-description (vector help-char))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 (single-key-description char))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 (setq def (lookup-key map (vector char))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 (cond ((eq def 'exit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 (setq next #'(lambda () nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 ((eq def 'act)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 ;; Act on the object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 (funcall actor elt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 (setq actions (1+ actions)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 ((eq def 'skip)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 ;; Skip the object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 ((eq def 'act-and-exit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 ;; Act on the object and then exit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 (funcall actor elt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 (setq actions (1+ actions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 next (function (lambda () nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 ((or (eq def 'quit) (eq def 'exit-prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 (setq quit-flag t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 (setq next `(lambda ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (setq next ',next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 ',elt)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 ((eq def 'automatic)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 ;; Act on this and all following objects.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 ;; (if (funcall prompter elt) ; Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 (if (eval (funcall prompter elt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 (funcall actor elt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 (setq actions (1+ actions))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (while (funcall next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 ;; (funcall prompter elt) ; Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 (if (eval (funcall prompter elt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 (funcall actor elt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 (setq actions (1+ actions))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 ((eq def 'help)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 (with-output-to-temp-buffer "*Help*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (princ
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (let ((object (if help (nth 0 help) "object"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 (objects (if help (nth 1 help) "objects"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 (action (if help (nth 2 help) "act on")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 (concat
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 (format "Type SPC or `y' to %s the current %s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 DEL or `n' to skip the current %s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 ! to %s all remaining %s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 ESC or `q' to exit;\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 action object object action objects)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 (mapconcat (function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 (lambda (elt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 (format "%c to %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 (nth 0 elt)
2545
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 442
diff changeset
234 (downcase
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 442
diff changeset
235 (normalize-menu-text
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 442
diff changeset
236 (nth 2 elt))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 action-alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 ";\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (if action-alist ";\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (format "or . (period) to %s \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 the current %s and exit."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 action object))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (set-buffer standard-output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 (help-mode)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (setq next `(lambda ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (setq next ',next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 ',elt)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 ((vectorp def)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 ;; A user-defined key.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (if (funcall (aref def 0) elt) ;Call its function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 ;; The function has eaten this object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 (setq actions (1+ actions))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 ;; Regurgitated; try again.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 (setq next `(lambda ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 (setq next ',next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 ',elt))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 ;((and (consp char) ; Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 ; (eq (car char) 'switch-frame))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 ; ;; switch-frame event. Put it off until we're done.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 ; (setq delayed-switch-frame char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 ; (setq next `(lambda ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 ; (setq next ',next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 ; ',elt)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 ;; Random char.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 (message "Type %s for help."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 (key-description (vector help-char)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 (beep)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 (sit-for 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 (setq next `(lambda ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 (setq next ',next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 ',elt)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 ((eval prompt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 (funcall actor elt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 (setq actions (1+ actions)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 ;;(if delayed-switch-frame
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 ;; (setq unread-command-events
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 ;; (cons delayed-switch-frame unread-command-events))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 ;; ((eval prompt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 ;; (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 ;; (funcall actor elt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 ;; (setq actions (1+ actions)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 ;; Clear the last prompt from the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 (clear-message 'prompt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 ;; Return the number of actions that were taken.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 actions))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 ;;; map-ynp.el ends here