aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/NEWS2
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/subr.el99
-rw-r--r--src/ChangeLog4
-rw-r--r--src/fns.c13
5 files changed, 63 insertions, 59 deletions
diff --git a/etc/NEWS b/etc/NEWS
index b55820dac0d..fdc066870ef 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -662,6 +662,8 @@ sc.el, x-menu.el, rnews.el, rnewspost.el
662 662
663* Lisp changes in Emacs 24.1 663* Lisp changes in Emacs 24.1
664 664
665** `y-or-n-p' and `yes-or-no-p' now accept format string arguments.
666
665** `image-library-alist' is renamed to `dynamic-library-alist'. 667** `image-library-alist' is renamed to `dynamic-library-alist'.
666The variable is now used to load all kind of supported dynamic libraries, 668The variable is now used to load all kind of supported dynamic libraries,
667not just image libraries. The previous name is still available as an 669not just image libraries. The previous name is still available as an
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index faec22993fa..22b0818b2bb 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
12011-01-07 Chong Yidong <cyd@stupidchicken.com>
2
3 * subr.el (y-or-n-p): Accept format string args.
4
12011-01-07 Glenn Morris <rgm@gnu.org> 52011-01-07 Glenn Morris <rgm@gnu.org>
2 6
3 * Makefile.in (EMACSOPT): Add --no-site-lisp. 7 * Makefile.in (EMACSOPT): Add --no-site-lisp.
diff --git a/lisp/subr.el b/lisp/subr.el
index 8a8e4410ce6..ce0149a477b 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2011,6 +2011,55 @@ floating point support."
2011 (push read unread-command-events) 2011 (push read unread-command-events)
2012 nil)))))) 2012 nil))))))
2013(set-advertised-calling-convention 'sit-for '(seconds &optional nodisp) "22.1") 2013(set-advertised-calling-convention 'sit-for '(seconds &optional nodisp) "22.1")
2014
2015(defun y-or-n-p (prompt &rest args)
2016 "Ask user a \"y or n\" question. Return t if answer is \"y\".
2017The argument PROMPT is the string to display to ask the question.
2018It should end in a space; `y-or-n-p' adds `(y or n) ' to it.
2019No confirmation of the answer is requested; a single character is enough.
2020Also accepts Space to mean yes, or Delete to mean no. \(Actually, it uses
2021the bindings in `query-replace-map'; see the documentation of that variable
2022for more information. In this case, the useful bindings are `act', `skip',
2023`recenter', and `quit'.\)
2024
2025Under a windowing system a dialog box will be used if `last-nonmenu-event'
2026is nil and `use-dialog-box' is non-nil."
2027 ;; ¡Beware! when I tried to edebug this code, Emacs got into a weird state
2028 ;; where all the keys were unbound (i.e. it somehow got triggered
2029 ;; within read-key, apparently). I had to kill it.
2030 (let ((answer 'recenter))
2031 (if (and (display-popup-menus-p)
2032 (listp last-nonmenu-event)
2033 use-dialog-box)
2034 (setq answer
2035 (x-popup-dialog t `(,prompt ("yes" . act) ("No" . skip))))
2036 (setq prompt (concat (apply 'format prompt args)
2037 (if (eq ?\s (aref prompt (1- (length prompt))))
2038 "" " ")
2039 "(y or n) "))
2040 (while
2041 (let* ((key
2042 (let ((cursor-in-echo-area t))
2043 (when minibuffer-auto-raise
2044 (raise-frame (window-frame (minibuffer-window))))
2045 (read-key (propertize (if (eq answer 'recenter)
2046 prompt
2047 (concat "Please answer y or n. "
2048 prompt))
2049 'face 'minibuffer-prompt)))))
2050 (setq answer (lookup-key query-replace-map (vector key) t))
2051 (cond
2052 ((memq answer '(skip act)) nil)
2053 ((eq answer 'recenter) (recenter) t)
2054 ((memq answer '(exit-prefix quit)) (signal 'quit nil) t)
2055 (t t)))
2056 (ding)
2057 (discard-input)))
2058 (let ((ret (eq answer 'act)))
2059 (unless noninteractive
2060 (message "%s %s" prompt (if ret "y" "n")))
2061 ret)))
2062
2014 2063
2015;;; Atomic change groups. 2064;;; Atomic change groups.
2016 2065
@@ -3305,56 +3354,6 @@ clone should be incorporated in the clone."
3305 (overlay-put ol2 'evaporate t) 3354 (overlay-put ol2 'evaporate t)
3306 (overlay-put ol2 'text-clones dups))) 3355 (overlay-put ol2 'text-clones dups)))
3307 3356
3308;;;; Misc functions moved over from the C side.
3309
3310(defun y-or-n-p (prompt)
3311 "Ask user a \"y or n\" question. Return t if answer is \"y\".
3312The argument PROMPT is the string to display to ask the question.
3313It should end in a space; `y-or-n-p' adds `(y or n) ' to it.
3314No confirmation of the answer is requested; a single character is enough.
3315Also accepts Space to mean yes, or Delete to mean no. \(Actually, it uses
3316the bindings in `query-replace-map'; see the documentation of that variable
3317for more information. In this case, the useful bindings are `act', `skip',
3318`recenter', and `quit'.\)
3319
3320Under a windowing system a dialog box will be used if `last-nonmenu-event'
3321is nil and `use-dialog-box' is non-nil."
3322 ;; ¡Beware! when I tried to edebug this code, Emacs got into a weird state
3323 ;; where all the keys were unbound (i.e. it somehow got triggered
3324 ;; within read-key, apparently). I had to kill it.
3325 (let ((answer 'recenter))
3326 (if (and (display-popup-menus-p)
3327 (listp last-nonmenu-event)
3328 use-dialog-box)
3329 (setq answer
3330 (x-popup-dialog t `(,prompt ("yes" . act) ("No" . skip))))
3331 (setq prompt (concat prompt
3332 (if (eq ?\s (aref prompt (1- (length prompt))))
3333 "" " ")
3334 "(y or n) "))
3335 (while
3336 (let* ((key
3337 (let ((cursor-in-echo-area t))
3338 (when minibuffer-auto-raise
3339 (raise-frame (window-frame (minibuffer-window))))
3340 (read-key (propertize (if (eq answer 'recenter)
3341 prompt
3342 (concat "Please answer y or n. "
3343 prompt))
3344 'face 'minibuffer-prompt)))))
3345 (setq answer (lookup-key query-replace-map (vector key) t))
3346 (cond
3347 ((memq answer '(skip act)) nil)
3348 ((eq answer 'recenter) (recenter) t)
3349 ((memq answer '(exit-prefix quit)) (signal 'quit nil) t)
3350 (t t)))
3351 (ding)
3352 (discard-input)))
3353 (let ((ret (eq answer 'act)))
3354 (unless noninteractive
3355 (message "%s %s" prompt (if ret "y" "n")))
3356 ret)))
3357
3358;;;; Mail user agents. 3357;;;; Mail user agents.
3359 3358
3360;; Here we include just enough for other packages to be able 3359;; Here we include just enough for other packages to be able
diff --git a/src/ChangeLog b/src/ChangeLog
index 12768f3578b..7fb63964b6e 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
12011-01-07 Chong Yidong <cyd@stupidchicken.com>
2
3 * fns.c (Fyes_or_no_p): Accept format string args.
4
12011-01-07 Glenn Morris <rgm@gnu.org> 52011-01-07 Glenn Morris <rgm@gnu.org>
2 6
3 * emacs.c (no_site_lisp): New int. 7 * emacs.c (no_site_lisp): New int.
diff --git a/src/fns.c b/src/fns.c
index 8d54b73586f..3282b300f49 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -2460,7 +2460,7 @@ do_yes_or_no_p (Lisp_Object prompt)
2460 2460
2461/* Anything that calls this function must protect from GC! */ 2461/* Anything that calls this function must protect from GC! */
2462 2462
2463DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, 1, 0, 2463DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, MANY, 0,
2464 doc: /* Ask user a yes-or-no question. Return t if answer is yes. 2464 doc: /* Ask user a yes-or-no question. Return t if answer is yes.
2465Takes one argument, which is the string to display to ask the question. 2465Takes one argument, which is the string to display to ask the question.
2466It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it. 2466It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it.
@@ -2469,13 +2469,11 @@ and can edit it until it has been confirmed.
2469 2469
2470Under a windowing system a dialog box will be used if `last-nonmenu-event' 2470Under a windowing system a dialog box will be used if `last-nonmenu-event'
2471is nil, and `use-dialog-box' is non-nil. */) 2471is nil, and `use-dialog-box' is non-nil. */)
2472 (Lisp_Object prompt) 2472 (int nargs, Lisp_Object *args)
2473{ 2473{
2474 register Lisp_Object ans; 2474 register Lisp_Object ans;
2475 Lisp_Object args[2];
2476 struct gcpro gcpro1; 2475 struct gcpro gcpro1;
2477 2476 Lisp_Object prompt = Fformat (nargs, args);
2478 CHECK_STRING (prompt);
2479 2477
2480#ifdef HAVE_MENUS 2478#ifdef HAVE_MENUS
2481 if (FRAME_WINDOW_P (SELECTED_FRAME ()) 2479 if (FRAME_WINDOW_P (SELECTED_FRAME ())
@@ -2496,10 +2494,7 @@ is nil, and `use-dialog-box' is non-nil. */)
2496 } 2494 }
2497#endif /* HAVE_MENUS */ 2495#endif /* HAVE_MENUS */
2498 2496
2499 args[0] = prompt; 2497 prompt = concat2 (prompt, build_string ("(yes or no) "));
2500 args[1] = build_string ("(yes or no) ");
2501 prompt = Fconcat (2, args);
2502
2503 GCPRO1 (prompt); 2498 GCPRO1 (prompt);
2504 2499
2505 while (1) 2500 while (1)