From c92345827ebc806d0296ef722ed8459cbdd33496 Mon Sep 17 00:00:00 2001 From: noa@gaiwan.org Date: Sat, 15 Jun 2024 21:08:45 +0000 Subject: Copy mode-line-format-right-align --- emacs/init.el | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'emacs') diff --git a/emacs/init.el b/emacs/init.el index 9d84400..f548346 100644 --- a/emacs/init.el +++ b/emacs/init.el @@ -85,11 +85,49 @@ (propertize " " 'display `(space :align-to (- right ,(length right)))) right)) +;; Copy the code from mode-line-format-right-align so that i can use it. This is an emacs 30 feature, which i don't run yet. In the future, i'll be able to remove this. +(defcustom mode-line-right-align-edge 'window + :type '(choice (const right-margin) + (const right-fringe) + (const window)) + :group 'mode-line + :version "30.1") +(defun mode--line-format-right-align () + (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 (and (display-graphic-p) + (not (eq mode-line-right-align-edge 'window))) + `(space :align-to (- ,mode-line-right-align-edge + (,rest-width))) + `(space :align-to (,(- (window-pixel-width) + (window-scroll-bar-width) + (window-right-divider-width) + (* (or (cdr (window-margins)) 1) + (frame-char-width)) + ;; Manually account for value of + ;; `mode-line-right-align-edge' even + ;; when display is non-graphical + (pcase mode-line-right-align-edge + ('right-margin + (or (cdr (window-margins)) 0)) + ('right-fringe + ;; what here? + (or (cadr (window-fringes)) 0)) + (_ 0)) + rest-width))))))) +(defvar mode-line-format-right-align '(:eval (mode--line-format-right-align)) + "Mode line construct to right align all following constructs.") +(put 'mode-line-format-right-align 'risky-local-variable t) + (setq-default header-line-format - '((:eval - (mode-line-render - (format-mode-line "%b:%l,%c ") - (format-mode-line "%1*%1+%1@"))))) + '("%b:%l,%c " + mode-line-format-right-align + "%1*%1+%1@")) (defun pulse-line (&rest _) "Pulse the current line." -- cgit 1.4.1-2-gfad0