From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#45502: [PATCH] Prettier key bindings in NS menu entries Date: Mon, 28 Dec 2020 18:36:05 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20441"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 45502@debbugs.gnu.org To: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 28 19:37:22 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 1ktxOT-0005Bt-Gp for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 28 Dec 2020 19:37:21 +0100 Original-Received: from localhost ([::1]:53218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ktxOS-0002M9-Hn for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 28 Dec 2020 13:37:20 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ktxOA-0002Ly-1i for bug-gnu-emacs@gnu.org; Mon, 28 Dec 2020 13:37:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53563) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ktxO9-00053l-Pf for bug-gnu-emacs@gnu.org; Mon, 28 Dec 2020 13:37:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ktxO9-0000o0-Ko for bug-gnu-emacs@gnu.org; Mon, 28 Dec 2020 13:37:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 28 Dec 2020 18:37:01 +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.16091805823045 (code B ref 45502); Mon, 28 Dec 2020 18:37:01 +0000 Original-Received: (at 45502) by debbugs.gnu.org; 28 Dec 2020 18:36:22 +0000 Original-Received: from localhost ([127.0.0.1]:36875 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ktxNV-0000n3-TB for submit@debbugs.gnu.org; Mon, 28 Dec 2020 13:36:22 -0500 Original-Received: from outbound.soverin.net ([116.202.65.218]:44903) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ktxNR-0000mn-Mq for 45502@debbugs.gnu.org; Mon, 28 Dec 2020 13:36:19 -0500 Original-Received: from smtp.soverin.net (unknown [10.10.3.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by outbound.soverin.net (Postfix) with ESMTPS id 2A5066020F; Mon, 28 Dec 2020 18:36:11 +0000 (UTC) Original-Received: from smtp.soverin.net (smtp.soverin.net [159.69.232.142]) by soverin.net DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=idiocy.org; s=soverin; t=1609180570; bh=vkVoFvKS31R+ad1MbwOh9QBkJNxbn2CIRlBMCZB2dwI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NWHVnRtgU8qW+UyVOLDNMmQplw3MZTm+VLXcDIIskZMptXFCC9ozXlZ5kAs6h09wQ MhS4HEl/nX+c6Oe58rQBJTDybPs79Dbog/kmFMiiHLpPGZLKcf1NgT5XP3GN6kTNfP xBID4XJtP7v1lHOKsTQUc4lCV3axTijCNTxoch/llymXzHFatrEEgE1DPNziLHJcuD 0riloXOyn9uVkKv5u2vPrGzCjAB9sel3TEP4Ksr8s0ZFjpZgO6tRIivl/H6IaQP0ax eXZyczMMLu292Nu9wTf31ddz/3ClXT/1Y6zgfD5GMcKdRpWJZ6rHiUSRp6J5vB5DeQ EfhgUspjgwJfQ== Original-Received: by breton.holly.idiocy.org (Postfix, from userid 501) id 53648202945628; Mon, 28 Dec 2020 18:36:05 +0000 (GMT) Mail-Followup-To: Alan Third , Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , 45502@debbugs.gnu.org Content-Disposition: inline In-Reply-To: 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:196888 Archived-At: On Mon, Dec 28, 2020 at 03:23:25PM +0100, Mattias Engdegård wrote: > The NS port shows key bindings in a rather cluttered way, with the > key in brackets directly after the menu entry. The Mac port of Emacs > is much neater with the bindings all aligned at a common tab > position. We could do the same, but having done some experiments I > actually prefer a right-alignment of the keys. Proof-of-concept > patch attached. > > The alignment is made by padding with spaces, and then with hair > spaces for extra precision; the result is not perfect but probably > better than what we have now. If I get some time, I might do an > experiment with more precise formatting. > > > I'd wondered about using NSAttributedString and NSParagraphStyle to > > set a tab stop at a specific pixel point, that should allow perfect > > alignment, or, and this is a bit hackier, display the binding in a > > monospace font. Then you could use (variable space font) spaces and > > tabs to line up the start of the binding text, then use (monospace > > font) spaces to align the bindings. That's maybe a bit too much work, > > though, and I'm not at all knowledgeable about how NSAttributedStrings > > actually work, so maybe it's impossible. > > It didn't look obvious how to do it, but I could use some help. I'm not sure either, but I guess the tabstop thing would look something like: NSMutableParagraphStyle *p = [NSMutableParagraphStyle defaultParagraphStyle]; NSArray *tabstops = [NSArray withObject:[[[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentRight location:50 // This is probably in points. options:nil]; [p setTabStops:tabstops]; NSAttributedString *s = [[NSAttributedString alloc] initWithString:yourString attributes:someDictionaryObjectIncludingTheParagraphStyle]; [releaseAllTheAllocedObjects]; I can never remember how to make dictionaries, so I'll leave that to you to work out. ;) Hopefully then all you have to do is set the string as the title and it will be drawn with the correct tabstop. Maybe NSMenuItems are special and it won't work, though. -- Alan Third