From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.bugs Subject: bug#30458: 26.0; `ucs-names': No reverse lookup function now Date: Wed, 14 Feb 2018 09:41:10 -0800 (PST) Message-ID: <35ab0734-9032-4331-90e8-825f58fba059@default> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1518630101 20773 195.159.176.226 (14 Feb 2018 17:41:41 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 14 Feb 2018 17:41:41 +0000 (UTC) To: 30458@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Feb 14 18:41:36 2018 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 1em13U-0003sH-WE for geb-bug-gnu-emacs@m.gmane.org; Wed, 14 Feb 2018 18:41:17 +0100 Original-Received: from localhost ([::1]:43704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1em15V-0002JJ-BU for geb-bug-gnu-emacs@m.gmane.org; Wed, 14 Feb 2018 12:43:21 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45674) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1em14I-0001cZ-7D for bug-gnu-emacs@gnu.org; Wed, 14 Feb 2018 12:42:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1em14F-0001Y4-3I for bug-gnu-emacs@gnu.org; Wed, 14 Feb 2018 12:42:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:35221) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1em14E-0001Xu-Ul for bug-gnu-emacs@gnu.org; Wed, 14 Feb 2018 12:42:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1em14E-0002sU-Km for bug-gnu-emacs@gnu.org; Wed, 14 Feb 2018 12:42:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 14 Feb 2018 17:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 30458 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.151863009511019 (code B ref -1); Wed, 14 Feb 2018 17:42:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 14 Feb 2018 17:41:35 +0000 Original-Received: from localhost ([127.0.0.1]:43118 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1em13n-0002rf-6V for submit@debbugs.gnu.org; Wed, 14 Feb 2018 12:41:35 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:54523) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1em13l-0002rQ-AB for submit@debbugs.gnu.org; Wed, 14 Feb 2018 12:41:34 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1em13f-0001Jt-7b for submit@debbugs.gnu.org; Wed, 14 Feb 2018 12:41:28 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:33727) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1em13f-0001JY-3w for submit@debbugs.gnu.org; Wed, 14 Feb 2018 12:41:27 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45481) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1em13c-0001Lw-0r for bug-gnu-emacs@gnu.org; Wed, 14 Feb 2018 12:41:26 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1em13Y-0001FU-SN for bug-gnu-emacs@gnu.org; Wed, 14 Feb 2018 12:41:24 -0500 Original-Received: from userp2120.oracle.com ([156.151.31.85]:52484) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1em13Y-0001EU-Hq for bug-gnu-emacs@gnu.org; Wed, 14 Feb 2018 12:41:20 -0500 Original-Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w1EHbu6g100029 for ; Wed, 14 Feb 2018 17:41:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : subject : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=8wl8bc4sPHo1JIswRbQ9HVN7p4G9hvetlebwebwSN5o=; b=AcM5SSZ7Cdh4NklD74qWyp4zbQjkeHCiCGH6cObmBsbMjCBO4YXc5WmAmP0E8mqh3MmF O808kQwhGdTkBM00OUaORKB49cN2jJ7v2IajCJnP3Xu26sXxJcQ4jJaJpqkgZT+YzBy6 w6DpHUlDMttCUKMD+gVTe9Np0IXYFUajOEJpm6Ewpmm3aOZV6e/B8yRVtB6dB+yhuYhb ldXktxur8/Dbdy1e8BYJSelp0ZVSe393E4qEhfUlR1COV66JWlYyE/OKcEMd9xO2uBmy 1xYM6czG3D/TodA8IdHZnPxQQlxdH6zu5QKNMLEkRrPHf86TENV917kUjZZpzr/0X9KG BQ== Original-Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2g4pqc18j4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 14 Feb 2018 17:41:13 +0000 Original-Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w1EHfBEM009272 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 14 Feb 2018 17:41:13 GMT Original-Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w1EHfBff029307 for ; Wed, 14 Feb 2018 17:41:11 GMT X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.4639.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8805 signatures=668671 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1802140207 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:143278 Archived-At: Before Emacs 26, `ucs-names' was an alist. That meant that you could not only look up a character, given its name or code, but you could also easily look up a character name, given the character: (car (rassq CHARACTER (ucs-names))) How is this done now, with (ucs-names) returning a hash table? There is now a function `char-from-name', to replace the former forward alist lookup (car (assoc CHAR-NAME (ucs-names))). But there doesn't seem to be any reverse lookup now for `ucs-names' (e.g. `char-name' or `char-name-from-char'). Seems like it should be possible to have such a reverse-lookup function for any hash table (perhaps coded in C). Sure, just like an alist, a hash table can have multiple keys that have the same value. And the order in a hash table is undefined, so when there are multiple keys for the same value, a function that gives you the key when you pass it the value can only give you one of those keys. But that might be better than nothing. Another possibility would be to have a function that returns all keys that have the same value. For example, naively (with lexical-binding): (defun get-hash-keys (value hash-table &optional value-test-function) "Return a list of keys associated with VALUE in HASH-TABLE. Optional arg VALUE-TEST-FUNCTION (default `equal') is the equality predicate used to compare values." (setq value-test-function (or value-test-function #'equal)) (let ((keys ())) (maphash (lambda (key val) (when (funcall value-test-function val value) (push key keys))) hash-table) keys)) Then: (get-hash-keys (char-from-name "GREEK SMALL LETTER LAMBDA") (ucs-names)) returns ("GREEK SMALL LETTER LAMBDA" "GREEK SMALL LETTER LAMDA"). And for example: (defun get-a-hash-key (value hash-table &optional value-test-function) "Return a hash key associated with VALUE in HASH-TABLE. If there is more than one such key then it is undefined which is returned. Optional arg VALUE-TEST-FUNCTION (default `equal') is the equality predicate used to compare values." (setq value-test-function (or value-test-function #'equal)) (catch 'get-a-hash-key (maphash (lambda (key val) (when (funcall value-test-function val value) (throw 'get-a-hash-key key))) hash-table) nil)) Then: (get-a-hash-key (char-from-name "GREEK SMALL LETTER LAMBDA") (ucs-names)) returns "GREEK SMALL LETTER LAMDA" (though one would probably prefer "GREEK SMALL LETTER LAMBDA"). For the reverse-lookup functions (reverse of `char-from-name') for a character we would have: (defun char-names (character) "Return a list of the names for CHARACTER." (get-hash-keys character (ucs-names))) (defun char-name (character) "Return a name for CHARACTER, from `ucs-names'." (get-a-hash-key character (ucs-names))) Please consider adding such reverse-lookup functions for hash tables (whether using such an implementation or something else), and adding specific such functions for `ucs-names', to accompany the forward-lookup function `char-from-name'. In GNU Emacs 26.0.91 (build 1, x86_64-w64-mingw32) of 2018-01-22 Repository revision: 752fba992b793a74d202c9cfc3e1a92fd458e748 Windowing system distributor `Microsoft Corp.', version 6.1.7601 Configured using: `configure --without-dbus --host=3Dx86_64-w64-mingw32 --without-compress-install 'CFLAGS=3D-O2 -static -g3''