diff options
| author | Richard M. Stallman | 1993-03-09 19:53:06 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-03-09 19:53:06 +0000 |
| commit | 0a2eb25e0527bb91575a3bdc4b978fad1f2c46c5 (patch) | |
| tree | eb48e82d3591f5e2a3a6d1d5b97fc7d32abfcf9a | |
| parent | 81bdc14db5596d5c80c08bd4f5eaeb1b59cf132c (diff) | |
| download | emacs-0a2eb25e0527bb91575a3bdc4b978fad1f2c46c5.tar.gz emacs-0a2eb25e0527bb91575a3bdc4b978fad1f2c46c5.zip | |
(map-y-or-n-p): Use query-replace-map.
| -rw-r--r-- | lisp/map-ynp.el | 88 |
1 files changed, 48 insertions, 40 deletions
diff --git a/lisp/map-ynp.el b/lisp/map-ynp.el index ddc91d32776..e79e47fa664 100644 --- a/lisp/map-ynp.el +++ b/lisp/map-ynp.el | |||
| @@ -67,28 +67,12 @@ FUNCTION is called. If it returns non-nil, the object is considered | |||
| 67 | \"acted upon\", and the next object from LIST is processed. If it returns | 67 | \"acted upon\", and the next object from LIST is processed. If it returns |
| 68 | nil, the prompt is repeated for the same object. | 68 | nil, the prompt is repeated for the same object. |
| 69 | 69 | ||
| 70 | This function uses `query-replace-map' to define the standard responses, | ||
| 71 | but not all of the responses which `query-replace' understands | ||
| 72 | are meaningful here. | ||
| 73 | |||
| 70 | Returns the number of actions taken." | 74 | Returns the number of actions taken." |
| 71 | (let* ((old-help-form help-form) | 75 | (let* ((user-keys (if action-alist |
| 72 | (help-form (let ((object (if help (nth 0 help) "object")) | ||
| 73 | (objects (if help (nth 1 help) "objects")) | ||
| 74 | (action (if help (nth 2 help) "act on"))) | ||
| 75 | (concat (format "Type SPC or `y' to %s the current %s; | ||
| 76 | DEL or `n' to skip the current %s; | ||
| 77 | ! to %s all remaining %s; | ||
| 78 | ESC or `q' to exit;\n" | ||
| 79 | action object object action objects) | ||
| 80 | (mapconcat (function | ||
| 81 | (lambda (elt) | ||
| 82 | (format "%c to %s" | ||
| 83 | (nth 0 elt) | ||
| 84 | (nth 2 elt)))) | ||
| 85 | action-alist | ||
| 86 | ";\n") | ||
| 87 | (if action-alist ";\n") | ||
| 88 | (format "or . (period) to %s \ | ||
| 89 | the current %s and exit." | ||
| 90 | action object)))) | ||
| 91 | (user-keys (if action-alist | ||
| 92 | (concat (mapconcat (function | 76 | (concat (mapconcat (function |
| 93 | (lambda (elt) | 77 | (lambda (elt) |
| 94 | (key-description | 78 | (key-description |
| @@ -96,8 +80,15 @@ the current %s and exit." | |||
| 96 | action-alist ", ") | 80 | action-alist ", ") |
| 97 | " ") | 81 | " ") |
| 98 | "")) | 82 | "")) |
| 83 | ;; Make a map that defines all the user keys as `user'. | ||
| 84 | (map (cons 'keymap | ||
| 85 | (append (mapcar (function | ||
| 86 | (lambda (elt) | ||
| 87 | (cons (car elt) 'user))) | ||
| 88 | action-alist) | ||
| 89 | query-replace-map))) | ||
| 99 | (actions 0) | 90 | (actions 0) |
| 100 | prompt char elt tail | 91 | prompt char elt tail def |
| 101 | (next (if (or (symbolp list) | 92 | (next (if (or (symbolp list) |
| 102 | (subrp list) | 93 | (subrp list) |
| 103 | (byte-code-function-p list) | 94 | (byte-code-function-p list) |
| @@ -112,6 +103,7 @@ the current %s and exit." | |||
| 112 | list (cdr list)) | 103 | list (cdr list)) |
| 113 | t) | 104 | t) |
| 114 | nil)))))) | 105 | nil)))))) |
| 106 | |||
| 115 | (if (stringp prompter) | 107 | (if (stringp prompter) |
| 116 | (setq prompter (` (lambda (object) | 108 | (setq prompter (` (lambda (object) |
| 117 | (format (, prompter) object))))) | 109 | (format (, prompter) object))))) |
| @@ -124,28 +116,23 @@ the current %s and exit." | |||
| 124 | (message "%s(y, n, !, ., q, %sor %s) " | 116 | (message "%s(y, n, !, ., q, %sor %s) " |
| 125 | prompt user-keys | 117 | prompt user-keys |
| 126 | (key-description (char-to-string help-char))) | 118 | (key-description (char-to-string help-char))) |
| 127 | (setq char (read-char))) | 119 | (setq char (read-event))) |
| 128 | (cond ((or (= ?q char) | 120 | (setq def (lookup-key map (vector char))) |
| 129 | (= ?\e char)) | 121 | (cond ((eq def 'exit) |
| 130 | (setq next (function (lambda () nil)))) | 122 | (setq next (function (lambda () nil)))) |
| 131 | ((or (= ?y char) | 123 | ((eq def 'act) |
| 132 | (= ?Y char) | ||
| 133 | (= ? char)) | ||
| 134 | ;; Act on the object. | 124 | ;; Act on the object. |
| 135 | (let ((help-form old-help-form)) | 125 | (funcall actor elt) |
| 136 | (funcall actor elt)) | ||
| 137 | (setq actions (1+ actions))) | 126 | (setq actions (1+ actions))) |
| 138 | ((or (= ?n char) | 127 | ((eq def 'skip) |
| 139 | (= ?N char) | ||
| 140 | (= ?\^? char)) | ||
| 141 | ;; Skip the object. | 128 | ;; Skip the object. |
| 142 | ) | 129 | ) |
| 143 | ((= ?. char) | 130 | ((eq def 'act-and-exit) |
| 144 | ;; Act on the object and then exit. | 131 | ;; Act on the object and then exit. |
| 145 | (funcall actor elt) | 132 | (funcall actor elt) |
| 146 | (setq actions (1+ actions) | 133 | (setq actions (1+ actions) |
| 147 | next (function (lambda () nil)))) | 134 | next (function (lambda () nil)))) |
| 148 | ((= ?! char) | 135 | ((eq def 'automatic) |
| 149 | ;; Act on this and all following objects. | 136 | ;; Act on this and all following objects. |
| 150 | (if (eval (funcall prompter elt)) | 137 | (if (eval (funcall prompter elt)) |
| 151 | (progn | 138 | (progn |
| @@ -156,20 +143,41 @@ the current %s and exit." | |||
| 156 | (progn | 143 | (progn |
| 157 | (funcall actor elt) | 144 | (funcall actor elt) |
| 158 | (setq actions (1+ actions)))))) | 145 | (setq actions (1+ actions)))))) |
| 159 | ((= ?? char) | 146 | ((eq def 'help) |
| 160 | (setq unread-command-events (list help-char)) | 147 | (with-output-to-temp-buffer "*Help*" |
| 148 | (princ | ||
| 149 | (let ((object (if help (nth 0 help) "object")) | ||
| 150 | (objects (if help (nth 1 help) "objects")) | ||
| 151 | (action (if help (nth 2 help) "act on"))) | ||
| 152 | (concat (format "Type SPC or `y' to %s the current %s; | ||
| 153 | DEL or `n' to skip the current %s; | ||
| 154 | ! to %s all remaining %s; | ||
| 155 | ESC or `q' to exit;\n" | ||
| 156 | action object object action objects) | ||
| 157 | (mapconcat (function | ||
| 158 | (lambda (elt) | ||
| 159 | (format "%c to %s" | ||
| 160 | (nth 0 elt) | ||
| 161 | (nth 2 elt)))) | ||
| 162 | action-alist | ||
| 163 | ";\n") | ||
| 164 | (if action-alist ";\n") | ||
| 165 | (format "or . (period) to %s \ | ||
| 166 | the current %s and exit." | ||
| 167 | action object))))) | ||
| 168 | |||
| 161 | (setq next (` (lambda () | 169 | (setq next (` (lambda () |
| 162 | (setq next '(, next)) | 170 | (setq next '(, next)) |
| 163 | '(, elt))))) | 171 | '(, elt))))) |
| 164 | ((setq tail (assq char action-alist)) | 172 | ((eq def 'user) |
| 165 | ;; A user-defined key. | 173 | ;; A user-defined key. |
| 166 | (if (funcall (nth 1 tail) elt) ;Call its function. | 174 | (if (funcall (nth 1 tail) elt) ;Call its function. |
| 167 | ;; The function has eaten this object. | 175 | ;; The function has eaten this object. |
| 168 | (setq actions (1+ actions)) | 176 | (setq actions (1+ actions)) |
| 169 | ;; Regurgitated; try again. | 177 | ;; Regurgitated; try again. |
| 170 | (setq next (` (lambda () | 178 | (setq next (` (lambda () |
| 171 | (setq next '(, next)) | 179 | (setq next '(, next)) |
| 172 | '(, elt)))))) | 180 | '(, elt)))))) |
| 173 | (t | 181 | (t |
| 174 | ;; Random char. | 182 | ;; Random char. |
| 175 | (message "Type %s for help." | 183 | (message "Type %s for help." |