all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#62606: [PATCH] function to align mode-line elements to right
@ 2023-04-01 22:27 hugo
  2023-04-02  5:47 ` Eli Zaretskii
                   ` (3 more replies)
  0 siblings, 4 replies; 24+ messages in thread
From: hugo @ 2023-04-01 22:27 UTC (permalink / raw)
  To: 62606

[-- Attachment #1: Type: text/plain, Size: 668 bytes --]

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>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Support-right-align-in-mode-line.patch --]
[-- Type: text/x-diff; name=0001-Support-right-align-in-mode-line.patch, Size: 2418 bytes --]

From 194ead37193a134040ac3f907199cbae2057efbb Mon Sep 17 00:00:00 2001
From: Hugo Heagren <hugo@heagren.com>
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


^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2024-01-21 10:39 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-01 22:27 bug#62606: [PATCH] function to align mode-line elements to right hugo
2023-04-02  5:47 ` Eli Zaretskii
2023-05-06 14:14   ` hugo
2023-05-06 14:39     ` Eli Zaretskii
2023-06-05 20:45       ` hugo
2023-06-06 11:24         ` Eli Zaretskii
2023-06-09 12:47           ` hugo
2023-06-09 13:13             ` Eli Zaretskii
     [not found]               ` <f60acc21a937b413f6528264f233ebfe@heagren.com>
2023-06-09 14:52                 ` Eli Zaretskii
2023-04-02 16:19 ` Juri Linkov
2023-06-09 16:03 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-09 16:17   ` Eli Zaretskii
2023-06-09 16:52     ` bug#62606: R2L modelines (was: bug#62606: [PATCH] function to align mode-line elements to right) Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-19 19:06   ` bug#62606: [PATCH] function to align mode-line elements to right hugo
2023-06-24 12:05     ` Eli Zaretskii
2023-06-26 10:06       ` hugo
2023-06-26 11:55         ` Eli Zaretskii
2023-07-02 12:43           ` hugo
2023-07-06  7:35             ` Eli Zaretskii
     [not found] ` <handler.62606.D62606.168862894016990.notifdone@debbugs.gnu.org>
2023-07-14 16:37   ` Juri Linkov
2023-07-17 17:56     ` Juri Linkov
     [not found]       ` <CALDnm53v4O9cYcYwcqGpYVb4xVOw6t+FM1xX21k7HFxWyuiSaQ@mail.gmail.com>
     [not found]         ` <83fryrs1l8.fsf@gnu.org>
     [not found]           ` <87edebjcku.fsf@gmail.com>
     [not found]             ` <835xznro5i.fsf@gnu.org>
2024-01-21 10:20               ` João Távora
2024-01-21 10:27                 ` Eli Zaretskii
2024-01-21 10:39                   ` João Távora

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.