From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#28525: 26.0.60; dired-delete-file: Accept y/n if yes-or-no-p is aliased to y-or-n-p Date: Sun, 01 Oct 2017 13:06:32 +0900 Message-ID: <87poa7tstz.fsf@gmail.com> References: <87mv5pn1dz.fsf@calancha-pc> <83zi9oeacc.fsf@gnu.org> <87tvzktk75.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1506830832 16281 195.159.176.226 (1 Oct 2017 04:07:12 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 1 Oct 2017 04:07:12 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 28525@debbugs.gnu.org, npostavs@users.sourceforge.net To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Oct 01 06:07:08 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dyVX1-0003TL-GN for geb-bug-gnu-emacs@m.gmane.org; Sun, 01 Oct 2017 06:07:07 +0200 Original-Received: from localhost ([::1]:41122 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dyVX5-0006VG-PF for geb-bug-gnu-emacs@m.gmane.org; Sun, 01 Oct 2017 00:07:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dyVWz-0006V3-LT for bug-gnu-emacs@gnu.org; Sun, 01 Oct 2017 00:07:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dyVWw-0008Fb-HO for bug-gnu-emacs@gnu.org; Sun, 01 Oct 2017 00:07:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:32978) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dyVWw-0008F8-DA for bug-gnu-emacs@gnu.org; Sun, 01 Oct 2017 00:07:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dyVWw-0007Mg-0s for bug-gnu-emacs@gnu.org; Sun, 01 Oct 2017 00:07:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 01 Oct 2017 04:07:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28525 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 28525-submit@debbugs.gnu.org id=B28525.150683081028290 (code B ref 28525); Sun, 01 Oct 2017 04:07:01 +0000 Original-Received: (at 28525) by debbugs.gnu.org; 1 Oct 2017 04:06:50 +0000 Original-Received: from localhost ([127.0.0.1]:41659 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dyVWj-0007ME-UM for submit@debbugs.gnu.org; Sun, 01 Oct 2017 00:06:50 -0400 Original-Received: from mail-pg0-f42.google.com ([74.125.83.42]:56319) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dyVWh-0007Lx-Sb for 28525@debbugs.gnu.org; Sun, 01 Oct 2017 00:06:48 -0400 Original-Received: by mail-pg0-f42.google.com with SMTP id b11so1519416pgn.12 for <28525@debbugs.gnu.org>; Sat, 30 Sep 2017 21:06:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=TxEkCqQYkMe/ATDKg0uMs5ej5/YwPslXw9pGPoYq4Ho=; b=WTLqIDIodxNCCAY24FvREYaPa+HE4O/Z6dQTPvWCz1kZRq2r2lSMG/1vpZdxdnYI9G 6ZtYfmEu3iGUPgHETWLEtzIYj+3MJ8aR3cfMoBjSereWnjapR1pc3YT2mWhJxbXVtYIl 8MnF8GMQAJ2kKItZY1g6/mGll+1w/uUTWEe/cXHqelL0/pfNZhyilSn6/B2iirPL4xyL qFl0v1uct9uIKNrMBHHMhyYTmw95JYx6dZpeMjNy2JcGlsFNgTG2qnhz02QOIT6fnfK6 /uE7Lm8fCUUV0GOcsTA3rzfNZF/VaJW3U40YQUb/ArRDQEhnz8CBz7J0F2n3dqEUHR13 GVCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=TxEkCqQYkMe/ATDKg0uMs5ej5/YwPslXw9pGPoYq4Ho=; b=I0x/kJ3fCvJJpDUrwn8Xx2RKDWs7gvg3h+k6b1YDW2V7u1h+QohrgVqDPVSSXzKasz gEwJXss1G1H6InRXYJ6GFCl/YbJTN+SE43jGs16JznV962K9E1Tgz+Fa1kMgR0irjAM5 NxAH5iJ6lN5huS1DUuSDePPcf8/so2MSqe0ZlpbIpRVioaqMtdO45yolO+NfE4Au6D3u FX4bNFV3mAn67SQobwbDnGj5RhlQbR701cVcowrK05No4LblSmJiCLUIOYehgJpqN8v5 gifi6JDz1hOOcp4CIRvUGZRKhtNGh+wd2xH43B1wCdBfbe6F2xuLkPzW44S8Zu7olooM eBRw== X-Gm-Message-State: AHPjjUj2JtqhlmL5DCm1qc9kXM8afj0J5xbVl3/NTHIJGWT8N4eLSzdc nocqbGEKb4+YQ1VwsgGDgzI= X-Google-Smtp-Source: AOwi7QBDmOO7McwAf4YBvXilfOIgsZ/E70ieGEOrEMxiClALF+O2yuViWij01zRGwQtSMayyNnl3RA== X-Received: by 10.159.211.76 with SMTP id g12mr11246689plp.312.1506830801908; Sat, 30 Sep 2017 21:06:41 -0700 (PDT) Original-Received: from calancha-pc (203.191.218.133.dy.bbexcite.jp. [133.218.191.203]) by smtp.gmail.com with ESMTPSA id m82sm12172730pfk.90.2017.09.30.21.06.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Sep 2017 21:06:40 -0700 (PDT) In-Reply-To: <87tvzktk75.fsf@gmail.com> (Tino Calancha's message of "Sat, 30 Sep 2017 22:00:46 +0900") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:137730 Archived-At: Tino Calancha writes: > In my previous patch i checked if `yes-or-no-p' is aliased to > `y-or-n-p'. > A more general way is to add new functions `yes-or-no-or-else-p', > `y-or-n-or-else-p': they ask the question and > accept additional answers according with an optional argument. Indeed, we don't need new functions just add an optional argument makes the thing (see below patch). In some cases it might be useful to allow more answers than just 'yes' or 'no'. (yes-or-no-p "Do it? ") ; Accepts 'yes' or 'no' (yes-or-no-p "Do it? " '((l . later) (m . maybe))) ;; Also accepts 'later' and 'maybe'. (y-or-n-p "Do it? " '((l . later) (m . maybe))) ;; Accepts: 'y', 'n', 'l' and 'm'. This has the advantage that is backward compatible for users doing: (fset 'yes-or-no-p 'y-or-n-p) Then, these users can use the new feature answering '!', if we write something like: (yes-or-no-p "Recursively delete dir? " '((! . all) (q . quit) (h . help))) --8<-----------------------------cut here---------------start------------->= 8--- commit 17b1d3715b3d07c487b5b9cc757fc2ce5e0a89a9 Author: Tino Calancha Date: Sun Oct 1 12:44:41 2017 +0900 Accept more answers in yes-or-no-or-else-p and y-or-n-or-else-p =20=20=20=20 * src/fns.c (yes-or-no-p) * lisp/subr.el (y-or-n-or-p): Add optional argument OTHERS. diff --git a/lisp/subr.el b/lisp/subr.el index cf15ec287f..1b11e84dd0 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2484,8 +2484,13 @@ sit-for ;; Behind display-popup-menus-p test. (declare-function x-popup-dialog "menu.c" (position contents &optional hea= der)) =20 -(defun y-or-n-p (prompt) - "Ask user a \"y or n\" question. +(defun y-or-n-p (prompt &optional others) + "Ask user a \"y or n r ...\" question. + +OTHERS is a list (INPUT . ACTION), with INPUT the user +input, and ACTION determines how to proceed; both are symbols. +For instance, SYMBOL might be '!' and ACTION 'automatic'. + Return t if answer is \"y\" and nil if it is \"n\". 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. @@ -2509,48 +2514,58 @@ y-or-n-p ;; =C2=A1Beware! when I tried to edebug this code, Emacs got into a weir= d 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) - (padded (lambda (prompt &optional dialog) - (let ((l (length prompt))) - (concat prompt - (if (or (zerop l) (eq ?\s (aref prompt (1- l)))) - "" " ") - (if dialog "" "(y or n) ")))))) + (let* ((answer 'recenter) + (options (mapcar #'car others)) + (options-str (mapconcat #'identity + (append (list "y" "n") + (mapcar (lambda (x) (symbol-name = (car x))) others)) " or ")) + (actions (append '(skip act) (mapcar #'cdr others))) + (padded (lambda (prompt &optional dialog) + (let ((l (length prompt))) + (concat prompt + (if (or (zerop l) (eq ?\s (aref prompt (1- l)))) + "" " ") + (if dialog "" (concat "(" options-str ")"))))))) (cond (noninteractive (setq prompt (funcall padded prompt)) (let ((temp-prompt prompt)) - (while (not (memq answer '(act skip))) + (while (not (memq answer actions)) (let ((str (read-string temp-prompt))) (cond ((member str '("y" "Y")) (setq answer 'act)) + ((assoc (intern str) others) (setq answer (cdr (assoc (i= ntern str) others)))) ((member str '("n" "N")) (setq answer 'skip)) - (t (setq temp-prompt (concat "Please answer y or n. " + (t (setq temp-prompt (concat "Please answer " options-str ". " prompt)))))))) ((and (display-popup-menus-p) last-input-event ; not during startup (listp last-nonmenu-event) use-dialog-box) (setq prompt (funcall padded prompt t) - answer (x-popup-dialog t `(,prompt ("Yes" . act) ("No" . skip))))) + answer + (x-popup-dialog + t + `(,prompt ("Yes" . act) ("No" . skip) + (mapcar (lambda (x) (cons (symbol-name (car x)) (cd= r x))) others))))) (t (setq prompt (funcall padded prompt)) (while (let* ((scroll-actions '(recenter scroll-up scroll-down - scroll-other-window scroll-other-window-down)) + scroll-other-window scroll-other-window-down)) (key (let ((cursor-in-echo-area t)) (when minibuffer-auto-raise (raise-frame (window-frame (minibuffer-window)))) (read-key (propertize (if (memq answer scroll-actions) prompt - (concat "Please answer y or n.= " - prompt)) + (concat "Please answer " optio= ns-str ". " 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 actions) nil) + ((member (intern (char-to-string key)) options) + (setq answer (cdr (assoc (intern (char-to-string key)) other= s))) nil) + ((eq answer 'recenter) (recenter) t) ((eq answer 'scroll-up) (ignore-errors (scroll-up-command)) t) ((eq answer 'scroll-down) @@ -2564,9 +2579,14 @@ y-or-n-p (t t))) (ding) (discard-input)))) - (let ((ret (eq answer 'act))) + (let ((ret (cond ((eq answer 'act)) + ((eq answer 'skip) nil) + ((memq answer actions) answer)))) (unless noninteractive - (message "%s%c" prompt (if ret ?y ?n))) + (message "%s%c" prompt (cond ((eq ret t) ?y) + ((null ret) ?n) + ((memq ret actions) + (string-to-char (symbol-name (car (r= assoc ret others)))))))) ret))) =20 diff --git a/src/fns.c b/src/fns.c index 4524ff9b26..a9e1a864cd 100644 --- a/src/fns.c +++ b/src/fns.c @@ -2582,20 +2582,27 @@ do_yes_or_no_p (Lisp_Object prompt) return call1 (intern ("yes-or-no-p"), prompt); } =20 -DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, 1, 0, - doc: /* Ask user a yes-or-no question. -Return t if answer is yes, and nil if the answer is no. +DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, 2, 0, + doc: /* Ask user a yes or no or ... question. +OTHERS is a list (INPUT . ACTION), with INPUT the user +input, and ACTION determines how to proceed; both are symbols. +For instance, SYMBOL might be '!' and ACTION 'automatic'. + +Return t if answer is yes, nil if the answer is no or ACTION if the answer +is ACTION. PROMPT 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. +a space; `yes-or-no-or-else-p' adds \"(yes or no or ACTION1 or ACTION2 ...= ) \" to it. =20 The user must confirm the answer with RET, and can edit it until it has been confirmed. =20 If dialog boxes are supported, a dialog box will be used -if `last-nonmenu-event' is nil, and `use-dialog-box' is non-nil. */) - (Lisp_Object prompt) +if `last-nonmenu-event' is nil, and `use-dialog-box' is non-nil. + +This function is like `yes-or-no-p' with the additional answers in OTHERS.= */) + (Lisp_Object prompt, Lisp_Object others) { - Lisp_Object ans; + Lisp_Object ans, yes_or_no, actions, str; =20 CHECK_STRING (prompt); =20 @@ -2611,9 +2618,21 @@ if `last-nonmenu-event' is nil, and `use-dialog-box'= is non-nil. */) return obj; } =20 - AUTO_STRING (yes_or_no, "(yes or no) "); - prompt =3D CALLN (Fconcat, prompt, yes_or_no); - + if (!NILP (others)) { + actions =3D Fmapcar (intern ("symbol-name"), Fmapcar (Qcdr, others)); + yes_or_no =3D Fmapconcat (Qidentity, + CALLN (Fappend, list2 (build_string ("yes"), + build_string ("no")), + actions), + build_string (" or ")); + yes_or_no =3D CALLN (Fconcat, build_string ("("), yes_or_no, build_str= ing (")")); + } + else { + actions =3D Qnil; + yes_or_no =3D build_string ("(yes or no)"); + } + prompt =3D CALLN (Fconcat, prompt, yes_or_no, build_string (" ")); + str =3D CALLN (Fconcat, build_string ("Please answer "), yes_or_no, buil= d_string (".")); while (1) { ans =3D Fdowncase (Fread_from_minibuffer (prompt, Qnil, Qnil, Qnil, @@ -2623,13 +2642,16 @@ if `last-nonmenu-event' is nil, and `use-dialog-box= ' is non-nil. */) return Qt; if (SCHARS (ans) =3D=3D 2 && !strcmp (SSDATA (ans), "no")) return Qnil; + if (!NILP (Fmember (ans, actions))) + return Fcdr (Frassoc (intern (SSDATA (ans)), others)); =20 Fding (Qnil); Fdiscard_input (); - message1 ("Please answer yes or no."); + message1 (SSDATA (str)); Fsleep_for (make_number (2), Qnil); } } + DEFUN ("load-average", Fload_average, Sload_average, 0, 1, 0, doc: /* Return list of 1 minute, 5 minute and 15 minute load averag= es. --8<-----------------------------cut here---------------end--------------->= 8--- In GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-09-30 Repository revision: 20a09de953f437109a098fa8c4d380663d921481