diff options
| author | Roland McGrath | 1995-06-08 16:48:40 +0000 |
|---|---|---|
| committer | Roland McGrath | 1995-06-08 16:48:40 +0000 |
| commit | 933fb95777b74b05adf973cd3e0ba771cde9bf02 (patch) | |
| tree | 450e9b9f03bc6e101390b0a6f5b28495b85917fe | |
| parent | 52fa3b2fae1cce79d95d79a41942f3bddcd9a6f4 (diff) | |
| download | emacs-933fb95777b74b05adf973cd3e0ba771cde9bf02.tar.gz emacs-933fb95777b74b05adf973cd3e0ba771cde9bf02.zip | |
(map-y-or-n-p): Don't eval return value of prompter function.
| -rw-r--r-- | lisp/map-ynp.el | 217 |
1 files changed, 107 insertions, 110 deletions
diff --git a/lisp/map-ynp.el b/lisp/map-ynp.el index 8194b568e40..61a19a31626 100644 --- a/lisp/map-ynp.el +++ b/lisp/map-ynp.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; map-ynp.el --- General-purpose boolean question-asker. | 1 | ;;; map-ynp.el --- General-purpose boolean question-asker. |
| 2 | 2 | ||
| 3 | ;;; Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc. | 3 | ;;; Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Roland McGrath <roland@gnu.ai.mit.edu> | 5 | ;; Author: Roland McGrath <roland@gnu.ai.mit.edu> |
| 6 | ;; Keywords: lisp, extensions | 6 | ;; Keywords: lisp, extensions |
| @@ -44,9 +44,8 @@ object or nil. | |||
| 44 | If PROMPTER is a string, the prompt is \(format PROMPTER OBJECT\). If not | 44 | If PROMPTER is a string, the prompt is \(format PROMPTER OBJECT\). If not |
| 45 | a string, PROMPTER is a function of one arg (an object from LIST), which | 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 | 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 | 47 | value is not a string, it may be nil to ignore the object or non-nil to act |
| 48 | ignore the object, t to act on the object without asking the user, or a | 48 | on the object without asking the user. |
| 49 | form to do a more complex prompt. | ||
| 50 | 49 | ||
| 51 | ACTOR is a function of one arg (an object from LIST), | 50 | ACTOR is a function of one arg (an object from LIST), |
| 52 | which gets called with each object that the user answers `yes' for. | 51 | which gets called with each object that the user answers `yes' for. |
| @@ -130,116 +129,114 @@ Returns the number of actions taken." | |||
| 130 | (format (, prompter) object))))) | 129 | (format (, prompter) object))))) |
| 131 | (while (funcall next) | 130 | (while (funcall next) |
| 132 | (setq prompt (funcall prompter elt)) | 131 | (setq prompt (funcall prompter elt)) |
| 133 | (if (stringp prompt) | 132 | (cond ((stringp prompt) |
| 134 | (progn | 133 | ;; Prompt the user about this object. |
| 135 | (setq quit-flag nil) | 134 | (setq quit-flag nil) |
| 136 | ;; Prompt the user about this object. | 135 | (if mouse-event |
| 137 | (if mouse-event | 136 | (setq def (or (x-popup-dialog mouse-event |
| 138 | (setq def (or (x-popup-dialog mouse-event | 137 | (cons prompt map)) |
| 139 | (cons prompt map)) | 138 | 'quit)) |
| 140 | 'quit)) | 139 | ;; Prompt in the echo area. |
| 141 | ;; Prompt in the echo area. | 140 | (let ((cursor-in-echo-area (not no-cursor-in-echo-area)) |
| 142 | (let ((cursor-in-echo-area (not no-cursor-in-echo-area)) | 141 | (message-log-max nil)) |
| 143 | (message-log-max nil)) | 142 | (message "%s(y, n, !, ., q, %sor %s) " |
| 144 | (message "%s(y, n, !, ., q, %sor %s) " | 143 | prompt user-keys |
| 145 | prompt user-keys | 144 | (key-description (vector help-char))) |
| 146 | (key-description (vector help-char))) | 145 | (setq char (read-event)) |
| 147 | (setq char (read-event)) | 146 | ;; Show the answer to the question. |
| 148 | ;; Show the answer to the question. | 147 | (message "%s(y, n, !, ., q, %sor %s) %s" |
| 149 | (message "%s(y, n, !, ., q, %sor %s) %s" | 148 | prompt user-keys |
| 150 | prompt user-keys | 149 | (key-description (vector help-char)) |
| 151 | (key-description (vector help-char)) | 150 | (single-key-description char))) |
| 152 | (single-key-description char))) | 151 | (setq def (lookup-key map (vector char)))) |
| 153 | (setq def (lookup-key map (vector char)))) | 152 | (cond ((eq def 'exit) |
| 154 | (cond ((eq def 'exit) | 153 | (setq next (function (lambda () nil)))) |
| 155 | (setq next (function (lambda () nil)))) | 154 | ((eq def 'act) |
| 156 | ((eq def 'act) | 155 | ;; Act on the object. |
| 157 | ;; Act on the object. | 156 | (funcall actor elt) |
| 158 | (funcall actor elt) | 157 | (setq actions (1+ actions))) |
| 159 | (setq actions (1+ actions))) | 158 | ((eq def 'skip) |
| 160 | ((eq def 'skip) | 159 | ;; Skip the object. |
| 161 | ;; Skip the object. | 160 | ) |
| 162 | ) | 161 | ((eq def 'act-and-exit) |
| 163 | ((eq def 'act-and-exit) | 162 | ;; Act on the object and then exit. |
| 164 | ;; Act on the object and then exit. | 163 | (funcall actor elt) |
| 165 | (funcall actor elt) | 164 | (setq actions (1+ actions) |
| 166 | (setq actions (1+ actions) | 165 | next (function (lambda () nil)))) |
| 167 | next (function (lambda () nil)))) | 166 | ((or (eq def 'quit) (eq def 'exit-prefix)) |
| 168 | ((or (eq def 'quit) (eq def 'exit-prefix)) | 167 | (setq quit-flag t) |
| 169 | (setq quit-flag t) | 168 | (setq next (` (lambda () |
| 170 | (setq next (` (lambda () | 169 | (setq next '(, next)) |
| 171 | (setq next '(, next)) | 170 | '(, elt))))) |
| 172 | '(, elt))))) | 171 | ((eq def 'automatic) |
| 173 | ((eq def 'automatic) | 172 | ;; Act on this and all following objects. |
| 174 | ;; Act on this and all following objects. | 173 | (if (funcall prompter elt) |
| 175 | (if (eval (funcall prompter elt)) | 174 | (progn |
| 176 | (progn | 175 | (funcall actor elt) |
| 177 | (funcall actor elt) | 176 | (setq actions (1+ actions)))) |
| 178 | (setq actions (1+ actions)))) | 177 | (while (funcall next) |
| 179 | (while (funcall next) | 178 | (if (funcall prompter elt) |
| 180 | (if (eval (funcall prompter elt)) | 179 | (progn |
| 181 | (progn | 180 | (funcall actor elt) |
| 182 | (funcall actor elt) | 181 | (setq actions (1+ actions)))))) |
| 183 | (setq actions (1+ actions)))))) | 182 | ((eq def 'help) |
| 184 | ((eq def 'help) | 183 | (with-output-to-temp-buffer "*Help*" |
| 185 | (with-output-to-temp-buffer "*Help*" | 184 | (princ |
| 186 | (princ | 185 | (let ((object (if help (nth 0 help) "object")) |
| 187 | (let ((object (if help (nth 0 help) "object")) | 186 | (objects (if help (nth 1 help) "objects")) |
| 188 | (objects (if help (nth 1 help) "objects")) | 187 | (action (if help (nth 2 help) "act on"))) |
| 189 | (action (if help (nth 2 help) "act on"))) | 188 | (concat |
| 190 | (concat | 189 | (format "Type SPC or `y' to %s the current %s; |
| 191 | (format "Type SPC or `y' to %s the current %s; | ||
| 192 | DEL or `n' to skip the current %s; | 190 | DEL or `n' to skip the current %s; |
| 193 | ! to %s all remaining %s; | 191 | ! to %s all remaining %s; |
| 194 | ESC or `q' to exit;\n" | 192 | ESC or `q' to exit;\n" |
| 195 | action object object action objects) | 193 | action object object action objects) |
| 196 | (mapconcat (function | 194 | (mapconcat (function |
| 197 | (lambda (elt) | 195 | (lambda (elt) |
| 198 | (format "%c to %s" | 196 | (format "%c to %s" |
| 199 | (nth 0 elt) | 197 | (nth 0 elt) |
| 200 | (nth 2 elt)))) | 198 | (nth 2 elt)))) |
| 201 | action-alist | 199 | action-alist |
| 202 | ";\n") | 200 | ";\n") |
| 203 | (if action-alist ";\n") | 201 | (if action-alist ";\n") |
| 204 | (format "or . (period) to %s \ | 202 | (format "or . (period) to %s \ |
| 205 | the current %s and exit." | 203 | the current %s and exit." |
| 206 | action object)))) | 204 | action object)))) |
| 207 | (save-excursion | 205 | (save-excursion |
| 208 | (set-buffer standard-output) | 206 | (set-buffer standard-output) |
| 209 | (help-mode))) | 207 | (help-mode))) |
| 210 | 208 | ||
| 211 | (setq next (` (lambda () | 209 | (setq next (` (lambda () |
| 212 | (setq next '(, next)) | 210 | (setq next '(, next)) |
| 213 | '(, elt))))) | 211 | '(, elt))))) |
| 214 | ((vectorp def) | 212 | ((vectorp def) |
| 215 | ;; A user-defined key. | 213 | ;; A user-defined key. |
| 216 | (if (funcall (aref def 0) elt) ;Call its function. | 214 | (if (funcall (aref def 0) elt) ;Call its function. |
| 217 | ;; The function has eaten this object. | 215 | ;; The function has eaten this object. |
| 218 | (setq actions (1+ actions)) | 216 | (setq actions (1+ actions)) |
| 219 | ;; Regurgitated; try again. | 217 | ;; Regurgitated; try again. |
| 220 | (setq next (` (lambda () | 218 | (setq next (` (lambda () |
| 221 | (setq next '(, next)) | 219 | (setq next '(, next)) |
| 222 | '(, elt)))))) | 220 | '(, elt)))))) |
| 223 | ((and (consp char) | 221 | ((and (consp char) |
| 224 | (eq (car char) 'switch-frame)) | 222 | (eq (car char) 'switch-frame)) |
| 225 | ;; switch-frame event. Put it off until we're done. | 223 | ;; switch-frame event. Put it off until we're done. |
| 226 | (setq delayed-switch-frame char) | 224 | (setq delayed-switch-frame char) |
| 227 | (setq next (` (lambda () | 225 | (setq next (` (lambda () |
| 228 | (setq next '(, next)) | 226 | (setq next '(, next)) |
| 229 | '(, elt))))) | 227 | '(, elt))))) |
| 230 | (t | 228 | (t |
| 231 | ;; Random char. | 229 | ;; Random char. |
| 232 | (message "Type %s for help." | 230 | (message "Type %s for help." |
| 233 | (key-description (vector help-char))) | 231 | (key-description (vector help-char))) |
| 234 | (beep) | 232 | (beep) |
| 235 | (sit-for 1) | 233 | (sit-for 1) |
| 236 | (setq next (` (lambda () | 234 | (setq next (` (lambda () |
| 237 | (setq next '(, next)) | 235 | (setq next '(, next)) |
| 238 | '(, elt))))))) | 236 | '(, elt))))))) |
| 239 | (if (eval prompt) | 237 | (prompt |
| 240 | (progn | 238 | (funcall actor elt) |
| 241 | (funcall actor elt) | 239 | (setq actions (1+ actions)))))) |
| 242 | (setq actions (1+ actions))))))) | ||
| 243 | (if delayed-switch-frame | 240 | (if delayed-switch-frame |
| 244 | (setq unread-command-events | 241 | (setq unread-command-events |
| 245 | (cons delayed-switch-frame unread-command-events)))) | 242 | (cons delayed-switch-frame unread-command-events)))) |