From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#13177: 24.3.50; doc of `read-char-by-name' Date: Sun, 16 Dec 2012 11:12:04 +0200 Organization: JURTA Message-ID: <8738z6r8pj.fsf@mail.jurta.org> References: <4AF22BD1F38E4AF2A650D1F537B47069@us.oracle.com> <8762431shy.fsf@mail.jurta.org> <9D74DAC118B44C3DAF75A8CFC6AE7FB3@us.oracle.com> <156AF208FCA440DDB10CA4CFBF2815AF@us.oracle.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1355650504 7230 80.91.229.3 (16 Dec 2012 09:35:04 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 16 Dec 2012 09:35:04 +0000 (UTC) Cc: 13177@debbugs.gnu.org To: "Drew Adams" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Dec 16 10:35:18 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TkAcs-0008Lr-KJ for geb-bug-gnu-emacs@m.gmane.org; Sun, 16 Dec 2012 10:35:14 +0100 Original-Received: from localhost ([::1]:34948 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkAcf-0000gi-Ek for geb-bug-gnu-emacs@m.gmane.org; Sun, 16 Dec 2012 04:35:01 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:38980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkAca-0000bZ-7L for bug-gnu-emacs@gnu.org; Sun, 16 Dec 2012 04:34:58 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TkAcZ-0000MM-0d for bug-gnu-emacs@gnu.org; Sun, 16 Dec 2012 04:34:56 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:34401) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkAcY-0000MI-TR for bug-gnu-emacs@gnu.org; Sun, 16 Dec 2012 04:34:54 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TkAde-00080e-VR for bug-gnu-emacs@gnu.org; Sun, 16 Dec 2012 04:36:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 16 Dec 2012 09:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13177 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 13177-submit@debbugs.gnu.org id=B13177.135565050230709 (code B ref 13177); Sun, 16 Dec 2012 09:36:02 +0000 Original-Received: (at 13177) by debbugs.gnu.org; 16 Dec 2012 09:35:02 +0000 Original-Received: from localhost ([127.0.0.1]:44649 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TkAcf-0007zE-U1 for submit@debbugs.gnu.org; Sun, 16 Dec 2012 04:35:02 -0500 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:39413 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TkAcd-0007yj-4H for 13177@debbugs.gnu.org; Sun, 16 Dec 2012 04:35:00 -0500 Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id D16F5451E1C8; Sun, 16 Dec 2012 01:33:48 -0800 (PST) In-Reply-To: <156AF208FCA440DDB10CA4CFBF2815AF@us.oracle.com> (Drew Adams's message of "Sat, 15 Dec 2012 15:39:29 -0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:68594 Archived-At: > Great. That's what I would prefer also. And that was exactly what > I said in the original bug report: that's what the other `read*' > functions do: return the thing their names say they read. `read-char' says it reads a character but it returns 0 (^@) for invalid characters. I see no reason why 0 would be better than nil. Using an arbitrary character ^@ for invalid characters makes no sense. Try to eval (insert-char (read-char)) and type `C-SPC'. It inserts the character ^@ with the value 0. Typing `C-M-SPC' reports: (wrong-type-argument characterp 134217728) Clicking a mouse button reports in the echo area: "Non-character input-event" This exhibits three different types of error processing for invalid characters. I think that displaying "Non-character input-event" in the echo area is the most reasonable and user-friendly. > So we start with a code bug - make sure it always returns a char. > Then we fix the doc. > Anyway, FWIW you've got my vote in favor of fixing the code > to always return a char. Also in bug#13195 the same request: > Seems like `read-char-by-name' should always return something > that `insert-char' can use, i.e., something that passes `characterp'. Yes, to always return a valid char or nil, we could check for `characterp' like in the patch below. So when you type `C-x 8 RET #10r1111111111 RET' it will report in the echo area: "You did not specify a valid character" IMO, this is a sufficient error processing, no? === modified file 'lisp/international/mule-cmds.el' --- lisp/international/mule-cmds.el 2012-12-15 13:07:58 +0000 +++ lisp/international/mule-cmds.el 2012-12-16 09:06:59 +0000 @@ -2944,7 +2944,10 @@ (defun read-char-by-name (prompt) This function also accepts a hexadecimal number of Unicode code point or a number in hash notation, e.g. #o21430 for octal, -#x2318 for hex, or #10r8984 for decimal." +#x2318 for hex, or #10r8984 for decimal. + +When input is neither a known Unicode name nor a hex number +that specifies a valid character, return nil." (let* ((enable-recursive-minibuffers t) (input (completing-read @@ -2953,14 +2956,16 @@ (defun read-char-by-name (prompt) (let ((completion-ignore-case t)) (if (eq action 'metadata) '(metadata (category . unicode-name)) - (complete-with-action action (ucs-names) string pred))))))) - (cond - ((string-match-p "\\`[0-9a-fA-F]+\\'" input) - (string-to-number input 16)) - ((string-match-p "\\`#" input) - (read input)) - (t - (cdr (assoc-string input (ucs-names) t)))))) + (complete-with-action action (ucs-names) string pred)))))) + (character + (cond + ((string-match-p "\\`[0-9a-fA-F]+\\'" input) + (string-to-number input 16)) + ((string-match-p "\\`#" input) + (read input)) + (t + (cdr (assoc-string input (ucs-names) t)))))) + (and (characterp character) character))) (define-obsolete-function-alias 'ucs-insert 'insert-char "24.3") (define-key ctl-x-map "8\r" 'insert-char)