summaryrefslogtreecommitdiff
path: root/lisp/subr.el
diff options
context:
space:
mode:
authorChong Yidong <cyd@gnu.org>2011-10-29 16:41:39 +0800
committerChong Yidong <cyd@gnu.org>2011-10-29 16:41:39 +0800
commitaa4de34102ce87590991e62680eeefe7efffcc79 (patch)
treefb6e966dc727036d2ec7d14b5547dae76c0db127 /lisp/subr.el
parente1eb5385bb8c30e9a9ff3b04b0928664e3440e01 (diff)
downloademacs-aa4de34102ce87590991e62680eeefe7efffcc79.tar.gz
* lisp/subr.el (y-or-n-p): Add code for batch mode.
Fixes: debbugs:9818
Diffstat (limited to 'lisp/subr.el')
-rw-r--r--lisp/subr.el26
1 files changed, 20 insertions, 6 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index f3cd4dabe20..50ea49bd8c9 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -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")))