diff options
| author | Jim Blandy | 1993-07-05 04:50:16 +0000 |
|---|---|---|
| committer | Jim Blandy | 1993-07-05 04:50:16 +0000 |
| commit | 3eea8aa2234f06d7209de642dbfe6238f7e0ef5d (patch) | |
| tree | 33cb79f042ee8014cdf5acb85f9cc7bf387c773e | |
| parent | 15db4e0e34041e0d0191503288cf00d9ba54c6b4 (diff) | |
| download | emacs-3eea8aa2234f06d7209de642dbfe6238f7e0ef5d.tar.gz emacs-3eea8aa2234f06d7209de642dbfe6238f7e0ef5d.zip | |
* map-ynp.el (map-y-or-n-p): If we get a switch-frame-event,
save it until we're done asking questions, and then unread it.
| -rw-r--r-- | lisp/map-ynp.el | 202 |
1 files changed, 107 insertions, 95 deletions
diff --git a/lisp/map-ynp.el b/lisp/map-ynp.el index c64b1c78ae1..28491b5626b 100644 --- a/lisp/map-ynp.el +++ b/lisp/map-ynp.el | |||
| @@ -88,7 +88,7 @@ Returns the number of actions taken." | |||
| 88 | action-alist) | 88 | action-alist) |
| 89 | query-replace-map))) | 89 | query-replace-map))) |
| 90 | (actions 0) | 90 | (actions 0) |
| 91 | prompt char elt tail def | 91 | prompt char elt tail def delayed-switch-frame |
| 92 | (next (if (or (symbolp list) | 92 | (next (if (or (symbolp list) |
| 93 | (subrp list) | 93 | (subrp list) |
| 94 | (byte-code-function-p list) | 94 | (byte-code-function-p list) |
| @@ -103,105 +103,117 @@ Returns the number of actions taken." | |||
| 103 | list (cdr list)) | 103 | list (cdr list)) |
| 104 | t) | 104 | t) |
| 105 | nil)))))) | 105 | nil)))))) |
| 106 | 106 | (unwind-protect | |
| 107 | (if (stringp prompter) | 107 | (progn |
| 108 | (setq prompter (` (lambda (object) | 108 | (if (stringp prompter) |
| 109 | (format (, prompter) object))))) | 109 | (setq prompter (` (lambda (object) |
| 110 | (while (funcall next) | 110 | (format (, prompter) object))))) |
| 111 | (setq prompt (funcall prompter elt)) | 111 | (while (funcall next) |
| 112 | (if (stringp prompt) | 112 | (setq prompt (funcall prompter elt)) |
| 113 | (progn | 113 | (if (stringp prompt) |
| 114 | (setq quit-flag nil) | 114 | (progn |
| 115 | ;; Prompt the user about this object. | 115 | (setq quit-flag nil) |
| 116 | (let ((cursor-in-echo-area t)) | 116 | ;; Prompt the user about this object. |
| 117 | (message "%s(y, n, !, ., q, %sor %s) " | 117 | (let ((cursor-in-echo-area t)) |
| 118 | prompt user-keys | 118 | (message "%s(y, n, !, ., q, %sor %s) " |
| 119 | (key-description (char-to-string help-char))) | 119 | prompt user-keys |
| 120 | (setq char (read-event))) | 120 | (key-description (char-to-string help-char))) |
| 121 | ;; Show the answer to the question. | 121 | (setq char (read-event))) |
| 122 | (message "%s(y, n, !, ., q, %sor %s) %s" | 122 | ;; Show the answer to the question. |
| 123 | prompt user-keys | 123 | (message "%s(y, n, !, ., q, %sor %s) %s" |
| 124 | (key-description (char-to-string help-char)) | 124 | prompt user-keys |
| 125 | (single-key-description char)) | 125 | (key-description (char-to-string help-char)) |
| 126 | (setq def (lookup-key map (vector char))) | 126 | (single-key-description char)) |
| 127 | (cond ((eq def 'exit) | 127 | (setq def (lookup-key map (vector char))) |
| 128 | (setq next (function (lambda () nil)))) | 128 | (cond ((eq def 'exit) |
| 129 | ((eq def 'act) | 129 | (setq next (function (lambda () nil)))) |
| 130 | ;; Act on the object. | 130 | ((eq def 'act) |
| 131 | (funcall actor elt) | 131 | ;; Act on the object. |
| 132 | (setq actions (1+ actions))) | 132 | (funcall actor elt) |
| 133 | ((eq def 'skip) | 133 | (setq actions (1+ actions))) |
| 134 | ;; Skip the object. | 134 | ((eq def 'skip) |
| 135 | ) | 135 | ;; Skip the object. |
| 136 | ((eq def 'act-and-exit) | 136 | ) |
| 137 | ;; Act on the object and then exit. | 137 | ((eq def 'act-and-exit) |
| 138 | (funcall actor elt) | 138 | ;; Act on the object and then exit. |
| 139 | (setq actions (1+ actions) | ||
| 140 | next (function (lambda () nil)))) | ||
| 141 | ((eq def 'quit) | ||
| 142 | (setq quit-flag t) | ||
| 143 | (setq next (` (lambda () | ||
| 144 | (setq next '(, next)) | ||
| 145 | '(, elt))))) | ||
| 146 | ((eq def 'automatic) | ||
| 147 | ;; Act on this and all following objects. | ||
| 148 | (if (eval (funcall prompter elt)) | ||
| 149 | (progn | ||
| 150 | (funcall actor elt) | 139 | (funcall actor elt) |
| 151 | (setq actions (1+ actions)))) | 140 | (setq actions (1+ actions) |
| 152 | (while (funcall next) | 141 | next (function (lambda () nil)))) |
| 153 | (if (eval (funcall prompter elt)) | 142 | ((eq def 'quit) |
| 154 | (progn | 143 | (setq quit-flag t) |
| 155 | (funcall actor elt) | 144 | (setq next (` (lambda () |
| 156 | (setq actions (1+ actions)))))) | 145 | (setq next '(, next)) |
| 157 | ((eq def 'help) | 146 | '(, elt))))) |
| 158 | (with-output-to-temp-buffer "*Help*" | 147 | ((eq def 'automatic) |
| 159 | (princ | 148 | ;; Act on this and all following objects. |
| 160 | (let ((object (if help (nth 0 help) "object")) | 149 | (if (eval (funcall prompter elt)) |
| 161 | (objects (if help (nth 1 help) "objects")) | 150 | (progn |
| 162 | (action (if help (nth 2 help) "act on"))) | 151 | (funcall actor elt) |
| 163 | (concat (format "Type SPC or `y' to %s the current %s; | 152 | (setq actions (1+ actions)))) |
| 153 | (while (funcall next) | ||
| 154 | (if (eval (funcall prompter elt)) | ||
| 155 | (progn | ||
| 156 | (funcall actor elt) | ||
| 157 | (setq actions (1+ actions)))))) | ||
| 158 | ((eq def 'help) | ||
| 159 | (with-output-to-temp-buffer "*Help*" | ||
| 160 | (princ | ||
| 161 | (let ((object (if help (nth 0 help) "object")) | ||
| 162 | (objects (if help (nth 1 help) "objects")) | ||
| 163 | (action (if help (nth 2 help) "act on"))) | ||
| 164 | (concat | ||
| 165 | (format "Type SPC or `y' to %s the current %s; | ||
| 164 | DEL or `n' to skip the current %s; | 166 | DEL or `n' to skip the current %s; |
| 165 | ! to %s all remaining %s; | 167 | ! to %s all remaining %s; |
| 166 | ESC or `q' to exit;\n" | 168 | ESC or `q' to exit;\n" |
| 167 | action object object action objects) | 169 | action object object action objects) |
| 168 | (mapconcat (function | 170 | (mapconcat (function |
| 169 | (lambda (elt) | 171 | (lambda (elt) |
| 170 | (format "%c to %s" | 172 | (format "%c to %s" |
| 171 | (nth 0 elt) | 173 | (nth 0 elt) |
| 172 | (nth 2 elt)))) | 174 | (nth 2 elt)))) |
| 173 | action-alist | 175 | action-alist |
| 174 | ";\n") | 176 | ";\n") |
| 175 | (if action-alist ";\n") | 177 | (if action-alist ";\n") |
| 176 | (format "or . (period) to %s \ | 178 | (format "or . (period) to %s \ |
| 177 | the current %s and exit." | 179 | the current %s and exit." |
| 178 | action object))))) | 180 | action object))))) |
| 179 | 181 | ||
| 180 | (setq next (` (lambda () | 182 | (setq next (` (lambda () |
| 181 | (setq next '(, next)) | 183 | (setq next '(, next)) |
| 182 | '(, elt))))) | 184 | '(, elt))))) |
| 183 | ((vectorp def) | 185 | ((vectorp def) |
| 184 | ;; A user-defined key. | 186 | ;; A user-defined key. |
| 185 | (if (funcall (aref def 0) elt) ;Call its function. | 187 | (if (funcall (aref def 0) elt) ;Call its function. |
| 186 | ;; The function has eaten this object. | 188 | ;; The function has eaten this object. |
| 187 | (setq actions (1+ actions)) | 189 | (setq actions (1+ actions)) |
| 188 | ;; Regurgitated; try again. | 190 | ;; Regurgitated; try again. |
| 189 | (setq next (` (lambda () | 191 | (setq next (` (lambda () |
| 190 | (setq next '(, next)) | 192 | (setq next '(, next)) |
| 191 | '(, elt)))))) | 193 | '(, elt)))))) |
| 192 | (t | 194 | ((and (consp char) |
| 193 | ;; Random char. | 195 | (eq (car char) 'switch-frame)) |
| 194 | (message "Type %s for help." | 196 | ;; switch-frame event. Put it off until we're done. |
| 195 | (key-description (char-to-string help-char))) | 197 | (setq delayed-switch-frame char) |
| 196 | (beep) | 198 | (setq next (` (lambda () |
| 197 | (sit-for 1) | 199 | (setq next '(, next)) |
| 198 | (setq next (` (lambda () | 200 | '(, elt))))) |
| 199 | (setq next '(, next)) | 201 | (t |
| 200 | '(, elt))))))) | 202 | ;; Random char. |
| 201 | (if (eval prompt) | 203 | (message "Type %s for help." |
| 202 | (progn | 204 | (key-description (char-to-string help-char))) |
| 203 | (funcall actor elt) | 205 | (beep) |
| 204 | (setq actions (1+ actions)))))) | 206 | (sit-for 1) |
| 207 | (setq next (` (lambda () | ||
| 208 | (setq next '(, next)) | ||
| 209 | '(, elt))))))) | ||
| 210 | (if (eval prompt) | ||
| 211 | (progn | ||
| 212 | (funcall actor elt) | ||
| 213 | (setq actions (1+ actions))))))) | ||
| 214 | (if delayed-switch-frame | ||
| 215 | (setq unread-command-events | ||
| 216 | (cons delayed-switch-frame unread-command-events)))) | ||
| 205 | ;; Clear the last prompt from the minibuffer. | 217 | ;; Clear the last prompt from the minibuffer. |
| 206 | (message "") | 218 | (message "") |
| 207 | ;; Return the number of actions that were taken. | 219 | ;; Return the number of actions that were taken. |