Mercurial > emacs
annotate lisp/map-ynp.el @ 39074:cb9433671068
(Resources X): Document more attribute* face resources.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 01 Sep 2001 18:00:45 +0000 |
parents | 253f761ad37b |
children | e907858b9aef |
rev | line source |
---|---|
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
31967
diff
changeset
|
1 ;;; map-ynp.el --- general-purpose boolean question-asker |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
580
diff
changeset
|
2 |
31710
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
3 ;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 2000 Free Software Foundation, Inc. |
840
113281b361ec
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
4 |
25278 | 5 ;; Author: Roland McGrath <roland@gnu.org> |
21057 | 6 ;; Maintainer: FSF |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
7 ;; Keywords: lisp, extensions |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
8 |
14169 | 9 ;; This file is part of GNU Emacs. |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
25 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
26 ;;; Commentary: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
27 |
14169 | 28 ;; map-y-or-n-p is a general-purpose question-asking function. |
29 ;; It asks a series of y/n questions (a la y-or-n-p), and decides to | |
19662 | 30 ;; apply an action to each element of a list based on the answer. |
14169 | 31 ;; The nice thing is that you also get some other possible answers |
32 ;; to use, reminiscent of query-replace: ! to answer y to all remaining | |
33 ;; questions; ESC or q to answer n to all remaining questions; . to answer | |
34 ;; y once and then n for the remainder; and you can get help with C-h. | |
304 | 35 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
36 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
37 |
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
|
38 (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
|
39 no-cursor-in-echo-area) |
304 | 40 "Ask a series of boolean questions. |
891 | 41 Takes args PROMPTER ACTOR LIST, and optional args HELP and ACTION-ALIST. |
304 | 42 |
43 LIST is a list of objects, or a function of no arguments to return the next | |
44 object or nil. | |
45 | |
580 | 46 If PROMPTER is a string, the prompt is \(format PROMPTER OBJECT\). If not |
572 | 47 a string, PROMPTER is a function of one arg (an object from LIST), which |
48 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
|
49 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
|
50 on the object without asking the user. |
572 | 51 |
304 | 52 ACTOR is a function of one arg (an object from LIST), |
53 which gets called with each object that the user answers `yes' for. | |
54 | |
55 If HELP is given, it is a list (OBJECT OBJECTS ACTION), | |
56 where OBJECT is a string giving the singular noun for an elt of LIST; | |
57 OBJECTS is the plural noun for elts of LIST, and ACTION is a transitive | |
58 verb describing ACTOR. The default is \(\"object\" \"objects\" \"act on\"\). | |
59 | |
60 At the prompts, the user may enter y, Y, or SPC to act on that object; | |
61 n, N, or DEL to skip that object; ! to act on all following objects; | |
62 ESC or q to exit (skip all following objects); . (period) to act on the | |
63 current object and then exit; or \\[help-command] to get help. | |
64 | |
891 | 65 If ACTION-ALIST is given, it is an alist (KEY FUNCTION HELP) of extra keys |
66 that will be accepted. KEY is a character; FUNCTION is a function of one | |
67 arg (an object from LIST); HELP is a string. When the user hits KEY, | |
68 FUNCTION is called. If it returns non-nil, the object is considered | |
69 \"acted upon\", and the next object from LIST is processed. If it returns | |
70 nil, the prompt is repeated for the same object. | |
71 | |
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
|
72 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
|
73 `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
|
74 |
2081
2b04be5e47e6
(map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
75 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
|
76 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
|
77 are meaningful here. |
2b04be5e47e6
(map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
78 |
304 | 79 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
|
80 (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
|
81 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
|
82 ;; 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
|
83 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
|
84 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
|
85 (next (if (or (and list (symbolp list)) |
474 | 86 (subrp list) |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1616
diff
changeset
|
87 (byte-code-function-p list) |
474 | 88 (and (consp list) |
89 (eq (car list) 'lambda))) | |
90 (function (lambda () | |
91 (setq elt (funcall list)))) | |
92 (function (lambda () | |
93 (if list | |
94 (progn | |
95 (setq elt (car list) | |
96 list (cdr list)) | |
97 t) | |
98 nil)))))) | |
31710
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
99 (if (and (listp last-nonmenu-event) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
100 use-dialog-box) |
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
|
101 ;; Make a list describing a dialog box. |
31710
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
102 (let ((object (if help (capitalize (nth 0 help)))) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
103 (objects (if help (capitalize (nth 1 help)))) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
104 (action (if help (capitalize (nth 2 help))))) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
105 (setq map `(("Yes" . act) ("No" . skip) ("Quit" . exit) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
106 (,(if help (concat action " " object " And Quit") |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
107 "Do it and Quit") . act-and-exit) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
108 (,(if help (concat action " All " objects) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
109 "Do All") . automatic) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
110 ,@(mapcar (lambda (elt) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
111 (cons (capitalize (nth 2 elt)) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
112 (vector (nth 1 elt)))) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
113 action-alist)) |
14818
3349089ced14
(map-y-or-n-p): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
114 use-menus t |
31967
54b09b09e4bd
(map-y-or-n-p): Fix missing backquotes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31710
diff
changeset
|
115 mouse-event last-nonmenu-event)) |
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
|
116 (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
|
117 (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
|
118 (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
|
119 (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
|
120 (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
|
121 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
|
122 " ") |
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 "") |
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 ;; 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
|
125 ;; 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
|
126 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
|
127 (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
|
128 (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
|
129 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
|
130 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
|
131 (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
|
132 (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
|
133 (if (stringp prompter) |
31710
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
134 (setq prompter `(lambda (object) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
135 (format ,prompter object)))) |
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
|
136 (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
|
137 (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
|
138 (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
|
139 ;; 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
|
140 (setq quit-flag nil) |
14818
3349089ced14
(map-y-or-n-p): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
141 (if use-menus |
3349089ced14
(map-y-or-n-p): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
142 (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
|
143 (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
|
144 'quit)) |
bd03a01d7059
(map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents:
11471
diff
changeset
|
145 ;; 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
|
146 (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
|
147 (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
|
148 (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
|
149 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
|
150 (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
|
151 (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
|
152 (raise-frame (window-frame (minibuffer-window)))) |
25963
cc89cf824a72
(map-y-or-n-p): If we read -1, for end of keyboard
Phillip Rulon <pjr@gnu.org>
parents:
25278
diff
changeset
|
153 (while (progn |
cc89cf824a72
(map-y-or-n-p): If we read -1, for end of keyboard
Phillip Rulon <pjr@gnu.org>
parents:
25278
diff
changeset
|
154 (setq char (read-event)) |
cc89cf824a72
(map-y-or-n-p): If we read -1, for end of keyboard
Phillip Rulon <pjr@gnu.org>
parents:
25278
diff
changeset
|
155 ;; If we get -1, from end of keyboard |
cc89cf824a72
(map-y-or-n-p): If we read -1, for end of keyboard
Phillip Rulon <pjr@gnu.org>
parents:
25278
diff
changeset
|
156 ;; macro, try again. |
26099
a1b5109f447a
(map-y-or-n-p): Remove extraneous `not'.
Gerd Moellmann <gerd@gnu.org>
parents:
25963
diff
changeset
|
157 (equal char -1))) |
12130
bd03a01d7059
(map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents:
11471
diff
changeset
|
158 ;; 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
|
159 (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
|
160 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
|
161 (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
|
162 (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
|
163 (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
|
164 (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
|
165 (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
|
166 ((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
|
167 ;; 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
|
168 (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
|
169 (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
|
170 ((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
|
171 ;; 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
|
172 ) |
bd03a01d7059
(map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents:
11471
diff
changeset
|
173 ((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
|
174 ;; 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
|
175 (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
|
176 (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
|
177 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
|
178 ((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
|
179 (setq quit-flag t) |
31710
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
180 (setq next `(lambda () |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
181 (setq next ',next) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
182 ',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
|
183 ((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
|
184 ;; 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
|
185 (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
|
186 (progn |
bd03a01d7059
(map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents:
11471
diff
changeset
|
187 (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
|
188 (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
|
189 (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
|
190 (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
|
191 (progn |
bd03a01d7059
(map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents:
11471
diff
changeset
|
192 (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
|
193 (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
|
194 ((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
|
195 (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
|
196 (princ |
bd03a01d7059
(map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents:
11471
diff
changeset
|
197 (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
|
198 (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
|
199 (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
|
200 (concat |
bd03a01d7059
(map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents:
11471
diff
changeset
|
201 (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
|
202 DEL or `n' to skip the current %s; |
23254
54fc6491e28b
(map-y-or-n-p): Mention RET, `q' in the help text.
Dave Love <fx@gnu.org>
parents:
21057
diff
changeset
|
203 RET or `q' to exit (skip all remaining %s); |
2081
2b04be5e47e6
(map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
204 ! 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
|
205 ESC or `q' to exit;\n" |
23254
54fc6491e28b
(map-y-or-n-p): Mention RET, `q' in the help text.
Dave Love <fx@gnu.org>
parents:
21057
diff
changeset
|
206 action object object objects action |
54fc6491e28b
(map-y-or-n-p): Mention RET, `q' in the help text.
Dave Love <fx@gnu.org>
parents:
21057
diff
changeset
|
207 objects) |
12130
bd03a01d7059
(map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents:
11471
diff
changeset
|
208 (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
|
209 (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
|
210 (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
|
211 (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
|
212 (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
|
213 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
|
214 ";\n") |
bd03a01d7059
(map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents:
11471
diff
changeset
|
215 (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
|
216 (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
|
217 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
|
218 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
|
219 (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
|
220 (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
|
221 (help-mode))) |
2081
2b04be5e47e6
(map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
222 |
31967
54b09b09e4bd
(map-y-or-n-p): Fix missing backquotes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31710
diff
changeset
|
223 (setq next `(lambda () |
31710
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
224 (setq next ',next) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
225 ',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
|
226 ((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
|
227 ;; 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
|
228 (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
|
229 ;; 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
|
230 (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
|
231 ;; Regurgitated; try again. |
31967
54b09b09e4bd
(map-y-or-n-p): Fix missing backquotes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31710
diff
changeset
|
232 (setq next `(lambda () |
31710
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
233 (setq next ',next) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
234 ',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
|
235 ((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
|
236 (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
|
237 ;; 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
|
238 (setq delayed-switch-frame char) |
31967
54b09b09e4bd
(map-y-or-n-p): Fix missing backquotes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31710
diff
changeset
|
239 (setq next `(lambda () |
31710
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
240 (setq next ',next) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
241 ',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
|
242 (t |
bd03a01d7059
(map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents:
11471
diff
changeset
|
243 ;; 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
|
244 (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
|
245 (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
|
246 (beep) |
bd03a01d7059
(map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents:
11471
diff
changeset
|
247 (sit-for 1) |
31967
54b09b09e4bd
(map-y-or-n-p): Fix missing backquotes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31710
diff
changeset
|
248 (setq next `(lambda () |
31710
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
249 (setq next ',next) |
6c1273035214
(map-y-or-n-p): Check use-dialog-box. Don't lose
Dave Love <fx@gnu.org>
parents:
26099
diff
changeset
|
250 ',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
|
251 (prompt |
bd03a01d7059
(map-y-or-n-p): Don't eval return value of prompter function.
Roland McGrath <roland@gnu.org>
parents:
11471
diff
changeset
|
252 (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
|
253 (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
|
254 (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
|
255 (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
|
256 (cons delayed-switch-frame unread-command-events)))) |
304 | 257 ;; 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
|
258 (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
|
259 (message "")) |
304 | 260 ;; Return the number of actions that were taken. |
261 actions)) | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
580
diff
changeset
|
262 |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
580
diff
changeset
|
263 ;;; map-ynp.el ends here |