annotate lisp/map-ynp.el @ 20496:b2536e1685e9

(Fexecute_extended_command): Save message_enable_multibyte and pass it to message2_nolog.
author Richard M. Stallman <rms@gnu.org>
date Sun, 21 Dec 1997 02:19:17 +0000
parents 791a40c16c0b
children 9b9c929675eb
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
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
3 ;; Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
840
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
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
8 ;; This file is part of GNU Emacs.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
9
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
13 ;; any later version.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
14
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
18 ;; GNU General Public License for more details.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
19
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
20 ;; You should have received a copy of the GNU General Public License
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
23 ;; Boston, MA 02111-1307, USA.
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
24
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
25 ;;; Commentary:
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
26
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
27 ;; map-y-or-n-p is a general-purpose question-asking function.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
28 ;; It asks a series of y/n questions (a la y-or-n-p), and decides to
19662
791a40c16c0b Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 16543
diff changeset
29 ;; apply an action to each element of a list based on the answer.
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
30 ;; The nice thing is that you also get some other possible answers
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
31 ;; to use, reminiscent of query-replace: ! to answer y to all remaining
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
32 ;; questions; ESC or q to answer n to all remaining questions; . to answer
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12130
diff changeset
33 ;; y once and then n for the remainder; and you can get help with C-h.
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
34
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
35 ;;; Code:
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
36
4845
6b7954afe2bf (map-y-or-n-p): Take new optional arg to not set cursor-in-echo-area.
Roland McGrath <roland@gnu.org>
parents: 4222
diff changeset
37 (defun map-y-or-n-p (prompter actor list &optional help action-alist
6b7954afe2bf (map-y-or-n-p): Take new optional arg to not set cursor-in-echo-area.
Roland McGrath <roland@gnu.org>
parents: 4222
diff changeset
38 no-cursor-in-echo-area)
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
39 "Ask a series of boolean questions.
891
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
40 Takes args PROMPTER ACTOR LIST, and optional args HELP and ACTION-ALIST.
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
41
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
42 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
43 object or nil.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
44
580
c8860f81ccf7 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 572
diff changeset
45 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
46 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
47 returns a string to be used as the prompt for that object. If the return
12130
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
48 value is not a string, it may be nil to ignore the object or non-nil to act
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
49 on the object without asking the user.
572
0c2e4ee42304 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 474
diff changeset
50
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
51 ACTOR is a function of one arg (an object from LIST),
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
52 which gets called with each object that the user answers `yes' for.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
53
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
54 If HELP is given, it is a list (OBJECT OBJECTS ACTION),
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
55 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
56 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
57 verb describing ACTOR. The default is \(\"object\" \"objects\" \"act on\"\).
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
58
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
59 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
60 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
61 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
62 current object and then exit; or \\[help-command] to get help.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
63
891
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
64 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
65 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
66 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
67 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
68 \"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
69 nil, the prompt is repeated for the same object.
f7de428cb8bf *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 840
diff changeset
70
4845
6b7954afe2bf (map-y-or-n-p): Take new optional arg to not set cursor-in-echo-area.
Roland McGrath <roland@gnu.org>
parents: 4222
diff changeset
71 Final optional argument NO-CURSOR-IN-ECHO-AREA non-nil says not to set
6b7954afe2bf (map-y-or-n-p): Take new optional arg to not set cursor-in-echo-area.
Roland McGrath <roland@gnu.org>
parents: 4222
diff changeset
72 `cursor-in-echo-area' while prompting.
6b7954afe2bf (map-y-or-n-p): Take new optional arg to not set cursor-in-echo-area.
Roland McGrath <roland@gnu.org>
parents: 4222
diff changeset
73
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
74 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
75 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
76 are meaningful here.
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
77
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
78 Returns the number of actions taken."
6409
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
79 (let* ((actions 0)
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
80 user-keys mouse-event map prompt char elt tail def
14818
3349089ced14 (map-y-or-n-p): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
81 ;; Non-nil means we should use mouse menus to ask.
3349089ced14 (map-y-or-n-p): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
82 use-menus
6409
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
83 delayed-switch-frame
4222
6a8d48a6ac10 (map-y-or-n-p): If LIST is nil, just return.
Richard M. Stallman <rms@gnu.org>
parents: 3992
diff changeset
84 (next (if (or (and list (symbolp list))
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
85 (subrp list)
1821
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1616
diff changeset
86 (byte-code-function-p list)
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
87 (and (consp list)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
88 (eq (car list) 'lambda)))
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
89 (function (lambda ()
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
90 (setq elt (funcall list))))
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
91 (function (lambda ()
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
92 (if list
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
93 (progn
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
94 (setq elt (car list)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
95 list (cdr list))
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
96 t)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 415
diff changeset
97 nil))))))
6409
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
98 (if (listp last-nonmenu-event)
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
99 ;; Make a list describing a dialog box.
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
100 (let ((object (capitalize (nth 0 help)))
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
101 (objects (capitalize (nth 1 help)))
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
102 (action (capitalize (nth 2 help))))
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
103 (setq map (` (("Yes" . act) ("No" . skip) ("Quit" . exit)
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
104 ((, (if help (concat action " " object " And Quit")
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
105 "Do it and Quit")) . act-and-exit)
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
106 ((, (if help (concat action " All " objects)
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
107 "Do All")) . automatic)
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
108 (,@ (mapcar (lambda (elt)
6460
2acd8bf3819a (map-y-or-n-p): Don't add any text to the ACTION-ALIST descriptions to make
Roland McGrath <roland@gnu.org>
parents: 6438
diff changeset
109 (cons (capitalize (nth 2 elt))
6409
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
110 (vector (nth 1 elt))))
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
111 action-alist))))
14818
3349089ced14 (map-y-or-n-p): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
112 use-menus t
6409
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
113 mouse-event last-nonmenu-event))
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
114 (setq user-keys (if action-alist
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
115 (concat (mapconcat (function
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
116 (lambda (elt)
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
117 (key-description
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
118 (char-to-string (car elt)))))
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
119 action-alist ", ")
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
120 " ")
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
121 "")
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
122 ;; Make a map that defines each user key as a vector containing
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
123 ;; its definition.
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
124 map (cons 'keymap
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
125 (append (mapcar (lambda (elt)
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
126 (cons (car elt) (vector (nth 1 elt))))
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
127 action-alist)
2f1e5e14dc25 (map-y-or-n-p): Use a dialog box when triggered by a mouse event.
Roland McGrath <roland@gnu.org>
parents: 4978
diff changeset
128 query-replace-map))))
3992
cb593618786e * map-ynp.el (map-y-or-n-p): If we get a switch-frame-event,
Jim Blandy <jimb@redhat.com>
parents: 2793
diff changeset
129 (unwind-protect
cb593618786e * map-ynp.el (map-y-or-n-p): If we get a switch-frame-event,
Jim Blandy <jimb@redhat.com>
parents: 2793
diff changeset
130 (progn
cb593618786e * map-ynp.el (map-y-or-n-p): If we get a switch-frame-event,
Jim Blandy <jimb@redhat.com>
parents: 2793
diff changeset
131 (if (stringp prompter)
cb593618786e * map-ynp.el (map-y-or-n-p): If we get a switch-frame-event,
Jim Blandy <jimb@redhat.com>
parents: 2793
diff changeset
132 (setq prompter (` (lambda (object)
cb593618786e * map-ynp.el (map-y-or-n-p): If we get a switch-frame-event,
Jim Blandy <jimb@redhat.com>
parents: 2793
diff changeset
133 (format (, prompter) object)))))
cb593618786e * map-ynp.el (map-y-or-n-p): If we get a switch-frame-event,
Jim Blandy <jimb@redhat.com>
parents: 2793
diff changeset
134 (while (funcall next)
cb593618786e * map-ynp.el (map-y-or-n-p): If we get a switch-frame-event,
Jim Blandy <jimb@redhat.com>
parents: 2793
diff changeset
135 (setq prompt (funcall prompter elt))
12130
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
136 (cond ((stringp prompt)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
137 ;; Prompt the user about this object.
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
138 (setq quit-flag nil)
14818
3349089ced14 (map-y-or-n-p): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
139 (if use-menus
3349089ced14 (map-y-or-n-p): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
140 (setq def (or (x-popup-dialog (or mouse-event use-menus)
12130
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
141 (cons prompt map))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
142 'quit))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
143 ;; Prompt in the echo area.
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
144 (let ((cursor-in-echo-area (not no-cursor-in-echo-area))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
145 (message-log-max nil))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
146 (message "%s(y, n, !, ., q, %sor %s) "
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
147 prompt user-keys
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
148 (key-description (vector help-char)))
16543
6f891b1ba617 (map-y-or-n-p): Handle minibuffer-auto-raise here.
Richard M. Stallman <rms@gnu.org>
parents: 14818
diff changeset
149 (if minibuffer-auto-raise
6f891b1ba617 (map-y-or-n-p): Handle minibuffer-auto-raise here.
Richard M. Stallman <rms@gnu.org>
parents: 14818
diff changeset
150 (raise-frame (window-frame (minibuffer-window))))
12130
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
151 (setq char (read-event))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
152 ;; Show the answer to the question.
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
153 (message "%s(y, n, !, ., q, %sor %s) %s"
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
154 prompt user-keys
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
155 (key-description (vector help-char))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
156 (single-key-description char)))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
157 (setq def (lookup-key map (vector char))))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
158 (cond ((eq def 'exit)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
159 (setq next (function (lambda () nil))))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
160 ((eq def 'act)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
161 ;; Act on the object.
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
162 (funcall actor elt)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
163 (setq actions (1+ actions)))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
164 ((eq def 'skip)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
165 ;; Skip the object.
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
166 )
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
167 ((eq def 'act-and-exit)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
168 ;; Act on the object and then exit.
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
169 (funcall actor elt)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
170 (setq actions (1+ actions)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
171 next (function (lambda () nil))))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
172 ((or (eq def 'quit) (eq def 'exit-prefix))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
173 (setq quit-flag t)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
174 (setq next (` (lambda ()
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
175 (setq next '(, next))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
176 '(, elt)))))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
177 ((eq def 'automatic)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
178 ;; Act on this and all following objects.
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
179 (if (funcall prompter elt)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
180 (progn
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
181 (funcall actor elt)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
182 (setq actions (1+ actions))))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
183 (while (funcall next)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
184 (if (funcall prompter elt)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
185 (progn
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
186 (funcall actor elt)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
187 (setq actions (1+ actions))))))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
188 ((eq def 'help)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
189 (with-output-to-temp-buffer "*Help*"
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
190 (princ
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
191 (let ((object (if help (nth 0 help) "object"))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
192 (objects (if help (nth 1 help) "objects"))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
193 (action (if help (nth 2 help) "act on")))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
194 (concat
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
195 (format "Type SPC or `y' to %s the current %s;
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
196 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
197 ! 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
198 ESC or `q' to exit;\n"
12130
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
199 action object object action objects)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
200 (mapconcat (function
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
201 (lambda (elt)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
202 (format "%c to %s"
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
203 (nth 0 elt)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
204 (nth 2 elt))))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
205 action-alist
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
206 ";\n")
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
207 (if action-alist ";\n")
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
208 (format "or . (period) to %s \
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
209 the current %s and exit."
12130
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
210 action object))))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
211 (save-excursion
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
212 (set-buffer standard-output)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
213 (help-mode)))
2081
2b04be5e47e6 (map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
214
12130
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
215 (setq next (` (lambda ()
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
216 (setq next '(, next))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
217 '(, elt)))))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
218 ((vectorp def)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
219 ;; A user-defined key.
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
220 (if (funcall (aref def 0) elt) ;Call its function.
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
221 ;; The function has eaten this object.
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
222 (setq actions (1+ actions))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
223 ;; Regurgitated; try again.
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
224 (setq next (` (lambda ()
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
225 (setq next '(, next))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
226 '(, elt))))))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
227 ((and (consp char)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
228 (eq (car char) 'switch-frame))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
229 ;; switch-frame event. Put it off until we're done.
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
230 (setq delayed-switch-frame char)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
231 (setq next (` (lambda ()
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
232 (setq next '(, next))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
233 '(, elt)))))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
234 (t
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
235 ;; Random char.
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
236 (message "Type %s for help."
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
237 (key-description (vector help-char)))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
238 (beep)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
239 (sit-for 1)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
240 (setq next (` (lambda ()
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
241 (setq next '(, next))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
242 '(, elt)))))))
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
243 (prompt
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
244 (funcall actor elt)
bd03a01d7059 (map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents: 11471
diff changeset
245 (setq actions (1+ actions))))))
3992
cb593618786e * map-ynp.el (map-y-or-n-p): If we get a switch-frame-event,
Jim Blandy <jimb@redhat.com>
parents: 2793
diff changeset
246 (if delayed-switch-frame
cb593618786e * map-ynp.el (map-y-or-n-p): If we get a switch-frame-event,
Jim Blandy <jimb@redhat.com>
parents: 2793
diff changeset
247 (setq unread-command-events
cb593618786e * map-ynp.el (map-y-or-n-p): If we get a switch-frame-event,
Jim Blandy <jimb@redhat.com>
parents: 2793
diff changeset
248 (cons delayed-switch-frame unread-command-events))))
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
249 ;; Clear the last prompt from the minibuffer.
11471
019a9e941699 (map-y-or-n-p): Don't log prompt messages.
Karl Heuer <kwzh@gnu.org>
parents: 10058
diff changeset
250 (let ((message-log-max nil))
019a9e941699 (map-y-or-n-p): Don't log prompt messages.
Karl Heuer <kwzh@gnu.org>
parents: 10058
diff changeset
251 (message ""))
304
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
252 ;; Return the number of actions that were taken.
f3dd86b71a52 Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
253 actions))
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 580
diff changeset
254
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 580
diff changeset
255 ;;; map-ynp.el ends here