From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.devel Subject: Re: catching keyboard-quit from read-char Date: Thu, 26 Jul 2018 13:03:55 -0700 Message-ID: <87woth3gt0.fsf@ericabrahamsen.net> References: <877eljj79j.fsf@ericabrahamsen.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1532635368 25775 195.159.176.226 (26 Jul 2018 20:02:48 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 26 Jul 2018 20:02:48 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 26 22:02:44 2018 Return-path: Envelope-to: ged-emacs-devel@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 1fimTE-0006ZJ-GP for ged-emacs-devel@m.gmane.org; Thu, 26 Jul 2018 22:02:44 +0200 Original-Received: from localhost ([::1]:37937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fimVL-0000tq-1h for ged-emacs-devel@m.gmane.org; Thu, 26 Jul 2018 16:04:55 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fimUd-0000tV-3X for emacs-devel@gnu.org; Thu, 26 Jul 2018 16:04:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fimUZ-0005hJ-3m for emacs-devel@gnu.org; Thu, 26 Jul 2018 16:04:11 -0400 Original-Received: from [195.159.176.226] (port=50503 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fimUY-0005cT-ST for emacs-devel@gnu.org; Thu, 26 Jul 2018 16:04:07 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1fimSP-0005Z7-4H for emacs-devel@gnu.org; Thu, 26 Jul 2018 22:01:53 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 41 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:vZd5dCVkuF1ADEPMTDsjS+vZ6QU= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:227841 Archived-At: Eric Abrahamsen writes: > I thought this used to work, but maybe I'm imagining things... > > I've got a macro for prompting the user for a value, but catching a > couple of signals and returning nil in those cases. It looks like: > > (defmacro ebdb-with-exit (&rest body) > "Execute BODY, returning nil on quit or an empty value." > `(condition-case-unless-debug nil > ,@body > ((quit ebdb-empty) > nil))) > > It works for `read-string', but not `read-char': > > (ebdb-with-exit (read-string "String: ")) ; C-g returns nil > (ebdb-with-exit (read-char "Character: ")) ; C-g raises an error Hmm, I guess `read-char' is a function on a different order than `read-string': the former belongs to the family of event readers, the latter to the family of minibuffer readers. Though I still don't quite understand why keyboard-quit is raised in an uncatchable fashion: it seems like either it should be raised and catchable, or else returned as a literal "C-g" key event. Interestingly, `read-char-choice' is not part of minibuffer.el, but it seems to duplicate a lot of the minibuffer work (propertizing the prompt, catching "C-g" as an key event and raising (keyboard-quit), etc). My use case above is prompting for a character to use as a register name. I guess I can just use `read-char-choice', offering as choices all the valid register keys from `register-alist'. The only downside is that if the user enters an invalid character nothing happens: there's no message indicating that they've entered an invalid character, it just sits and waits for valid input. Anyway, this was an interesting foray into event reading. Eric