summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornoa@gaiwan.org2024-06-15 21:08:45 +0000
committernoa@gaiwan.org2024-06-15 21:08:45 +0000
commitc92345827ebc806d0296ef722ed8459cbdd33496 (patch)
tree80807d60b605f584de2bb68872c6f62e44e67cdb
parentab3636ea0a7663b6bf894b6ef6429e2a832dc670 (diff)
Copy mode-line-format-right-align
-rw-r--r--emacs/init.el46
1 files changed, 42 insertions, 4 deletions
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."