(Emacs/config)~refactor better-mode-line settings

Use new namespace, move evil-state mode-line generation to personal
configuration and add (mode-line-selected-window-p) checks to hide the
left and right segment when they're not the focused window.
This commit is contained in:
2024-07-02 13:22:44 +01:00
parent 54a00ccd3d
commit 38b69af52b
2 changed files with 49 additions and 40 deletions

View File

@@ -285,8 +285,8 @@ above the minibuffer (where you do completions). It can store quite
literally anything, but generally stuff like the buffer name, file literally anything, but generally stuff like the buffer name, file
type, column and line info, etc is put there. type, column and line info, etc is put there.
The default mode-line is just... disgusting. It displays information The default mode-line is... disgusting. It displays information in an
in an unintelligible format and seems to smash together a bunch of unintelligible format and seems to smash together a bunch of
information without much care for ordering. Most heartbreaking is information without much care for ordering. Most heartbreaking is
that any mode can just insert new information onto the mode-line that any mode can just insert new information onto the mode-line
without any purview, which can be really annoying. It's also very without any purview, which can be really annoying. It's also very
@@ -301,15 +301,30 @@ the mode line to achieve this.
:load-path "elisp/" :load-path "elisp/"
:demand t :demand t
:init :init
(setq +better-mode-line/left-segment ;; LEFT SEGMENT (defun +mode-line/evil-state ()
"Returns either the empty string if no evil-state is defined or
the first character of the evil state capitalised"
(with-eval-after-load "evil"
(if (bound-and-true-p evil-state)
(upcase
(substring
(format "%s"
evil-state)
0 1))
"")))
(setq better-mode-line/left-segment ;; LEFT SEGMENT
'(" "
(:eval
(when (mode-line-window-selected-p)
'("%l:%c" ;; Line and column count '("%l:%c" ;; Line and column count
" " " "
"%p" ;; Percentage into buffer "%p" ;; Percentage into buffer
("[" ;; Evil state ("[" ;; Evil state
(:eval (:eval
(+better-mode-line/evil-state)) (+mode-line/evil-state))
"]")) "]")))))
+better-mode-line/centre-segment ;; CENTRE SEGMENT better-mode-line/centre-segment ;; CENTRE SEGMENT
'("%+" ;; Buffer state (changed or not) '("%+" ;; Buffer state (changed or not)
"%b" ;; Buffer name "%b" ;; Buffer name
("(" ;; Major mode ("(" ;; Major mode
@@ -318,7 +333,9 @@ the mode line to achieve this.
" " " "
"%I" ;; Buffer size (in bytes) "%I" ;; Buffer size (in bytes)
) )
+better-mode-line/right-segment ;; RIGHT SEGMENT better-mode-line/right-segment ;; RIGHT SEGMENT
'(:eval
(when (mode-line-window-selected-p)
'((:eval (if (project-current) ;; Name of current project (if any) '((:eval (if (project-current) ;; Name of current project (if any)
(concat (project-name (concat (project-name
(project-current)) (project-current))
@@ -327,11 +344,15 @@ the mode line to achieve this.
(:eval ;; LSP information (:eval ;; LSP information
(with-eval-after-load "eglot" (with-eval-after-load "eglot"
(if eglot--managed-mode (if eglot--managed-mode
(concat " " (eglot--mode-line-format))))) (concat
" "
(eglot--mode-line-format)))))
mode-line-misc-info ;; Any other information mode-line-misc-info ;; Any other information
)) " "
)))
)
:config :config
(+better-mode-line/setup-mode-line)) (better-mode-line/setup-mode-line))
#+end_src #+end_src
** Fringes ** Fringes
Turning off borders in my window manager was a good idea, so turn off Turning off borders in my window manager was a good idea, so turn off

View File

@@ -39,18 +39,6 @@
(defconst better-mode-line/--minimum-padding 4 (defconst better-mode-line/--minimum-padding 4
"Minimum size of padding string.") "Minimum size of padding string.")
(defun +better-mode-line/evil-state ()
"Returns either the empty string if no evil-state is defined or
the first character of the evil state capitalised"
(with-eval-after-load "evil"
(if (bound-and-true-p evil-state)
(upcase
(substring
(format "%s"
evil-state)
0 1))
"")))
(defun better-mode-line/--get-padding-size (other-size) (defun better-mode-line/--get-padding-size (other-size)
"Compute length of padding to ensure string of size OTHER is on an "Compute length of padding to ensure string of size OTHER is on an
extreme end to CENTRE-SEGMENT." extreme end to CENTRE-SEGMENT."