From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: hugo@heagren.com Newsgroups: gmane.emacs.bugs Subject: bug#62606: [PATCH] function to align mode-line elements to right Date: Sat, 06 May 2023 15:14:24 +0100 Message-ID: References: <83355iygw3.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=_0c7067c861114fa75502f588fe1f6415" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24587"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Roundcube Webmail/1.6.0 Cc: 62606@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat May 06 16:15:18 2023 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 1pvIgv-0006A3-4Q for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 06 May 2023 16:15:17 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pvIgj-0005KP-Ai; Sat, 06 May 2023 10:15:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pvIgh-0005KF-5m for bug-gnu-emacs@gnu.org; Sat, 06 May 2023 10:15:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pvIgg-0007Es-Qq for bug-gnu-emacs@gnu.org; Sat, 06 May 2023 10:15:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pvIgg-0002Kl-Fa for bug-gnu-emacs@gnu.org; Sat, 06 May 2023 10:15:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: hugo@heagren.com Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 06 May 2023 14:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62606 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 62606-submit@debbugs.gnu.org id=B62606.16833824818912 (code B ref 62606); Sat, 06 May 2023 14:15:02 +0000 Original-Received: (at 62606) by debbugs.gnu.org; 6 May 2023 14:14:41 +0000 Original-Received: from localhost ([127.0.0.1]:35497 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pvIgK-0002Jf-Re for submit@debbugs.gnu.org; Sat, 06 May 2023 10:14:41 -0400 Original-Received: from whuk14.whukhost.com ([5.77.41.174]:54506) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pvIgH-0002JL-AY for 62606@debbugs.gnu.org; Sat, 06 May 2023 10:14:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=heagren.com ; s=default; h=Content-Type:Message-ID:References:In-Reply-To:Subject:Cc:To: From:Date:MIME-Version:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=WdCkDaHZuCckJwrZrbuJN7jyjMdx6PDjhKZDZbGAj/A=; b=K+sIDnS5eXEeW1Za9eMNPrUJAJ EJ4sZx+qoJd6N6EWkhFGbGTe+8d4HPcK1ViU65V1QGDpnAyoyMOQCOKXN7GX/q21qrXZIgX9yvtAh 4nfJVkwxQWR4GC9LgxfvXjwEbvMaAT2LLf9xU+89Ge0dGSYrScbEmn1tzuiE18X6b0vMysnw+0UZ2 b+x4xvyhHl5CEBkO6sHLowOw7FetVXWSpzVpkzfnNNTmlAIwlCnSUIxKvr2uac8N1bhy1gK0sIOD+ c8hoav9/smHANagFaF7LLTRaezZflZrJCFN5J7mhTUVhfuLoEascyM5U4Kpwh8JOaCCplFcGtMzYA MCUVrvWw==; Original-Received: from [::1] (port=45336 helo=whuk14.whukhost.com) by whuk14.whukhost.com with esmtpa (Exim 4.96) (envelope-from ) id 1pvIg5-00BeMP-1m; Sat, 06 May 2023 15:14:30 +0100 In-Reply-To: <83355iygw3.fsf@gnu.org> X-Sender: hugo@heagren.com X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - whuk14.whukhost.com X-AntiAbuse: Original Domain - debbugs.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - heagren.com X-Get-Message-Sender-Via: whuk14.whukhost.com: authenticated_id: hugo@heagren.com X-Authenticated-Sender: whuk14.whukhost.com: hugo@heagren.com 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:261198 Archived-At: --=_0c7067c861114fa75502f588fe1f6415 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Thanks for the feedback. A new patch is attached. > From: Eli Zaretskii > Date: Sun, 02 Apr 2023 08:47:40 +0300 > What would be the situations where the user could want this alignment? It's merely an aesthetic thing -- I just like having some of my information right-aligned. I think the motivation for the tab bar right-align function is similar? > One possible issue with right alignment is that when the total size of > the mode-line text changes (e.g., the mode lighter changes), the > leftmost part of it will move horizontally, something that could be > unpleasant and even annoying. This doesn't happen with my proposed setup (though I agree it would be annoying if it did!). The user includes the symbol `mode-line-format-right-align' in their mode line format. This is a variable which holds a mode-line construct `(:eval (mode-line-format-right-align))'. So whenever the mode-line is reloaded (and therefore, whenever the length could change), the space used to pad the right-aligned part to the right is recalculated. The only situation where this could go wrong would be if the length of the left part of the mode-line changed /during/ the process of reloading the mode-line, which seems unlikely to happen. > Also, what happens if the mode-line text is longer than the window > width. What are user expectations in that case, and does :align-to > meet those expectations? Then the text overflows to the right. The behaviour with my patch is the same as without: the text furthest to the right is not visible. The way the patch is written would mean that the padding used to align text to the right would be nil (i.e. a zero-width) string, but this is not really relevant because it won't be visible (because it will be off the right-hand edge of the screen). > > The functin aligns to the right /fringe/ rather than the margin because > > some modes (e.g. [visual-fill-column-mode]) mess around the margin size, > > but the right-align should be unaffected by this. > This detail should not be hard-coded, IMO. On reflection, I think you're right. > It should be up to the calling Lisp program (or maybe even user > option) whether the alignment is to the right margin or to the window > edge. I found this easier to implement as a user option -- I've added `mode-line-right-align-edge' to the patch. > Also, did you test this when the fringe is inside the margins and the > margins have non-zero width? Yes. It does exactly what you expect (i.e. if `mode-line-right-align-edge' is set to `right-fringe' then align to the fringe, it set to `right-margin' etc.). Setting `mode-line-right-align-edge' to `window' aligns to the right of the window even in these circumstances. > The call to string-pixel-width will significantly slow down redisplay > of the mode line. Yes, unfortunately. > I wonder whether this feature should be implemented in C instead, to > avoid the slowdown. This would be great, but I definitely don't have the skills to do it. Unless someone else does this, perhaps we could include my lisp implementation for now, document the slowness (in the docstring), and put a C implementation on the wishlist/TODO? > This should use display-graphic-p, not window-system. Fixed. > Did you test this in a session which has both GUI and TTY frames? Yes, it behaves correctly (i.e. right-aligns in both, even when the same buffer is simultaneously displayed in both). > From: Juri Linkov > Date: Sun, 02 Apr 2023 19:19:01 +0300 > Here `format-mode-line' returns an empty string when > `mode-line-format-right-align' was added in the middle of > `mode-line-format'. For a strange reason, it expects that > `mode-line-format' should start with a string. So everything is fine > after replacing in your patch Thanks for pointing this out. I've fixed it in the new patch (though my fix uses a back-quote construction, but the effect is the same). Hope the new version is better. Thoughts? --=_0c7067c861114fa75502f588fe1f6415 Content-Transfer-Encoding: base64 Content-Type: text/x-diff; name=0001-Support-right-align-in-mode-line.patch Content-Disposition: attachment; filename=0001-Support-right-align-in-mode-line.patch; size=4513 RnJvbSA3NzBlMmEwNjE3YzY1MDc1NWYxYmUzZGUxNWZmYmUxM2E5NjY0YTUzIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBIdWdvIEhlYWdyZW4gPGh1Z29AaGVhZ3Jlbi5jb20+CkRhdGU6 IFNhdCwgMSBBcHIgMjAyMyAyMjoyNzoyNSArMDEwMApTdWJqZWN0OiBbUEFUQ0hdIFN1cHBvcnQg cmlnaHQtYWxpZ24gaW4gbW9kZS1saW5lCgoqIGxpc3AvYmluZGluZ3MuZWwgKG1vZGUtbGluZS1y aWdodC1hbGlnbi1lZGdlKTogIE5ldyBjdXN0b20gdmFyaWFibGUuCkNvbnRyb2xzIHdoZXJlIGBt b2RlLWxpbmUtZm9ybWF0LXJpZ2h0LWFsaWduJyBzaG91bGQgYWxpZ24gdG8uCihtb2RlLWxpbmUt Zm9ybWF0LXJpZ2h0LWFsaWduKTogIE5ldyBmdW5jdGlvbi4gIElmIHRoZSBzeW1ib2wKYG1vZGUt bGluZS1mb3JtYXQtcmlnaHQtYWxpZ24nIGFwcGVhcnMgaW4gYG1vZGUtbGluZS1mb3JtYXQnLCB0 aGVuCnJldHVybiByZXR1cm4gYSBwYWRkaW5nIHN0cmluZyB3aGljaCBhbGlnbnMgZXZlcnl0aGlu ZyBhZnRlciB0aGF0CnN5bWJvbCB0byB0aGUgcmlnaHQuICBQYWRkaW5nIHdpZHRoIGlzIGFsdGVy ZWQgd2l0a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CkpKQor CQkgIGAoc3BhY2UgOmFsaWduLXRvICgsKC0gKHdpbmRvdy1waXhlbC13aWR0aCkKKyAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKHdpbmRvdy1zY3JvbGwtYmFyLXdpZHRo KQorICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAod2luZG93LXJpZ2h0 LWRpdmlkZXItd2lkdGgpCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICgqIChvciAoY2RyICh3aW5kb3ctbWFyZ2lucykpIDEpCisgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgIChmcmFtZS1jaGFyLXdpZHRoKSkKKyAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgOzsgTWFudWFsbHkgYWNjb3VudCBmb3IgdmFsdWUg b2YKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgOzsgYG1vZGUtbGlu ZS1yaWdodC1hbGlnbi1lZGdlJyBldmVuCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgIDs7IHdoZW4gZGlzcGxheSBpcyBub24tZ3JhcGhpY2FsCisgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgIChwY2FzZSBtb2RlLWxpbmUtcmlnaHQtYWxpZ24t ZWRnZQorICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICgob3IgJ3Jp Z2h0ICdyaWdodC1tYXJnaW4pCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgIChvciAoY2RyICh3aW5kb3ctbWFyZ2lucykpIDApKQorICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICgncmlnaHQtZnJpbmdlCisgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgIDs7IHdoYXQgaGVyZT8KKyAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKG9yIChjYWRyICh3aW5kb3ctZnJpbmdlcykp IDApKQorICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChfIDApKQor ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN0LXdpZHRoKSkpKSkp KQorCisoZGVmdmFyIG1vZGUtbGluZS1mb3JtYXQtcmlnaHQtYWxpZ24gJyg6ZXZhbCAobW9kZS1s aW5lLWZvcm1hdC1yaWdodC1hbGlnbikpCisgICJNb2RlIGxpbmUgY29uc3RydWN0IHRvIHJpZ2h0 IGFsaWduIGFsbCBmb2xsb3dpbmcgY29uc3RydWN0cy4iKQorOzs7IyMjYXV0b2xvYWQKKyhwdXQg J21vZGUtbGluZS1mb3JtYXQtcmlnaHQtYWxpZ24gJ3Jpc2t5LWxvY2FsLXZhcmlhYmxlIHQpCisK IChkZWZ1biBiaW5kaW5ncy0tZGVmaW5lLWtleSAobWFwIGtleSBpdGVtKQogICAiRGVmaW5lIEtF WSBpbiBrZXltYXAgTUFQIGFjY29yZGluZyB0byBJVEVNIGZyb20gYSBtZW51LgogVGhpcyBpcyBs aWtlIGBkZWZpbmUta2V5JywgYnV0IGl0IHRha2VzIHRoZSBkZWZpbml0aW9uIGZyb20gdGhlCi0t IAoyLjIwLjEKCg== --=_0c7067c861114fa75502f588fe1f6415--