Subject: bug#62606: closed (Re: bug#62606: [PATCH] function to align mode-line elements to right)

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 06 Jul 2023 07:36:02 +0000

Your bug report

#62606: [PATCH] function to align mode-line elements to right

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
62606: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=62606
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#62606: [PATCH] function to align mode-line elements to right
From: Eli Zaretskii <[email-masked]>
To: [email-masked]
Cc: [email-masked], [email-masked]
Date: Thu, 06 Jul 2023 10:35:20 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> Date: Sun, 02 Jul 2023 13:43:21 +0100
> From: [email-masked]
> Cc: [email-masked], [email-masked]
> 
> > This will need suitable additions to NEWS
> 
> New patch attached with addition to NEWS (and a version tag for the
> defcustom, which I forgot last time). I haven't marked the news item
> with +++ or ---, wasn't sure whether I've done everything I need to yet.
> 
> > and the manual
> 
> I've added documentation to the 'Mode Line Variables' section of the
> Elisp manual. This seemed to be where similar things were documented.
> Updated my commit message to reflect this.
> 
> >> I'v already assinged copyright -- I've contributed to Emacs before.
> > Yes, I see it now, sorry. (I didn't find it before because your name
> > appears in the list of assignment with a typo. Should be fixed soon.)
> 
> Do I need to update my AUTHORs entry with this new change?
> 
> Hope that's all good.

Thanks, installed on the master branch, and closing the bug.

In the future, please mention the bug number in the log message, when
that number becomes known to you (basically, if you post an updated
patch, the bug number should already be known).

Subject: [PATCH] function to align mode-line elements to right
From: [email-masked]
To: [email-masked]
Date: Sat, 01 Apr 2023 23:27:31 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

I wanted to be able to right-align some elements of the mode-line. I
used `tab-bar-format-align-right' as a base and modified it to work with
the mode-line.

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.

Patch attached. I want to know that the code is good before I do NEWS
and docs etc. Obviously it would be useful to document this in info
(elisp) Mode Line Variables and maybe in the `mode-line-format'
docstring.

Blue skies,

Hugo

[visual-fill-column-mode]
<https://codeberg.org/joostkremers/visual-fill-column>

From 194ead37193a134040ac3f907199cbae2057efbb Mon Sep 17 00:00:00 2001
From: Hugo Heagren <[email-masked]>
Date: Sat, 1 Apr 2023 22:27:25 +0100
Subject: [PATCH] Support right-align in mode-line

* lisp/bindings.el (mode-line-format-right-align):  New function.  If
the symbol `mode-line-format-right-align' appears in
`mode-line-format', then return return a padding string which aligns
everything after that symbol to the right. Padding width is altered
with the display property.
(mode-line-format-right-align):  New variable.  Convenience definition
for including right alignment in `mode-line-format'.
---
 lisp/bindings.el | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/lisp/bindings.el b/lisp/bindings.el
index 34aa8399a96..95a063fbbaf 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -304,6 +304,35 @@ mode-line-process
 ;;;###autoload
 (put 'mode-line-process 'risky-local-variable t)
 
+(defun mode-line-format-right-align ()
+  "Right-align all following mode-line constructs.
+
+When the symbol `mode-line-format-right-align' appears in
+`mode-line-format', return a string of one space, with a display
+property to make it appear long enough to align anything after
+that symbol to the right of the rendered modeline.
+
+It is important that the symbol `mode-line-format-right-align' be
+included in `mode-line-format' (and not another similar construct
+such as `(:eval (mode-line-format-right-align)'). This is because
+`mode-line-format-right-align' is processed by `format-mode-line'
+as a variable."
+  (let* ((rest (cdr (memq 'mode-line-format-right-align
+			  mode-line-format)))
+	 (rest-str (format-mode-line rest))
+	 (rest-width (string-pixel-width rest-str)))
+    (propertize " " 'display
+		;; The `right' spec doesn't work on TTY frames
+		;; when windows are split horizontally (bug#59620)
+		(if (window-system)
+		    `(space :align-to (- right-fringe (,rest-width)))
+		  `(space :align-to (,(- (window-pixel-width) rest-width)))))))
+
+(defvar mode-line-format-right-align '(:eval (mode-line-format-right-align))
+  "Mode line construct to right align all following constructs.")
+;;;###autoload
+(put 'mode-line-format-right-align 'risky-local-variable t)
+
 (defun bindings--define-key (map key item)
   "Define KEY in keymap MAP according to ITEM from a menu.
 This is like `define-key', but it takes the definition from the
-- 
2.20.1