From 393038643a5dee5adc0d7c084e0a669ffc404269 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Mon, 1 Jul 2024 04:09:23 +0100 Subject: (Emacs/elisp)~better-mode-line now ignores margins (window-width) cares about margins which isn't nice for padding computations, so I made a function for computing padding sizes including margins. --- Emacs/.config/emacs/elisp/better-mode-line.el | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'Emacs/.config/emacs/elisp') diff --git a/Emacs/.config/emacs/elisp/better-mode-line.el b/Emacs/.config/emacs/elisp/better-mode-line.el index a5cce16..fd29614 100644 --- a/Emacs/.config/emacs/elisp/better-mode-line.el +++ b/Emacs/.config/emacs/elisp/better-mode-line.el @@ -51,12 +51,20 @@ the first character of the evil state capitalised" (defconst +better-mode-line/--minimum-padding 4 "Minimum size of padding string.") +(defun +better-mode-line/--get-padding-size (centre-size other-size) + (let* ((win-width (window-width)) + (margins (window-margins)) + (width (if (null (car margins)) + win-width + (+ (car margins) win-width (cdr margins))))) + (- (/ width 2) (/ centre-size 2) other-size))) + (defun +better-mode-line/--left->centre-padding () "Returns a string which pads the centre segment perfectly relative to the left segment." (let* ((left-segment-size (length (format-mode-line +better-mode-line/left-segment))) (centre-segment-size (length (format-mode-line +better-mode-line/centre-segment))) - (padding-size (- (/ (window-width) 2) (/ centre-segment-size 2) left-segment-size))) + (padding-size (+better-mode-line/--get-padding-size centre-segment-size left-segment-size))) (make-string (if (< padding-size +better-mode-line/--minimum-padding) +better-mode-line/--minimum-padding padding-size) @@ -67,7 +75,7 @@ to the left segment." to the centre segment" (let* ((centre-segment-size (length (format-mode-line +better-mode-line/centre-segment))) (right-segment-size (length (format-mode-line +better-mode-line/right-segment))) - (padding-size (- (/ (window-width) 2) (/ centre-segment-size 2) right-segment-size))) + (padding-size (+better-mode-line/--get-padding-size centre-segment-size right-segment-size))) (make-string (if (< padding-size +better-mode-line/--minimum-padding) +better-mode-line/--minimum-padding padding-size) -- cgit v1.2.3-13-gbd6f