From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#45502: [PATCH] Prettier key bindings in NS menu entries Date: Wed, 30 Dec 2020 13:19:48 +0100 Message-ID: <0F1B9914-2668-4775-822A-49A36D4A9F3F@acm.org> References: <02937096-EAF5-4B74-A1C7-CCE6E64C67E3@acm.org> <99CD03DA-DF1F-4C2C-A2FA-DFD7DF3B2750@acm.org> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.17\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_A5E4FB74-4F00-4327-9160-6F58E05CDD5C" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15777"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 45502@debbugs.gnu.org, Daniel =?UTF-8?Q?Mart=C3=ADn?= To: Alan Third Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 30 13:22:07 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kuaUQ-0003yI-LG for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Dec 2020 13:22:06 +0100 Original-Received: from localhost ([::1]:60622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kuaUP-00073p-JU for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Dec 2020 07:22:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54714) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kuaSQ-0006A9-JQ for bug-gnu-emacs@gnu.org; Wed, 30 Dec 2020 07:20:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58770) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kuaSQ-0003Sa-Av for bug-gnu-emacs@gnu.org; Wed, 30 Dec 2020 07:20:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kuaSQ-0000xI-5R for bug-gnu-emacs@gnu.org; Wed, 30 Dec 2020 07:20:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 30 Dec 2020 12:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45502 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 45502-submit@debbugs.gnu.org id=B45502.16093308003661 (code B ref 45502); Wed, 30 Dec 2020 12:20:02 +0000 Original-Received: (at 45502) by debbugs.gnu.org; 30 Dec 2020 12:20:00 +0000 Original-Received: from localhost ([127.0.0.1]:42083 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kuaSO-0000wz-Hy for submit@debbugs.gnu.org; Wed, 30 Dec 2020 07:20:00 -0500 Original-Received: from mail1443c50.megamailservers.eu ([91.136.14.43]:36300 helo=mail264c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kuaSL-0000wj-Pw for 45502@debbugs.gnu.org; Wed, 30 Dec 2020 07:19:59 -0500 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1609330791; bh=OHwIVE3+uHnykNejIrArdO+eZIy9/iaf/upyW15lghM=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=d7+0UChijCiX9UnVDcl7Acf0lz3QiJ/nOKhgu8myDtjOimEMsShmkqCSNZ1TMAaBF rf/sEFCUGrj4+Szu1f9KOoznz1CBXqiUBYfp6pXoHpLrn1BCY3xNwWDNqG7/ihgJcn 2fkvKz98HTVrSZYr/Lhr0B/9pRbUCJk8gBDkRL9c= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.0.4] (c188-150-171-71.bredband.comhem.se [188.150.171.71]) (authenticated bits=0) by mail264c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 0BUCJm8x004424; Wed, 30 Dec 2020 12:19:50 +0000 In-Reply-To: X-Mailer: Apple Mail (2.3445.104.17) X-CTCH-RefID: str=0001.0A742F1E.5FEC7067.0007, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=bPlo382Z c=1 sm=1 tr=0 a=SF+I6pRkHZhrawxbOkkvaA==:117 a=SF+I6pRkHZhrawxbOkkvaA==:17 a=M51BFTxLslgA:10 a=hIj89exaAAAA:8 a=OsWix0dI85E5UVEG74cA:9 a=CjuIK1q_8ugA:10 a=jH5F5EiGhjIdZ16PmNgA:9 a=B2y7HmGcmWMA:10 a=lS9wXHQM5UdnNJ4u63Ry:22 X-Origin-Country: SE X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:197022 Archived-At: --Apple-Mail=_A5E4FB74-4F00-4327-9160-6F58E05CDD5C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 30 dec. 2020 kl. 00.49 skrev Alan Third : > I think it's maybe visually a little neater to use autorelease, but > either way works and I would probably do it the other way in different > circumstances. Feel free to change it if you want. Thanks, I'm sticking to autorelease for uniformity here; slightly = delayed deallocation is no worse than GC after all. >> Presumably 'atitle' should be sent autorelease (or release) as well? >=20 > Yes, I missed that one. And actually, I think the alloc'd NSMenuItem > on line 484 will need released too. It should probably be autoreleased > because it's returned to the calling function, and the caller can then > decide whether to retain it or not (it doesn't in this case). Yes, fixed. (By the way, 'chording' isn't quite the same as a multi-key sequence; = chords are rather simultaneous presses, like C-M-x, no? To continue a = musical metaphor, perhaps an Emacs key sequence is an arpeggio?) Here is a slightly less ugly variant of the symbol substitution patch. = Maybe we should apply it and see if there are any complaints, or if we = turn against it ourselves later on? --Apple-Mail=_A5E4FB74-4F00-4327-9160-6F58E05CDD5C Content-Disposition: attachment; filename=0001-Use-standard-key-symbols-in-NS-menu-entries.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Use-standard-key-symbols-in-NS-menu-entries.patch" Content-Transfer-Encoding: quoted-printable =46rom=207ccf892b25d04d94bdcb76dfb6a000028e7b3c2a=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Wed,=2030=20Dec=202020=2013:06:47=20+0100=0A= Subject:=20[PATCH]=20Use=20standard=20key=20symbols=20in=20NS=20menu=20= entries=0A=0A*=20src/nsmenu.m=20(skipspc):=20Remove.=0A(key_symbols,=20= prettify_key):=20New.=0A([EmacsMenu=20fillWithWidgetValue:]):=20Call=20= prettify_key.=0A---=0A=20src/nsmenu.m=20|=2070=20= ++++++++++++++++++++++++++++++++++++++++++++--------=0A=201=20file=20= changed,=2060=20insertions(+),=2010=20deletions(-)=0A=0Adiff=20--git=20= a/src/nsmenu.m=20b/src/nsmenu.m=0Aindex=2034912705e2..c124bf500d=20= 100644=0A---=20a/src/nsmenu.m=0A+++=20b/src/nsmenu.m=0A@@=20-458,14=20= +458,6=20@@=20-=20(BOOL)performKeyEquivalent:=20(NSEvent=20*)theEvent=0A=20= }=0A=20=0A=20=0A-static=20const=20char=20*=0A-skipspc=20(const=20char=20= *s)=0A-{=0A-=20=20while=20(*s=20=3D=3D=20'=20')=0A-=20=20=20=20s++;=0A-=20= =20return=20s;=0A-}=0A-=0A=20-=20(NSMenuItem=20*)addItemWithWidgetValue:=20= (void=20*)wvptr=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20attributes:=20(NSDictionary=20*)attributes=0A= =20{=0A@@=20-485,7=20+477,7=20@@=20-=20(NSMenuItem=20= *)addItemWithWidgetValue:=20(void=20*)wvptr=0A=20=20=20=20=20=20=20item=20= =3D=20[[[NSMenuItem=20alloc]=20init]=20autorelease];=0A=20=20=20=20=20=20= =20if=20(wv->key)=0A=20=20=20=20=20=20=20=20=20{=0A-=20=20=20=20=20=20=20= =20=20=20NSString=20*key=20=3D=20[NSString=20stringWithUTF8String:=20= skipspc=20(wv->key)];=0A+=20=20=20=20=20=20=20=20=20=20NSString=20*key=20= =3D=20[NSString=20stringWithUTF8String:=20wv->key];=0A=20#ifdef=20= NS_IMPL_COCOA=0A=20=20=20=20=20=20=20=20=20=20=20/*=20Cocoa=20only=20= permits=20a=20single=20key=20(with=20modifiers)=20as=0A=20=20=20=20=20=20= =20=20=20=20=20=20=20=20keyEquivalent,=20so=20we=20put=20them=20in=20the=20= title=20string=0A@@=20-537,6=20+529,63=20@@=20-(void)removeAllItems=0A=20= }=0A=20=0A=20=0A+typedef=20struct=20{=0A+=20=20const=20char=20*from,=20= *to;=0A+}=20subst_t;=0A+=0A+/*=20Standard=20keyboard=20symbols=20used=20= in=20menus.=20*/=0A+static=20const=20subst_t=20key_symbols[]=20=3D=20{=0A= +=20=20{"",=20=20"=E2=8C=AB"},=0A+=20=20{"DEL",=20=20=20=20=20= =20=20=20=20=20"=E2=8C=AB"},=0A+=20=20{"",=20"=E2=8C=A6"},=0A= +=20=20{"",=20=20=20=20=20"=E2=86=A9"},=0A+=20=20{"RET",=20=20=20= =20=20=20=20=20=20=20"=E2=86=A9"},=0A+=20=20{"",=20=20=20=20=20=20=20= "=E2=86=90"},=0A+=20=20{"",=20=20=20=20=20=20"=E2=86=92"},=0A+=20=20= {"",=20=20=20=20=20=20=20=20=20"=E2=86=91"},=0A+=20=20{"",=20=20= =20=20=20=20=20"=E2=86=93"},=0A+=20=20{"",=20=20=20=20=20=20= "=E2=87=9E"},=0A+=20=20{"",=20=20=20=20=20=20=20"=E2=87=9F"},=0A+=20= =20{"",=20=20=20=20=20=20=20"=E2=86=96"},=0A+=20=20{"",=20=20=20= =20=20=20=20=20"=E2=86=98"},=0A+=20=20{"",=20=20=20=20=20=20=20=20= "=E2=87=A5"},=0A+=20=20{"TAB",=20=20=20=20=20=20=20=20=20=20"=E2=87=A5"},=0A= +=20=20{"",=20=20=20=20"=E2=87=A4"},=0A+};=0A+=0A+/*=20= Transform=20the=20key=20sequence=20KEY=20into=20something=20prettier=20= by=0A+=20=20=20substituting=20keyboard=20symbols.=20*/=0A+static=20char=20= *=0A+prettify_key=20(const=20char=20*key)=0A+{=0A+=20=20while=20(*key=20= =3D=3D=20'=20')=20key++;=0A+=0A+=20=20int=20len=20=3D=20strlen=20(key);=0A= +=20=20char=20*buf=20=3D=20xmalloc=20(len=20+=201);=0A+=20=20memcpy=20= (buf,=20key,=20len=20+=201);=0A+=20=20for=20(int=20i=20=3D=200;=20i=20<=20= ARRAYELTS=20(key_symbols);=20i++)=0A+=20=20=20=20{=0A+=20=20=20=20=20=20= ptrdiff_t=20fromlen=20=3D=20strlen=20(key_symbols[i].from);=0A+=20=20=20=20= =20=20char=20*p=20=3D=20buf;=0A+=20=20=20=20=20=20while=20(p=20<=20buf=20= +=20len)=0A+=20=20=20=20=20=20=20=20{=0A+=20=20=20=20=20=20=20=20=20=20= char=20*match=20=3D=20memmem=20(buf,=20len,=20key_symbols[i].from,=20= fromlen);=0A+=20=20=20=20=20=20=20=20=20=20if=20(!match)=0A+=20=20=20=20=20= =20=20=20=20=20=20=20break;=0A+=20=20=20=20=20=20=20=20=20=20ptrdiff_t=20= tolen=20=3D=20strlen=20(key_symbols[i].to);=0A+=20=20=20=20=20=20=20=20=20= =20eassert=20(tolen=20<=3D=20fromlen);=0A+=20=20=20=20=20=20=20=20=20=20= memcpy=20(match,=20key_symbols[i].to,=20tolen);=0A+=20=20=20=20=20=20=20=20= =20=20memmove=20(match=20+=20tolen,=20match=20+=20fromlen,=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20len=20-=20(match=20+=20= fromlen=20-=20buf)=20+=201);=0A+=20=20=20=20=20=20=20=20=20=20len=20-=3D=20= fromlen=20-=20tolen;=0A+=20=20=20=20=20=20=20=20=20=20p=20=3D=20match=20= +=20tolen;=0A+=20=20=20=20=20=20=20=20}=0A+=20=20=20=20}=0A+=20=20= Lisp_Object=20result=20=3D=20build_string=20(buf);=0A+=20=20xfree=20= (buf);=0A+=20=20return=20SSDATA=20(result);=0A+}=0A+=0A=20-=20= (void)fillWithWidgetValue:=20(void=20*)wvptr=0A=20{=0A=20=20=20= widget_value=20*first_wv=20=3D=20(widget_value=20*)wvptr;=0A@@=20-560,7=20= +609,8=20@@=20-=20(void)fillWithWidgetValue:=20(void=20*)wvptr=0A=20=20=20= =20=20=20=20=20=20maxNameWidth=20=3D=20MAX(maxNameWidth,=20= nameSize.width);=0A=20=20=20=20=20=20=20=20=20if=20(wv->key)=0A=20=20=20=20= =20=20=20=20=20=20=20{=0A-=20=20=20=20=20=20=20=20=20=20=20=20NSString=20= *key=20=3D=20[NSString=20stringWithUTF8String:=20skipspc=20(wv->key)];=0A= +=20=20=20=20=20=20=20=20=20=20=20=20wv->key=20=3D=20prettify_key=20= (wv->key);=0A+=20=20=20=20=20=20=20=20=20=20=20=20NSString=20*key=20=3D=20= [NSString=20stringWithUTF8String:=20wv->key];=0A=20=20=20=20=20=20=20=20=20= =20=20=20=20NSSize=20keySize=20=3D=20[key=20sizeWithAttributes:=20= font_attribs];=0A=20=20=20=20=20=20=20=20=20=20=20=20=20maxKeyWidth=20=3D=20= MAX(maxKeyWidth,=20keySize.width);=0A=20=20=20=20=20=20=20=20=20=20=20}=0A= --=20=0A2.21.1=20(Apple=20Git-122.3)=0A=0A= --Apple-Mail=_A5E4FB74-4F00-4327-9160-6F58E05CDD5C--