[StumpWM] Better mode-line formatting handling

This commit is contained in:
Lucien Cartier-Tilet 2021-11-23 14:56:16 +01:00
parent fa9767ec19
commit 27fdcac542
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -494,6 +494,15 @@ the font I am using (see §[[#Theme-Fonts-28pc8141v5j0]]).
: (("%g") ("%W") ("^>") ("mu-unread" . t) ("%m") ("%I") ("%l") ("%C") ("%M") ("%B") ("%d")) : (("%g") ("%W") ("^>") ("mu-unread" . t) ("%m") ("%I") ("%l") ("%C") ("%M") ("%B") ("%d"))
#+begin_src lisp :noweb yes #+begin_src lisp :noweb yes
(defvar *mode-line-formatter-list*
'<<modeline-format-gen()>>
"List of formatters for the modeline.")
#+end_src
As you can see, ~generate-modeline~ generates the string defining
~*screen-mode-line-format*~ from the list of formatters we gave it with
the table [[modeline-format]].
#+begin_src lisp
(defun generate-modeline (elements &optional not-invertedp) (defun generate-modeline (elements &optional not-invertedp)
"Generate a modeline for StumpWM. "Generate a modeline for StumpWM.
ELEMENTS should be a list of `cons'es which `car' is the modeline ELEMENTS should be a list of `cons'es which `car' is the modeline
@ -517,20 +526,21 @@ when the `car' is a formatter and t when it is a shell command."
`(:eval (run-shell-command ,formatter t)) `(:eval (run-shell-command ,formatter t))
(format nil "~A" formatter)) (format nil "~A" formatter))
(generate-modeline (cdr elements) (not not-invertedp))))))) (generate-modeline (cdr elements) (not not-invertedp)))))))
#+end_src
It is then easy to define a command that can call this function and
set this variable so we can sort of reload the mode-line.
#+begin_src lisp
(defcommand reload-modeline () () (defcommand reload-modeline () ()
"Reload modeline." "Reload modeline."
(setf *screen-mode-line-format* (setf *screen-mode-line-format*
(cdr (generate-modeline '<<modeline-format-gen()>>)))) (cdr (generate-modeline *mode-line-formatter-list*))))
(reload-modeline)
#+end_src #+end_src
This variable as you can see is a list of elements, although here I am And actually, lets reload the modeline immediately.
only using one string. But it is absolutely possible to insert some #+begin_src lisp
CLisp code in here that returns some string if the user needs some (reload-modeline)
code to return data that cannot be easily accesible otherwise. I might #+end_src
add some at some point, but not today yet.
** TODO Investigate why ~stumptray~ acts up :noexport: ** TODO Investigate why ~stumptray~ acts up :noexport:
:PROPERTIES: :PROPERTIES: