]> code.delx.au - gnu-emacs/blobdiff - lisp/emacs-lisp/map-ynp.el
Fix breakage from previous change.
[gnu-emacs] / lisp / emacs-lisp / map-ynp.el
index 13202a9ce4d11deebf53b5c526a597b9a2740488..86057706ffced6e54b83346b92d52d3a355df663 100644 (file)
@@ -1,9 +1,9 @@
-;;; map-ynp.el --- general-purpose boolean question-asker
+;;; map-ynp.el --- general-purpose boolean question-asker  -*- lexical-binding:t -*-
 
 
-;; Copyright (C) 1991-1995, 2000-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1991-1995, 2000-2016 Free Software Foundation, Inc.
 
 ;; Author: Roland McGrath <roland@gnu.org>
 
 ;; Author: Roland McGrath <roland@gnu.org>
-;; Maintainer: FSF
+;; Maintainer: emacs-devel@gnu.org
 ;; Keywords: lisp, extensions
 ;; Package: emacs
 
 ;; Keywords: lisp, extensions
 ;; Package: emacs
 
@@ -34,7 +34,7 @@
 
 ;;; Code:
 
 
 ;;; Code:
 
-(declare-function x-popup-dialog "xmenu.c" (position contents &optional header))
+(declare-function x-popup-dialog "menu.c" (position contents &optional header))
 
 (defun map-y-or-n-p (prompter actor list &optional help action-alist
                              no-cursor-in-echo-area)
 
 (defun map-y-or-n-p (prompter actor list &optional help action-alist
                              no-cursor-in-echo-area)
@@ -44,7 +44,7 @@ Takes args PROMPTER ACTOR LIST, and optional args HELP and ACTION-ALIST.
 LIST is a list of objects, or a function of no arguments to return the next
 object or nil.
 
 LIST is a list of objects, or a function of no arguments to return the next
 object or nil.
 
-If PROMPTER is a string, the prompt is \(format PROMPTER OBJECT\).  If not
+If PROMPTER is a string, the prompt is \(format PROMPTER OBJECT).  If not
 a string, PROMPTER is a function of one arg (an object from LIST), which
 returns a string to be used as the prompt for that object.  If the return
 value is not a string, it may be nil to ignore the object or non-nil to act
 a string, PROMPTER is a function of one arg (an object from LIST), which
 returns a string to be used as the prompt for that object.  If the return
 value is not a string, it may be nil to ignore the object or non-nil to act
@@ -56,7 +56,7 @@ which gets called with each object that the user answers `yes' for.
 If HELP is given, it is a list (OBJECT OBJECTS ACTION),
 where OBJECT is a string giving the singular noun for an elt of LIST;
 OBJECTS is the plural noun for elts of LIST, and ACTION is a transitive
 If HELP is given, it is a list (OBJECT OBJECTS ACTION),
 where OBJECT is a string giving the singular noun for an elt of LIST;
 OBJECTS is the plural noun for elts of LIST, and ACTION is a transitive
-verb describing ACTOR.  The default is \(\"object\" \"objects\" \"act on\"\).
+verb describing ACTOR.  The default is \(\"object\" \"objects\" \"act on\").
 
 At the prompts, the user may enter y, Y, or SPC to act on that object;
 n, N, or DEL to skip that object; ! to act on all following objects;
 
 At the prompts, the user may enter y, Y, or SPC to act on that object;
 n, N, or DEL to skip that object; ! to act on all following objects;
@@ -79,7 +79,7 @@ are meaningful here.
 
 Returns the number of actions taken."
   (let* ((actions 0)
 
 Returns the number of actions taken."
   (let* ((actions 0)
-        user-keys mouse-event map prompt char elt tail def
+        user-keys mouse-event map prompt char elt def
         ;; Non-nil means we should use mouse menus to ask.
         use-menus
         delayed-switch-frame
         ;; Non-nil means we should use mouse menus to ask.
         use-menus
         delayed-switch-frame
@@ -89,13 +89,15 @@ Returns the number of actions taken."
         (next (if (functionp list)
                    (lambda () (setq elt (funcall list)))
                  (lambda () (when list
         (next (if (functionp list)
                    (lambda () (setq elt (funcall list)))
                  (lambda () (when list
-                         (setq elt (pop list))
-                         t)))))
+                             (setq elt (pop list))
+                             t))))
+        (try-again (lambda ()
+                     (let ((x next))
+                       (setq next (lambda () (setq next x) elt))))))
     (if (and (listp last-nonmenu-event)
             use-dialog-box)
        ;; Make a list describing a dialog box.
     (if (and (listp last-nonmenu-event)
             use-dialog-box)
        ;; Make a list describing a dialog box.
-       (let ((object (if help (capitalize (nth 0 help))))
-             (objects (if help (capitalize (nth 1 help))))
+       (let ((objects (if help (capitalize (nth 1 help))))
              (action (if help (capitalize (nth 2 help)))))
          (setq map `(("Yes" . act) ("No" . skip)
                      ,@(mapcar (lambda (elt)
              (action (if help (capitalize (nth 2 help)))))
          (setq map `(("Yes" . act) ("No" . skip)
                      ,@(mapcar (lambda (elt)
@@ -129,8 +131,9 @@ Returns the number of actions taken."
     (unwind-protect
        (progn
          (if (stringp prompter)
     (unwind-protect
        (progn
          (if (stringp prompter)
-             (setq prompter `(lambda (object)
-                               (format ,prompter object))))
+             (setq prompter (let ((prompter prompter))
+                              (lambda (object)
+                                (format prompter object)))))
          (while (funcall next)
            (setq prompt (funcall prompter elt))
            (cond ((stringp prompt)
          (while (funcall next)
            (setq prompt (funcall prompter elt))
            (cond ((stringp prompt)
@@ -176,9 +179,7 @@ Returns the number of actions taken."
                                next (lambda () nil)))
                         ((eq def 'quit)
                          (setq quit-flag t)
                                next (lambda () nil)))
                         ((eq def 'quit)
                          (setq quit-flag t)
-                         (setq next `(lambda ()
-                                       (setq next ',next)
-                                       ',elt)))
+                         (funcall try-again))
                         ((eq def 'automatic)
                          ;; Act on this and all following objects.
                          (if (funcall prompter elt)
                         ((eq def 'automatic)
                          ;; Act on this and all following objects.
                          (if (funcall prompter elt)
@@ -197,7 +198,8 @@ Returns the number of actions taken."
                                   (objects (if help (nth 1 help) "objects"))
                                   (action (if help (nth 2 help) "act on")))
                               (concat
                                   (objects (if help (nth 1 help) "objects"))
                                   (action (if help (nth 2 help) "act on")))
                               (concat
-                               (format "Type SPC or `y' to %s the current %s;
+                               (format-message "\
+Type SPC or `y' to %s the current %s;
 DEL or `n' to skip the current %s;
 RET or `q' to give up on the %s (skip all remaining %s);
 C-g to quit (cancel the whole command);
 DEL or `n' to skip the current %s;
 RET or `q' to give up on the %s (skip all remaining %s);
 C-g to quit (cancel the whole command);
@@ -219,40 +221,30 @@ the current %s and exit."
                            (with-current-buffer standard-output
                              (help-mode)))
 
                            (with-current-buffer standard-output
                              (help-mode)))
 
-                         (setq next `(lambda ()
-                                      (setq next ',next)
-                                      ',elt)))
-                         ((and (symbolp def) (commandp def))
-                          (call-interactively def)
-                          ;; Regurgitated; try again.
-                          (setq next `(lambda ()
-                                        (setq next ',next)
-                                        ',elt)))
+                         (funcall try-again))
+                        ((and (symbolp def) (commandp def))
+                         (call-interactively def)
+                         ;; Regurgitated; try again.
+                         (funcall try-again))
                         ((vectorp def)
                          ;; A user-defined key.
                          (if (funcall (aref def 0) elt) ;Call its function.
                              ;; The function has eaten this object.
                              (setq actions (1+ actions))
                            ;; Regurgitated; try again.
                         ((vectorp def)
                          ;; A user-defined key.
                          (if (funcall (aref def 0) elt) ;Call its function.
                              ;; The function has eaten this object.
                              (setq actions (1+ actions))
                            ;; Regurgitated; try again.
-                           (setq next `(lambda ()
-                                        (setq next ',next)
-                                        ',elt))))
+                           (funcall try-again)))
                         ((and (consp char)
                               (eq (car char) 'switch-frame))
                          ;; switch-frame event.  Put it off until we're done.
                          (setq delayed-switch-frame char)
                         ((and (consp char)
                               (eq (car char) 'switch-frame))
                          ;; switch-frame event.  Put it off until we're done.
                          (setq delayed-switch-frame char)
-                         (setq next `(lambda ()
-                                      (setq next ',next)
-                                      ',elt)))
+                         (funcall try-again))
                         (t
                          ;; Random char.
                          (message "Type %s for help."
                                   (key-description (vector help-char)))
                          (beep)
                          (sit-for 1)
                         (t
                          ;; Random char.
                          (message "Type %s for help."
                                   (key-description (vector help-char)))
                          (beep)
                          (sit-for 1)
-                         (setq next `(lambda ()
-                                      (setq next ',next)
-                                      ',elt)))))
+                         (funcall try-again))))
                  (prompt
                   (funcall actor elt)
                   (setq actions (1+ actions))))))
                  (prompt
                   (funcall actor elt)
                   (setq actions (1+ actions))))))