[StumpWM] Simpler modeline generation

This commit is contained in:
Lucien Cartier-Tilet 2021-10-15 14:30:41 +02:00
parent 836441b97f
commit b4b742cf14
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -441,33 +441,34 @@ the font I am using (see §[[#Theme-Fonts-28pc8141v5j0]]).
: (("%g") ("%W") ("^>") ("mu-unread" . t) ("%I") ("%C") ("%M") ("%B") ("%d")) : (("%g") ("%W") ("^>") ("mu-unread" . t) ("%I") ("%C") ("%M") ("%B") ("%d"))
#+begin_src lisp :noweb yes #+begin_src lisp :noweb yes
(defcommand reload-modeline () () (defun generate-modeline (elements &optional not-invertedp)
"Reload modeline." "Generate a modeline for StumpWM.
(setq *screen-mode-line-format* nil) ELEMENTS should be a list of `cons'es which `car' is the modeline
(let ((invertedp nil)) formatter or the shell command to run, and their `cdr' is either nil
(dolist (element '<<modeline-format-gen()>>) when the `car' is a formatter and t when it is a shell command."
(setf invertedp (not invertedp)) (when elements
(setf *screen-mode-line-format* (cons (if not-invertedp
(cons (if invertedp
(format nil
" ^(:fg \"~A\")^(:bg \"~A\")^f1^f0^** "
phundrak-nord15
phundrak-nord1)
(format nil (format nil
" ^(:fg \"~A\")^(:bg \"~A\")^f1^f0^(:fg \"~A\") " " ^(:fg \"~A\")^(:bg \"~A\")^f1^f0^(:fg \"~A\") "
phundrak-nord1 phundrak-nord1
phundrak-nord15 phundrak-nord15
phundrak-nord3)) phundrak-nord3)
,*screen-mode-line-format*)) (format nil
(let ((formatter (car element)) " ^(:fg \"~A\")^(:bg \"~A\")^f1^f0^** "
(commandp (cdr element))) phundrak-nord15
(setf *screen-mode-line-format* phundrak-nord1))
(let* ((current-element (car elements))
(formatter (car current-element))
(commandp (cdr current-element)))
(cons (if commandp (cons (if commandp
`(:eval (run-shell-command ,formatter t)) `(:eval (run-shell-command ,formatter t))
(format nil "~A" formatter)) (format nil "~A" formatter))
,*screen-mode-line-format*))))) (generate-modeline (cdr elements) (not not-invertedp)))))))
(setf *screen-mode-line-format* (reverse (cons " " *screen-mode-line-format*)))
(pop *screen-mode-line-format*)) (defcommand reload-modeline () ()
"Reload modeline."
(setf *screen-mode-line-format*
(cdr (generate-modeline '<<modeline-format-gen()>>))))
(reload-modeline) (reload-modeline)
#+end_src #+end_src