[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"))
#+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)
"Generate a modeline for StumpWM.
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))
(format nil "~A" formatter))
(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 () ()
"Reload modeline."
(setf *screen-mode-line-format*
(cdr (generate-modeline '<<modeline-format-gen()>>))))
(reload-modeline)
(cdr (generate-modeline *mode-line-formatter-list*))))
#+end_src
This variable as you can see is a list of elements, although here I am
only using one string. But it is absolutely possible to insert some
CLisp code in here that returns some string if the user needs some
code to return data that cannot be easily accesible otherwise. I might
add some at some point, but not today yet.
And actually, lets reload the modeline immediately.
#+begin_src lisp
(reload-modeline)
#+end_src
** TODO Investigate why ~stumptray~ acts up :noexport:
:PROPERTIES: