]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/subr.el (y-or-n-p): Add code for batch mode.
authorChong Yidong <cyd@gnu.org>
Sat, 29 Oct 2011 08:41:39 +0000 (16:41 +0800)
committerChong Yidong <cyd@gnu.org>
Sat, 29 Oct 2011 08:41:39 +0000 (16:41 +0800)
Fixes: debbugs:9818
lisp/ChangeLog
lisp/subr.el

index 7565548fe535cc612bc57493c1fc1a7a2ad59ae8..8309d3256bf0bdfb0f8031807c79ce1f4e3a8796 100644 (file)
@@ -1,5 +1,7 @@
 2011-10-29  Chong Yidong  <cyd@gnu.org>
 
+       * subr.el (y-or-n-p): Add code for batch mode (Bug#9818).
+
        * mouse.el (mouse-yank-primary): Push the mark (Bug#9894).
 
        * textmodes/flyspell.el (flyspell-word): Fix char offset for
index f3cd4dabe20a02f31486666006866b33578ff9a6..50ea49bd8c9a7f2b0b68db838f94eb4f52e813fd 100644 (file)
@@ -2262,11 +2262,25 @@ is nil and `use-dialog-box' is non-nil."
   ;; where all the keys were unbound (i.e. it somehow got triggered
   ;; within read-key, apparently).  I had to kill it.
   (let ((answer 'recenter))
-    (if (and (display-popup-menus-p)
-             (listp last-nonmenu-event)
-             use-dialog-box)
-        (setq answer
-              (x-popup-dialog t `(,prompt ("Yes" . act) ("No" . skip))))
+    (cond
+     (noninteractive
+      (setq prompt (concat prompt
+                           (if (eq ?\s (aref prompt (1- (length prompt))))
+                               "" " ")
+                           "(y or n) "))
+      (let ((temp-prompt prompt))
+       (while (not (memq answer '(act skip)))
+         (let ((str (read-string temp-prompt)))
+           (cond ((member str '("y" "Y")) (setq answer 'act))
+                 ((member str '("n" "N")) (setq answer 'skip))
+                 (t (setq temp-prompt (concat "Please answer y or n.  "
+                                              prompt))))))))
+     ((and (display-popup-menus-p)
+          (listp last-nonmenu-event)
+          use-dialog-box)
+      (setq answer
+           (x-popup-dialog t `(,prompt ("Yes" . act) ("No" . skip)))))
+     (t
       (setq prompt (concat prompt
                            (if (eq ?\s (aref prompt (1- (length prompt))))
                                "" " ")
@@ -2288,7 +2302,7 @@ is nil and `use-dialog-box' is non-nil."
              ((memq answer '(exit-prefix quit)) (signal 'quit nil) t)
              (t t)))
         (ding)
-        (discard-input)))
+        (discard-input))))
     (let ((ret (eq answer 'act)))
       (unless noninteractive
         (message "%s %s" prompt (if ret "y" "n")))