unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Matthew Mundell <matt@mundell.ukfsn.org>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: Improved help from minibuffer prompts
Date: 15 Apr 2004 12:42:10 +0100	[thread overview]
Message-ID: <87y8oxh3hp.fsf@sno.mundell.ukfsn.org> (raw)
In-Reply-To: w4dptacgzr0.fsf@nanni.riic.uni-linz.ac.at

[-- Attachment #1: Type: text/plain, Size: 4358 bytes --]

Stefan Reichör <xsteve@riic.at> writes:

> Hi!
> 
> I am currently working on xtla.el (the arch interface for emacs).
> 
> In my mode the user is often asked some questions in the
> minibuffer. Sometimes the questions need some more
> explanations. So I decided to put the needed help in the
> function's docstring.

Here's a function called `question' which may be of use.

It allows the responses to an interactive question to be defined,
including a help response and associated help string.  The patch
includes a change to `shell-command' to use `question', in the way
suggested for the `compile' command by Dan Jacobson (in the attached
mail).  This allows `shell-command' to start concurrent asynchronous
shell commands.

The function `may-y-or-n-p' may also be useful.

Note that `question' will need dialog popup additions to be better
analogous to yes-or-no-p.

===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/simple.el,v
retrieving revision 1.634
diff -u -r1.634 simple.el
--- lisp/simple.el	25 Mar 2004 16:01:37 -0000	1.634
+++ lisp/simple.el	15 Apr 2004 11:14:47 -0000
@@ -1227,6 +1227,62 @@
 	     '(0 . 0)))
     '(0 . 0)))
 \f
+(defvar question-history nil)
+
+(defun question (prompt &optional responses help-response)
+"Prompt with PROMPT for a response from RESPONSES.
+
+RESPONSES is an alist associating responses with returns.  Each
+member of RESPONSES is of the form (\"response\" . return).  For
+example '((\"yes\" . t) (\"no\" . n)).  The return can be
+anything except nil, which is used when searching the list.
+
+HELP-RESPONSE is a cons cell with a response as its car and a
+help string as its cdr.  If the help response is entered the
+string is displayed in the other buffer and prompting continues.
+
+If only PROMPT is given `yes-or-no-p' is called with PROMPT as
+its argument."
+  (if responses
+      (let ((options))
+	;; add alternatives to prompt
+	(let (rest (answers (if help-response
+				(append responses (list help-response))
+	
+		      responses)))
+	  (while answers
+	    (setq options
+		  (concat options
+			  (if (prog1 rest (setq rest t))
+			      (if (cdr answers)
+				  (concat ", "
+					  (car (car answers)))
+				(concat " or "
+					(car (car answers))))
+			    (car (car answers)))))
+	    (setq answers (cdr answers))))
+	(setq prompt (concat prompt "(" options ") "))
+	;; return the value associated with a prompted response
+	(cdr (let (ret rsp)
+		 (while (not
+			 (setq ret (assoc (setq rsp (read-from-minibuffer
+						     prompt nil nil nil
+						     question-history nil
+						     nil))
+					  responses)))
+		   (if (and help-response
+			    (equal rsp (car help-response)))
+		       (with-output-to-temp-buffer "*Help*"
+			 (princ (cdr help-response))
+			 (with-current-buffer standard-output
+			   (help-mode)))
+		     (ding)
+		     (discard-input)
+		     (message "Please answer %s." options)
+		     (sleep-for 2 nil)))
+		   ret)))
+    (yes-or-no-p prompt)))
+\f
 (defvar shell-command-history nil
   "History list for some commands that read shell commands.")
 
@@ -1356,9 +1412,23 @@
 		;; If will kill a process, query first.
 		(setq proc (get-buffer-process buffer))
 		(if proc
-		    (if (yes-or-no-p "A command is running.  Kill it? ")
-			(kill-process proc)
-		      (error "Shell command in progress")))
+		    (let ((res (question
+				"A command is running.  Kill it? "
+				'(("yes" . t) ("no" . no) ("r" . run))
+				'("?" . "An asynchronous command is already running in the \"*Async Shell Command*\" buffer.
+Enter
+  \"yes\"  to kill the running command, replacing it with the new one,
+  \"no\"   to quit, leaving the current command running, or
+  \"r\"    to run the new command in parallel in a uniquely-named buffer."))))
+		      (cond
+		       ((eq res 'run)
+			(setq buffer (get-buffer-create
+				      (generate-new-buffer-name
+				       (buffer-name buffer)))))
+		       ((eq res t) (kill-process proc))
+		       ((eq res 'no) (error "Shell command in progress"))
+		       ;; question-p prevents this case
+		       (t (error "Error processing response")))))
 		(with-current-buffer buffer
 		  (setq buffer-read-only nil)
 		  (erase-buffer)




[-- Attachment #2: Type: message/rfc822, Size: 3345 bytes --]

From: Dan Jacobson <jidanni@jidanni.org>
Subject: A Compilation process is running; kill it? (yes or no)
Date: Wed, 17 Mar 2004 10:13:35 +0800
Message-ID: <87vfl4jk4w.fsf@jidanni.org>

When attempting a second compilation, instead of asking
A Compilation process is running; kill it? (yes or no)
ask
A Compilation process is running;a kill it? (yes or q)
which is more telling instead of "no".  Better yet, ask
A Compilation process is running; kill it? (yes, c, q, ?)
c - launch a parallel compilation.

[-- Attachment #3: Type: text/plain, Size: 141 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/emacs-devel

  parent reply	other threads:[~2004-04-15 11:42 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-13  6:26 Improved help from minibuffer prompts Stefan Reichör
2004-04-13  6:57 ` Miles Bader
2004-04-13 10:48   ` Stefan Reichör
2004-04-14  1:22     ` Miles Bader
2004-04-14  5:35       ` Stefan Reichör
2004-04-14  6:49         ` Miles Bader
2004-04-14 10:04           ` Kim F. Storm
2004-04-14 10:39             ` Stefan Reichör
2004-04-15 16:44               ` Richard Stallman
2004-04-16  6:15                 ` Stefan Reichör
2004-04-16 10:04                   ` Kim F. Storm
2004-04-16 13:12                   ` Kai Grossjohann
2004-04-14 22:53           ` Richard Stallman
2004-04-15  1:23             ` Kim F. Storm
2004-04-16 18:08               ` Richard Stallman
2004-04-14  3:43   ` Masatake YAMATO
2004-04-14 18:02   ` Richard Stallman
2004-04-14 18:02 ` Richard Stallman
2004-04-15  5:50   ` Stefan Reichör
2004-04-16 18:07     ` Richard Stallman
2004-04-16 21:55       ` Kim F. Storm
2004-04-17 19:47         ` Richard Stallman
2004-04-19  7:51           ` Stefan Reichör
2004-04-19 11:50             ` Kim F. Storm
2004-04-29 23:48               ` Juanma Barranquero
2004-04-30  5:32                 ` Stefan Reichör
2004-04-30  9:07                   ` Juanma Barranquero
2004-05-01 17:51                     ` Richard Stallman
2004-05-01 18:33                       ` Juanma Barranquero
2004-05-02 19:52                         ` Richard Stallman
2004-05-02 22:45                           ` Juanma Barranquero
2004-05-03 22:20                             ` Richard Stallman
2004-05-06  1:08                           ` Juanma Barranquero
2004-05-06 14:13                             ` Stefan Monnier
2004-05-07  1:11                               ` Juanma Barranquero
2004-05-09  2:03                               ` Juanma Barranquero
2004-05-07  0:29                             ` Richard Stallman
2004-04-30 10:08                 ` Kim F. Storm
2004-04-30 13:39                   ` Juanma Barranquero
2004-04-30 15:50                     ` Kim F. Storm
2004-04-30 22:20                       ` Juanma Barranquero
2004-04-30 15:57                     ` Stefan Monnier
2004-04-30 21:28                       ` Juanma Barranquero
2004-04-30 22:49                         ` Stefan Monnier
2004-05-01  2:17                           ` Juanma Barranquero
2004-05-01 20:23                             ` Stefan Monnier
2004-05-02  1:52                               ` Juanma Barranquero
2004-05-04  0:32                                 ` Juanma Barranquero
2004-05-04 20:07                                   ` Richard Stallman
2004-05-04 22:52                                     ` Juanma Barranquero
2004-04-19 17:32             ` Drew Adams
2004-04-20 20:47               ` Richard Stallman
2004-04-20 23:13                 ` Drew Adams
2004-04-21  6:25                   ` Eli Zaretskii
2004-04-19 18:20             ` Richard Stallman
2004-04-16 18:07     ` Richard Stallman
2004-04-15 11:42 ` Matthew Mundell [this message]
2004-04-16  6:05   ` Stefan Reichör
2004-04-18 21:47   ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y8oxh3hp.fsf@sno.mundell.ukfsn.org \
    --to=matt@mundell.ukfsn.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).