From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Matthew Mundell Newsgroups: gmane.emacs.devel Subject: Re: [matt@mundell.ukfsn.org: momentary-string-display input passing] Date: 26 Mar 2004 21:51:04 +0000 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <87k717cm5z.fsf@sno.mundell.ukfsn.org> References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1080338003 13507 80.91.224.253 (26 Mar 2004 21:53:23 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 26 Mar 2004 21:53:23 +0000 (UTC) Cc: emacs-devel Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Fri Mar 26 22:53:15 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1B6zGN-0007k4-00 for ; Fri, 26 Mar 2004 22:53:15 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1B6zGM-0004Un-00 for ; Fri, 26 Mar 2004 22:53:14 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1B6zF1-00044A-FO for emacs-devel@quimby.gnus.org; Fri, 26 Mar 2004 16:51:51 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1B6zEw-00043M-BL for emacs-devel@gnu.org; Fri, 26 Mar 2004 16:51:46 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1B6zEP-0003uo-Rw for emacs-devel@gnu.org; Fri, 26 Mar 2004 16:51:45 -0500 Original-Received: from [217.158.120.143] (helo=mail.ukfsn.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1B6zEP-0003tu-7o; Fri, 26 Mar 2004 16:51:13 -0500 Original-Received: from localhost (lucy.ukfsn.org [127.0.0.1]) by mail.ukfsn.org (Postfix) with ESMTP id A7319E6DEE; Fri, 26 Mar 2004 21:50:21 +0000 (GMT) Original-Received: from mail.ukfsn.org ([127.0.0.1]) by localhost (lucy.ukfsn.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 15341-12; Fri, 26 Mar 2004 21:50:21 +0000 (GMT) Original-Received: from sno.mundell.ukfsn.org (dsl213-218-238-16.as15444.net [213.218.238.16]) by mail.ukfsn.org (Postfix) with ESMTP id 3CAC3E6A97; Fri, 26 Mar 2004 21:50:21 +0000 (GMT) Original-Received: from sno.mundell.ukfsn.org ([10.0.0.3]) by sno.mundell.ukfsn.org with esmtp (Exim 3.36 #1 (Debian)) id 1B6zEH-0000db-00; Fri, 26 Mar 2004 21:51:05 +0000 Original-To: rms@gnu.org Original-Lines: 139 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:20979 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:20979 Richard Stallman writes: > This change looks basically reasonable to me, except I don't think > that an error is the right thing to do when the user types a function > key or clicks the mouse instead of typing the specified key. I think > those should just be ignored, the way other input characters are > ignored. > > Would someone like to make that change and install this? The change does ignore such errors. They are caught by the condition-case around read-char. A stray string in the condition case handler's body makes the handler look like a call to error. It may be that I left the string there when turning an older call to error into the condition case. A new patch and a change log are below. > From: Matthew Mundell > Subject: momentary-string-display input passing > To: emacs-pretest-bug > Date: 17 Feb 2004 23:15:12 +0000 > > The CVS Elisp manual has the following example for > momentary-string-display. > > (momentary-string-display > "**** Important Message! ****" > (point) ?\r > "Type RET when done reading") > > The idea seems to be that an Enter in response will only remove the > message. However, evaluating the form (in the CVS Emacs) and pressing > Enter in response also results in the insertion of a newline. > > The Enter key press is read with `read-event', which returns the > symbol `return', which is different from ?\r. > > Perhaps the following change to momentary-string-display will be of > help. It uses read-char when the parameter to be matched, EXIT-CHAR, > is a character. It would need additions to handle mouse events. > > =================================================================== > RCS file: /cvsroot/emacs/emacs/lisp/subr.el,v > retrieving revision 1.379 > diff -c -r1.379 subr.el > *** subr.el 16 Feb 2004 19:40:07 -0000 1.379 > - --- subr.el 17 Feb 2004 18:34:04 -0000 > *************** > *** 1455,1463 **** > (recenter 0)))) > (message (or message "Type %s to continue editing.") > (single-key-description exit-char)) > ! (let ((char (read-event))) > ! (or (eq char exit-char) > ! (setq unread-command-events (list char))))) > (if insert-end > (save-excursion > (delete-region pos insert-end))) > - --- 1455,1475 ---- > (recenter 0)))) > (message (or message "Type %s to continue editing.") > (single-key-description exit-char)) > ! (let (char) > ! (if (integerp exit-char) > ! (condition-case nil > ! (progn > ! (setq char (read-char)) > ! (or (eq char exit-char) > ! (setq unread-command-events (list char)))) > ! (error "Non-character input-event" > ! ;; character type exit-char will differ from this event > ! (setq unread-command-events (list char)))) > ! ;; assume exit-char an event > ! (setq char (read-event)) > ! (or (eq char exit-char) > ! (eq char (event-convert-list exit-char)) > ! (setq unread-command-events (list char)))))) > (if insert-end > (save-excursion > (delete-region pos insert-end))) > 2004-03-26 Matthew Mundell * subr.el (momentary-string-display): If EXIT-CHAR is a character then read input using read-char, catching any error resulting from the input of an event. Otherwise read with read-event, comparing EXIT-CHAR to the input both as a character and an event description list. Doc updated to match. =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/subr.el,v diff -u -r1.379 subr.el --- lisp/subr.el 16 Feb 2004 19:40:07 -0000 1.379 +++ lisp/subr.el 26 Mar 2004 17:08:41 -0000 @@ -1423,9 +1423,11 @@ (defun momentary-string-display (string pos &optional exit-char message) "Momentarily display STRING in the buffer at POS. -Display remains until next character is typed. -If the char is EXIT-CHAR (optional third arg, default is SPC) it is swallowed; -otherwise it is then available as input (as a command if nothing else). +Display remains until next event is input. +Optional third arg EXIT-CHAR can be a character, event or event +description list. EXIT-CHAR defaults to SPC. If the input is +EXIT-CHAR it is swallowed; otherwise it is then available as +input (as a command if nothing else). Display MESSAGE (optional fourth arg) in the echo area. If MESSAGE is nil, instructions to type EXIT-CHAR are displayed there." (or exit-char (setq exit-char ?\ )) @@ -1455,9 +1457,23 @@ (recenter 0)))) (message (or message "Type %s to continue editing.") (single-key-description exit-char)) - (let ((char (read-event))) - (or (eq char exit-char) - (setq unread-command-events (list char))))) + (let (char) + (if (integerp exit-char) + (condition-case nil + (progn + (setq char (read-char)) + (or (eq char exit-char) + (setq unread-command-events (list char)))) + (error + ;; `exit-char' is a character, hence it differs + ;; from char, which is an event. + (setq unread-command-events (list char)))) + ;; `exit-char' can be an event, or an event description + ;; list. + (setq char (read-event)) + (or (eq char exit-char) + (eq char (event-convert-list exit-char)) + (setq unread-command-events (list char)))))) (if insert-end (save-excursion (delete-region pos insert-end)))