diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-07-01 04:09:23 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-07-01 04:16:05 +0100 |
commit | 393038643a5dee5adc0d7c084e0a669ffc404269 (patch) | |
tree | 1e0678799dd149529abf6035443c58f492f590ac /Emacs/.config/emacs/elisp/better-mode-line.el | |
parent | 9bef5d5109926bdc1663deaf2e04a98bc86c6f10 (diff) | |
download | dotfiles-393038643a5dee5adc0d7c084e0a669ffc404269.tar.gz dotfiles-393038643a5dee5adc0d7c084e0a669ffc404269.tar.bz2 dotfiles-393038643a5dee5adc0d7c084e0a669ffc404269.zip |
(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.
Diffstat (limited to 'Emacs/.config/emacs/elisp/better-mode-line.el')
-rw-r--r-- | Emacs/.config/emacs/elisp/better-mode-line.el | 12 |
1 files changed, 10 insertions, 2 deletions
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) |