Mercurial > emacs
annotate lisp/map-ynp.el @ 6445:19bf0e182eda
(make-lucid-menu-keymap): Any row of dashes means blank.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Mon, 21 Mar 1994 00:37:56 +0000 |
parents | 45ab50a1dc55 |
children | 2acd8bf3819a |
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 |
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
|
3 ;;; Copyright (C) 1991, 1992, 1993, 1994 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 |
304 | 8 ;;; This program is free software; you can redistribute it and/or modify |
9 ;;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
10 ;;; the Free Software Foundation; either version 2, or (at your option) |
304 | 11 ;;; any later version. |
12 ;;; | |
13 ;;; This program is distributed in the hope that it will be useful, | |
14 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;;; GNU General Public License for more details. | |
17 ;;; | |
18 ;;; A copy of the GNU General Public License can be obtained from this | |
19 ;;; program's author (send electronic mail to roland@ai.mit.edu) or from | |
20 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA | |
21 ;;; 02139, USA. | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
22 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
23 ;;; Commentary: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
24 |
304 | 25 ;;; map-y-or-n-p is a general-purpose question-asking function. |
26 ;;; It asks a series of y/n questions (a la y-or-n-p), and decides to | |
27 ;;; applies an action to each element of a list based on the answer. | |
28 ;;; The nice thing is that you also get some other possible answers | |
29 ;;; to use, reminiscent of query-replace: ! to answer y to all remaining | |
30 ;;; questions; ESC or q to answer n to all remaining questions; . to answer | |
31 ;;; y once and then n for the remainder; and you can get help with C-h. | |
32 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
33 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
34 |
304 | 35 ;;;###autoload |
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
|
36 (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
|
37 no-cursor-in-echo-area) |
304 | 38 "Ask a series of boolean questions. |
891 | 39 Takes args PROMPTER ACTOR LIST, and optional args HELP and ACTION-ALIST. |
304 | 40 |
41 LIST is a list of objects, or a function of no arguments to return the next | |
42 object or nil. | |
43 | |
580 | 44 If PROMPTER is a string, the prompt is \(format PROMPTER OBJECT\). If not |
572 | 45 a string, PROMPTER is a function of one arg (an object from LIST), which |
46 returns a string to be used as the prompt for that object. If the return | |
47 value is not a string, it is eval'd to get the answer; it may be nil to | |
48 ignore the object, t to act on the object without asking the user, or a | |
49 form to do a more complex prompt. | |
50 | |
304 | 51 ACTOR is a function of one arg (an object from LIST), |
52 which gets called with each object that the user answers `yes' for. | |
53 | |
54 If HELP is given, it is a list (OBJECT OBJECTS ACTION), | |
55 where OBJECT is a string giving the singular noun for an elt of LIST; | |
56 OBJECTS is the plural noun for elts of LIST, and ACTION is a transitive | |
57 verb describing ACTOR. The default is \(\"object\" \"objects\" \"act on\"\). | |
58 | |
59 At the prompts, the user may enter y, Y, or SPC to act on that object; | |
60 n, N, or DEL to skip that object; ! to act on all following objects; | |
61 ESC or q to exit (skip all following objects); . (period) to act on the | |
62 current object and then exit; or \\[help-command] to get help. | |
63 | |
891 | 64 If ACTION-ALIST is given, it is an alist (KEY FUNCTION HELP) of extra keys |
65 that will be accepted. KEY is a character; FUNCTION is a function of one | |
66 arg (an object from LIST); HELP is a string. When the user hits KEY, | |
67 FUNCTION is called. If it returns non-nil, the object is considered | |
68 \"acted upon\", and the next object from LIST is processed. If it returns | |
69 nil, the prompt is repeated for the same object. | |
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 | 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 |
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 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
|
82 (next (if (or (and list (symbolp list)) |
474 | 83 (subrp list) |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1616
diff
changeset
|
84 (byte-code-function-p list) |
474 | 85 (and (consp list) |
86 (eq (car list) 'lambda))) | |
87 (function (lambda () | |
88 (setq elt (funcall list)))) | |
89 (function (lambda () | |
90 (if list | |
91 (progn | |
92 (setq elt (car list) | |
93 list (cdr list)) | |
94 t) | |
95 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
|
96 (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
|
97 ;; 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
|
98 (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
|
99 (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
|
100 (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
|
101 (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
|
102 ((, (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
|
103 "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
|
104 ((, (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
|
105 "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
|
106 (,@ (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
|
107 (cons (concat (capitalize (nth 2 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
|
108 " " object) |
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
|
109 (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
|
110 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
|
111 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
|
112 (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
|
113 (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
|
114 (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
|
115 (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
|
116 (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
|
117 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
|
118 " ") |
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 "") |
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 ;; 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
|
121 ;; 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
|
122 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
|
123 (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
|
124 (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
|
125 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
|
126 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
|
127 (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
|
128 (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
|
129 (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
|
130 (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
|
131 (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
|
132 (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
|
133 (setq prompt (funcall prompter elt)) |
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 (if (stringp prompt) |
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 (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
|
136 (setq quit-flag nil) |
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 ;; Prompt the user about this object. |
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
|
138 (if mouse-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
|
139 (setq def (or (x-popup-dialog mouse-event |
6438
45ab50a1dc55
(map-y-or-n-p): Call x-popup-dialog the new way.
Richard M. Stallman <rms@gnu.org>
parents:
6409
diff
changeset
|
140 (cons prompt map)) |
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
|
141 '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
|
142 ;; Prompt in the echo area. |
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
|
143 (let ((cursor-in-echo-area (not no-cursor-in-echo-area))) |
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
|
144 (message "%s(y, n, !, ., q, %sor %s) " |
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
|
145 prompt user-keys |
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
|
146 (key-description (vector help-char))) |
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
|
147 (setq char (read-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
|
148 ;; Show the answer to the question. |
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
|
149 (message "%s(y, n, !, ., q, %sor %s) %s" |
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
|
150 prompt user-keys |
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
|
151 (key-description (vector help-char)) |
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
|
152 (single-key-description char)) |
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
|
153 (setq def (lookup-key map (vector char)))) |
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
|
154 (cond ((eq def 'exit) |
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
|
155 (setq next (function (lambda () nil)))) |
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
|
156 ((eq def 'act) |
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
|
157 ;; Act on the object. |
319 | 158 (funcall actor elt) |
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
|
159 (setq actions (1+ actions))) |
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
|
160 ((eq def 'skip) |
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
|
161 ;; Skip the 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
|
162 ) |
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
|
163 ((eq def 'act-and-exit) |
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
|
164 ;; Act on the object and then exit. |
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
|
165 (funcall actor elt) |
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
|
166 (setq actions (1+ actions) |
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
|
167 next (function (lambda () nil)))) |
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
|
168 ((eq def 'quit) |
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
|
169 (setq quit-flag t) |
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
|
170 (setq next (` (lambda () |
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
|
171 (setq next '(, 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
|
172 '(, elt))))) |
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
|
173 ((eq def 'automatic) |
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
|
174 ;; Act on this and all following objects. |
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
|
175 (if (eval (funcall prompter elt)) |
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
|
176 (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
|
177 (funcall actor elt) |
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
|
178 (setq actions (1+ actions)))) |
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
|
179 (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
|
180 (if (eval (funcall prompter elt)) |
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
|
181 (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
|
182 (funcall actor elt) |
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
|
183 (setq actions (1+ actions)))))) |
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
|
184 ((eq def 'help) |
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
|
185 (with-output-to-temp-buffer "*Help*" |
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
|
186 (princ |
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
|
187 (let ((object (if help (nth 0 help) "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
|
188 (objects (if help (nth 1 help) "objects")) |
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
|
189 (action (if help (nth 2 help) "act on"))) |
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
|
190 (concat |
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
|
191 (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
|
192 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
|
193 ! 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
|
194 ESC or `q' to exit;\n" |
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
|
195 action object object action objects) |
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
|
196 (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
|
197 (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
|
198 (format "%c to %s" |
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
|
199 (nth 0 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
|
200 (nth 2 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
|
201 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
|
202 ";\n") |
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
|
203 (if action-alist ";\n") |
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
|
204 (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
|
205 the current %s and exit." |
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
|
206 action object))))) |
2081
2b04be5e47e6
(map-y-or-n-p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
207 |
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
|
208 (setq next (` (lambda () |
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
|
209 (setq next '(, 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
|
210 '(, elt))))) |
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
|
211 ((vectorp def) |
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
|
212 ;; A user-defined key. |
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
|
213 (if (funcall (aref def 0) elt) ;Call its function. |
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
|
214 ;; The function has eaten this 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
|
215 (setq actions (1+ actions)) |
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
|
216 ;; Regurgitated; try again. |
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
|
217 (setq next (` (lambda () |
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
|
218 (setq next '(, 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
|
219 '(, elt)))))) |
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
|
220 ((and (consp char) |
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
|
221 (eq (car char) '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
|
222 ;; switch-frame event. Put it off until we're done. |
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
|
223 (setq delayed-switch-frame char) |
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
|
224 (setq next (` (lambda () |
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
|
225 (setq next '(, 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
|
226 '(, elt))))) |
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
|
227 (t |
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
|
228 ;; Random char. |
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
|
229 (message "Type %s for help." |
4978
fec7580888dd
(map-y-or-n-p): Handle help-char values other than chars.
Richard M. Stallman <rms@gnu.org>
parents:
4845
diff
changeset
|
230 (key-description (vector help-char))) |
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
|
231 (beep) |
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
|
232 (sit-for 1) |
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
|
233 (setq next (` (lambda () |
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
|
234 (setq next '(, 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
|
235 '(, elt))))))) |
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
|
236 (if (eval prompt) |
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
|
237 (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
|
238 (funcall actor elt) |
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
|
239 (setq actions (1+ actions))))))) |
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
|
240 (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
|
241 (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
|
242 (cons delayed-switch-frame unread-command-events)))) |
304 | 243 ;; Clear the last prompt from the minibuffer. |
244 (message "") | |
245 ;; Return the number of actions that were taken. | |
246 actions)) | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
580
diff
changeset
|
247 |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
580
diff
changeset
|
248 ;;; map-ynp.el ends here |