Mercurial > hg > xemacs-beta
annotate lisp/map-ynp.el @ 5820:b3824b7f5627
Some changes to eliminate warnings with Apple clang version 1.7.
src/ChangeLog addition:
2014-10-18 Aidan Kehoe <kehoea@parhasard.net>
Some changes to eliminate warnings with Apple clang version 1.7.
* cm.c (send_string_to_tty_console):
* doprnt.c (doprnt_2):
* doprnt.c (parse_off_posnum):
* event-stream.c (dribble_out_event):
Cast various calls to Lstream_putc() to void when the result isn't
being used, for the sake of clang.
* lisp.h:
Declare #'replace here too, it's used in event-stream.c.
* lisp.h (ALLOCA):
* lisp.h (MALLOC_OR_ALLOCA):
Cast a couple of zeros in the context of the ternary operator to
void to prevent unused value warnings with clang.
* sysdep.c (child_setup_tty):
* text.h (ASSERT_ASCTEXT_ASCII_LEN):
Use DO_NOTHING in these files to quieten the compiler.
lib-src/ChangeLog addition:
2014-10-18 Aidan Kehoe <kehoea@parhasard.net>
* ootags.c (substitute):
Cast the result of strlen to int before comparing it with a signed
value, for the sake of compiler warnings.
| author | Aidan Kehoe <kehoea@parhasard.net> |
|---|---|
| date | Sat, 18 Oct 2014 21:48:10 +0100 |
| parents | 308d34e9f07d |
| children |
| rev | line source |
|---|---|
| 428 | 1 ;;; map-ynp.el --- General-purpose boolean question-asker. |
| 2 | |
| 3 ;; Copyright (C) 1991-1995, 1997 Free Software Foundation, Inc. | |
| 4 | |
| 5 ;; Author: Roland McGrath <roland@gnu.ai.mit.edu> | |
| 6 ;; Keywords: lisp, extensions, dumped | |
| 7 | |
| 8 ;; This file is part of XEmacs. | |
| 9 | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4783
diff
changeset
|
10 ;; XEmacs is free software: you can redistribute it and/or modify it |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4783
diff
changeset
|
11 ;; under the terms of the GNU General Public License as published by the |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4783
diff
changeset
|
12 ;; Free Software Foundation, either version 3 of the License, or (at your |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4783
diff
changeset
|
13 ;; option) any later version. |
| 428 | 14 |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4783
diff
changeset
|
15 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4783
diff
changeset
|
16 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4783
diff
changeset
|
17 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4783
diff
changeset
|
18 ;; for more details. |
| 428 | 19 |
| 20 ;; You should have received a copy of the GNU General Public License | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4783
diff
changeset
|
21 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
| 428 | 22 |
| 23 ;;; Synched up with: Emacs/Mule zeta. | |
| 24 | |
| 25 ;;; Commentary: | |
| 26 | |
| 27 ;; This file is dumped with XEmacs. | |
| 28 | |
| 29 ;; map-y-or-n-p is a general-purpose question-asking function. | |
| 30 ;; It asks a series of y/n questions (a la y-or-n-p), and decides to | |
| 2757 | 31 ;; apply an action to each element of a list based on the answer. |
| 428 | 32 ;; The nice thing is that you also get some other possible answers |
| 33 ;; to use, reminiscent of query-replace: ! to answer y to all remaining | |
| 34 ;; questions; ESC or q to answer n to all remaining questions; . to answer | |
| 35 ;; y once and then n for the remainder; and you can get help with C-h. | |
| 36 | |
| 37 ;;; Code: | |
| 38 | |
| 39 (defun map-y-or-n-p (prompter actor list &optional help action-alist | |
| 40 no-cursor-in-echo-area) | |
| 41 "Ask a series of boolean questions. | |
| 42 Takes args PROMPTER ACTOR LIST, and optional args HELP and ACTION-ALIST. | |
| 43 | |
| 44 LIST is a list of objects, or a function of no arguments to return the next | |
| 45 object or nil. | |
| 46 | |
| 47 If PROMPTER is a string, the prompt is \(format PROMPTER OBJECT\). If not | |
| 48 a string, PROMPTER is a function of one arg (an object from LIST), which | |
| 49 returns a string to be used as the prompt for that object. If the return | |
| 50 value is not a string, it may be nil to ignore the object or non-nil to act | |
| 51 on the object without asking the user. | |
| 52 | |
| 53 ACTOR is a function of one arg (an object from LIST), | |
| 54 which gets called with each object that the user answers `yes' for. | |
| 55 | |
| 56 If HELP is given, it is a list (OBJECT OBJECTS ACTION), | |
| 57 where OBJECT is a string giving the singular noun for an elt of LIST; | |
| 58 OBJECTS is the plural noun for elts of LIST, and ACTION is a transitive | |
| 59 verb describing ACTOR. The default is \(\"object\" \"objects\" \"act on\"\). | |
| 60 | |
| 61 At the prompts, the user may enter y, Y, or SPC to act on that object; | |
| 62 n, N, or DEL to skip that object; ! to act on all following objects; | |
| 63 ESC or q to exit (skip all following objects); . (period) to act on the | |
| 64 current object and then exit; or \\[help-command] to get help. | |
| 65 | |
| 66 If ACTION-ALIST is given, it is an alist (KEY FUNCTION HELP) of extra keys | |
| 67 that will be accepted. KEY is a character; FUNCTION is a function of one | |
| 68 arg (an object from LIST); HELP is a string. When the user hits KEY, | |
| 69 FUNCTION is called. If it returns non-nil, the object is considered | |
| 70 \"acted upon\", and the next object from LIST is processed. If it returns | |
| 71 nil, the prompt is repeated for the same object. | |
| 72 | |
| 73 Final optional argument NO-CURSOR-IN-ECHO-AREA non-nil says not to set | |
| 74 `cursor-in-echo-area' while prompting. | |
| 75 | |
| 76 This function uses `query-replace-map' to define the standard responses, | |
| 77 but not all of the responses which `query-replace' understands | |
| 78 are meaningful here. | |
| 79 | |
| 80 Returns the number of actions taken." | |
| 81 (let* ((actions 0) | |
| 82 user-keys mouse-event map prompt char elt def | |
| 83 ;; Non-nil means we should use mouse menus to ask. | |
| 84 ;; use-menus | |
| 85 ;;delayed-switch-frame | |
| 86 (next (if (or (and list (symbolp list)) | |
| 87 (subrp list) | |
| 88 (compiled-function-p list) | |
| 89 (and (consp list) | |
| 90 (eq (car list) 'lambda))) | |
| 91 #'(lambda () (setq elt (funcall list))) | |
| 92 #'(lambda () | |
| 93 (if list | |
| 94 (progn | |
| 95 (setq elt (car list) | |
| 96 list (cdr list)) | |
| 97 t) | |
| 98 nil))))) | |
| 99 (if (should-use-dialog-box-p) | |
| 100 ;; Make a list describing a dialog box. | |
| 101 (let (;; (object (capitalize (or (nth 0 help) "object"))) | |
| 102 ;; (objects (capitalize (or (nth 1 help) "objects"))) | |
| 103 ;; (action (capitalize (or (nth 2 help) "act on"))) | |
| 104 ) | |
| 442 | 105 (setq map `(("%_Yes" . act) ("%_No" . skip) |
| 428 | 106 ; bogus crap. --ben |
| 107 ; ((, (if help | |
| 108 ; (capitalize | |
| 109 ; (or (nth 3 help) | |
| 110 ; (concat action " All " objects))) | |
| 111 ; "Do All")) . automatic) | |
| 112 ; ((, (if help | |
| 113 ; (capitalize | |
| 114 ; (or (nth 4 help) | |
| 115 ; (concat action " " object " And Quit"))) | |
| 116 ; "Do it and Quit")) . act-and-exit) | |
| 117 ; ((, (capitalize | |
| 118 ; (or (and help (nth 5 help)) "Quit"))) | |
| 119 ; . exit) | |
| 442 | 120 ("Yes %_All" . automatic) |
| 121 ("No A%_ll" . exit) | |
| 122 ("%_Cancel" . quit) | |
| 428 | 123 ,@(mapcar #'(lambda (elt) |
| 124 (cons (capitalize (nth 2 elt)) | |
| 125 (vector (nth 1 elt)))) | |
| 126 action-alist)) | |
| 127 mouse-event last-command-event)) | |
| 128 (setq user-keys (if action-alist | |
| 129 (concat (mapconcat #'(lambda (elt) | |
| 130 (key-description | |
| 131 (if (characterp (car elt)) | |
| 132 ;; XEmacs | |
| 133 (char-to-string (car elt)) | |
| 134 (car elt)))) | |
| 135 action-alist ", ") | |
| 136 " ") | |
| 137 "") | |
| 138 ;; Make a map that defines each user key as a vector containing | |
| 139 ;; its definition. | |
| 140 ;; XEmacs | |
| 141 map (let ((foomap (make-sparse-keymap))) | |
|
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
142 (mapc #'(lambda (elt) |
|
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
143 (define-key |
|
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
144 foomap |
|
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
145 (if (characterp (car elt)) |
|
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
146 (char-to-string (car elt)) |
|
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
147 (car elt)) |
|
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
148 (vector (nth 1 elt)))) |
|
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
149 action-alist) |
| 428 | 150 (set-keymap-parents foomap (list query-replace-map)) |
| 151 foomap))) | |
| 152 (unwind-protect | |
| 153 (progn | |
| 154 (if (stringp prompter) | |
| 155 (setq prompter `(lambda (object) | |
| 156 (format ,prompter object)))) | |
| 157 (while (funcall next) | |
| 158 (setq prompt (funcall prompter elt)) | |
| 159 (cond ((stringp prompt) | |
| 160 ;; Prompt the user about this object. | |
| 161 (setq quit-flag nil) | |
| 162 (if mouse-event ; XEmacs | |
| 4222 | 163 (setq def (or (and-fboundp |
| 164 #'get-dialog-box-response | |
| 165 (get-dialog-box-response | |
| 166 mouse-event | |
| 167 (cons prompt map))) | |
| 428 | 168 'quit)) |
| 169 ;; Prompt in the echo area. | |
| 170 (let ((cursor-in-echo-area (not no-cursor-in-echo-area))) | |
| 171 (display-message | |
| 172 'prompt | |
| 173 (format "%s(y, n, !, ., q, %sor %s) " | |
| 174 prompt user-keys | |
| 175 (key-description (vector help-char)))) | |
| 176 (setq char (next-command-event)) | |
| 177 ;; Show the answer to the question. | |
| 178 (display-message | |
| 179 'prompt | |
| 180 (format | |
| 181 "%s(y, n, !, ., q, %sor %s) %s" | |
| 182 prompt user-keys | |
| 183 (key-description (vector help-char)) | |
| 184 (single-key-description char)))) | |
| 185 (setq def (lookup-key map (vector char)))) | |
| 186 (cond ((eq def 'exit) | |
| 187 (setq next #'(lambda () nil))) | |
| 188 ((eq def 'act) | |
| 189 ;; Act on the object. | |
| 190 (funcall actor elt) | |
| 191 (setq actions (1+ actions))) | |
| 192 ((eq def 'skip) | |
| 193 ;; Skip the object. | |
| 194 ) | |
| 195 ((eq def 'act-and-exit) | |
| 196 ;; Act on the object and then exit. | |
| 197 (funcall actor elt) | |
| 198 (setq actions (1+ actions) | |
| 199 next (function (lambda () nil)))) | |
| 200 ((or (eq def 'quit) (eq def 'exit-prefix)) | |
| 201 (setq quit-flag t) | |
| 202 (setq next `(lambda () | |
| 203 (setq next ',next) | |
| 204 ',elt))) | |
| 205 ((eq def 'automatic) | |
| 206 ;; Act on this and all following objects. | |
| 207 ;; (if (funcall prompter elt) ; Emacs | |
| 208 (if (eval (funcall prompter elt)) | |
| 209 (progn | |
| 210 (funcall actor elt) | |
| 211 (setq actions (1+ actions)))) | |
| 212 (while (funcall next) | |
| 213 ;; (funcall prompter elt) ; Emacs | |
| 214 (if (eval (funcall prompter elt)) | |
| 215 (progn | |
| 216 (funcall actor elt) | |
| 217 (setq actions (1+ actions)))))) | |
| 218 ((eq def 'help) | |
| 219 (with-output-to-temp-buffer "*Help*" | |
| 220 (princ | |
| 221 (let ((object (if help (nth 0 help) "object")) | |
| 222 (objects (if help (nth 1 help) "objects")) | |
| 223 (action (if help (nth 2 help) "act on"))) | |
| 224 (concat | |
| 225 (format "Type SPC or `y' to %s the current %s; | |
| 226 DEL or `n' to skip the current %s; | |
| 227 ! to %s all remaining %s; | |
| 228 ESC or `q' to exit;\n" | |
| 229 action object object action objects) | |
| 230 (mapconcat (function | |
| 231 (lambda (elt) | |
| 232 (format "%c to %s" | |
| 233 (nth 0 elt) | |
| 2545 | 234 (downcase |
| 235 (normalize-menu-text | |
| 236 (nth 2 elt)))))) | |
| 428 | 237 action-alist |
| 238 ";\n") | |
| 239 (if action-alist ";\n") | |
| 240 (format "or . (period) to %s \ | |
| 241 the current %s and exit." | |
| 242 action object)))) | |
| 243 (save-excursion | |
| 244 (set-buffer standard-output) | |
| 245 (help-mode))) | |
| 246 | |
| 247 (setq next `(lambda () | |
| 248 (setq next ',next) | |
| 249 ',elt))) | |
| 250 ((vectorp def) | |
| 251 ;; A user-defined key. | |
| 252 (if (funcall (aref def 0) elt) ;Call its function. | |
| 253 ;; The function has eaten this object. | |
| 254 (setq actions (1+ actions)) | |
| 255 ;; Regurgitated; try again. | |
| 256 (setq next `(lambda () | |
| 257 (setq next ',next) | |
| 258 ',elt)))) | |
| 259 ;((and (consp char) ; Emacs | |
| 260 ; (eq (car char) 'switch-frame)) | |
| 261 ; ;; switch-frame event. Put it off until we're done. | |
| 262 ; (setq delayed-switch-frame char) | |
| 263 ; (setq next `(lambda () | |
| 264 ; (setq next ',next) | |
| 265 ; ',elt))) | |
| 266 (t | |
| 267 ;; Random char. | |
| 268 (message "Type %s for help." | |
| 269 (key-description (vector help-char))) | |
| 270 (beep) | |
| 271 (sit-for 1) | |
| 272 (setq next `(lambda () | |
| 273 (setq next ',next) | |
| 274 ',elt))))) | |
| 275 ((eval prompt) | |
| 276 (progn | |
| 277 (funcall actor elt) | |
| 278 (setq actions (1+ actions))))))) | |
| 279 ;;(if delayed-switch-frame | |
| 280 ;; (setq unread-command-events | |
| 281 ;; (cons delayed-switch-frame unread-command-events)))) | |
| 282 ;; ((eval prompt) | |
| 283 ;; (progn | |
| 284 ;; (funcall actor elt) | |
| 285 ;; (setq actions (1+ actions))))) | |
| 286 ) | |
| 287 ;; Clear the last prompt from the minibuffer. | |
| 288 (clear-message 'prompt) | |
| 289 ;; Return the number of actions that were taken. | |
| 290 actions)) | |
| 291 | |
| 292 ;;; map-ynp.el ends here |
