emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r102775: Allow format args for y-or-n


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r102775: Allow format args for y-or-n-p and yes-or-no-p.
Date: Fri, 07 Jan 2011 12:34:02 -0500
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 102775
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Fri 2011-01-07 12:34:02 -0500
message:
  Allow format args for y-or-n-p and yes-or-no-p.
  
  * lisp/subr.el (y-or-n-p): Accept format string args.
  * src/fns.c (Fyes_or_no_p): Accept format string args.
modified:
  etc/NEWS
  lisp/ChangeLog
  lisp/subr.el
  src/ChangeLog
  src/fns.c
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2011-01-07 03:10:39 +0000
+++ b/etc/NEWS  2011-01-07 17:34:02 +0000
@@ -662,6 +662,8 @@
 
 * Lisp changes in Emacs 24.1
 
+** `y-or-n-p' and `yes-or-no-p' now accept format string arguments.
+
 ** `image-library-alist' is renamed to `dynamic-library-alist'.
 The variable is now used to load all kind of supported dynamic libraries,
 not just image libraries.  The previous name is still available as an

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-01-07 03:10:39 +0000
+++ b/lisp/ChangeLog    2011-01-07 17:34:02 +0000
@@ -1,3 +1,7 @@
+2011-01-07  Chong Yidong  <address@hidden>
+
+       * subr.el (y-or-n-p): Accept format string args.
+
 2011-01-07  Glenn Morris  <address@hidden>
 
        * Makefile.in (EMACSOPT): Add --no-site-lisp.

=== modified file 'lisp/subr.el'
--- a/lisp/subr.el      2010-12-15 08:16:53 +0000
+++ b/lisp/subr.el      2011-01-07 17:34:02 +0000
@@ -2011,6 +2011,55 @@
            (push read unread-command-events)
            nil))))))
 (set-advertised-calling-convention 'sit-for '(seconds &optional nodisp) "22.1")
+
+(defun y-or-n-p (prompt &rest args)
+  "Ask user a \"y or n\" question.  Return t if answer is \"y\".
+The argument PROMPT is the string to display to ask the question.
+It should end in a space; `y-or-n-p' adds `(y or n) ' to it.
+No confirmation of the answer is requested; a single character is enough.
+Also accepts Space to mean yes, or Delete to mean no.  \(Actually, it uses
+the bindings in `query-replace-map'; see the documentation of that variable
+for more information.  In this case, the useful bindings are `act', `skip',
+`recenter', and `quit'.\)
+
+Under a windowing system a dialog box will be used if `last-nonmenu-event'
+is nil and `use-dialog-box' is non-nil."
+  ;; ¡Beware! when I tried to edebug this code, Emacs got into a weird state
+  ;; 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))))
+      (setq prompt (concat (apply 'format prompt args)
+                           (if (eq ?\s (aref prompt (1- (length prompt))))
+                               "" " ")
+                           "(y or n) "))
+      (while
+          (let* ((key
+                  (let ((cursor-in-echo-area t))
+                    (when minibuffer-auto-raise
+                      (raise-frame (window-frame (minibuffer-window))))
+                    (read-key (propertize (if (eq answer 'recenter)
+                                              prompt
+                                            (concat "Please answer y or n.  "
+                                                    prompt))
+                                          'face 'minibuffer-prompt)))))
+            (setq answer (lookup-key query-replace-map (vector key) t))
+            (cond
+             ((memq answer '(skip act)) nil)
+             ((eq answer 'recenter) (recenter) t)
+             ((memq answer '(exit-prefix quit)) (signal 'quit nil) t)
+             (t t)))
+        (ding)
+        (discard-input)))
+    (let ((ret (eq answer 'act)))
+      (unless noninteractive
+        (message "%s %s" prompt (if ret "y" "n")))
+      ret)))
+
 
 ;;; Atomic change groups.
 
@@ -3305,56 +3354,6 @@
     (overlay-put ol2 'evaporate t)
     (overlay-put ol2 'text-clones dups)))
 
-;;;; Misc functions moved over from the C side.
-
-(defun y-or-n-p (prompt)
-  "Ask user a \"y or n\" question.  Return t if answer is \"y\".
-The argument PROMPT is the string to display to ask the question.
-It should end in a space; `y-or-n-p' adds `(y or n) ' to it.
-No confirmation of the answer is requested; a single character is enough.
-Also accepts Space to mean yes, or Delete to mean no.  \(Actually, it uses
-the bindings in `query-replace-map'; see the documentation of that variable
-for more information.  In this case, the useful bindings are `act', `skip',
-`recenter', and `quit'.\)
-
-Under a windowing system a dialog box will be used if `last-nonmenu-event'
-is nil and `use-dialog-box' is non-nil."
-  ;; ¡Beware! when I tried to edebug this code, Emacs got into a weird state
-  ;; 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))))
-      (setq prompt (concat prompt
-                           (if (eq ?\s (aref prompt (1- (length prompt))))
-                               "" " ")
-                           "(y or n) "))
-      (while
-          (let* ((key
-                  (let ((cursor-in-echo-area t))
-                    (when minibuffer-auto-raise
-                      (raise-frame (window-frame (minibuffer-window))))
-                    (read-key (propertize (if (eq answer 'recenter)
-                                              prompt
-                                            (concat "Please answer y or n.  "
-                                                    prompt))
-                                          'face 'minibuffer-prompt)))))
-            (setq answer (lookup-key query-replace-map (vector key) t))
-            (cond
-             ((memq answer '(skip act)) nil)
-             ((eq answer 'recenter) (recenter) t)
-             ((memq answer '(exit-prefix quit)) (signal 'quit nil) t)
-             (t t)))
-        (ding)
-        (discard-input)))
-    (let ((ret (eq answer 'act)))
-      (unless noninteractive
-        (message "%s %s" prompt (if ret "y" "n")))
-      ret)))
-
 ;;;; Mail user agents.
 
 ;; Here we include just enough for other packages to be able

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2011-01-07 03:10:39 +0000
+++ b/src/ChangeLog     2011-01-07 17:34:02 +0000
@@ -1,3 +1,7 @@
+2011-01-07  Chong Yidong  <address@hidden>
+
+       * fns.c (Fyes_or_no_p): Accept format string args.
+
 2011-01-07  Glenn Morris  <address@hidden>
 
        * emacs.c (no_site_lisp): New int.

=== modified file 'src/fns.c'
--- a/src/fns.c 2010-12-27 17:29:38 +0000
+++ b/src/fns.c 2011-01-07 17:34:02 +0000
@@ -2460,7 +2460,7 @@
 
 /* Anything that calls this function must protect from GC!  */
 
-DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, 1, 0,
+DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, MANY, 0,
        doc: /* Ask user a yes-or-no question.  Return t if answer is yes.
 Takes one argument, which is the string to display to ask the question.
 It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it.
@@ -2469,13 +2469,11 @@
 
 Under a windowing system a dialog box will be used if `last-nonmenu-event'
 is nil, and `use-dialog-box' is non-nil.  */)
-  (Lisp_Object prompt)
+  (int nargs, Lisp_Object *args)
 {
   register Lisp_Object ans;
-  Lisp_Object args[2];
   struct gcpro gcpro1;
-
-  CHECK_STRING (prompt);
+  Lisp_Object prompt = Fformat (nargs, args);
 
 #ifdef HAVE_MENUS
   if (FRAME_WINDOW_P (SELECTED_FRAME ())
@@ -2496,10 +2494,7 @@
     }
 #endif /* HAVE_MENUS */
 
-  args[0] = prompt;
-  args[1] = build_string ("(yes or no) ");
-  prompt = Fconcat (2, args);
-
+  prompt = concat2 (prompt, build_string ("(yes or no) "));
   GCPRO1 (prompt);
 
   while (1)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]