From b4b742cf145fd2fe66978f77540a6ae4d3f1723f Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Fri, 15 Oct 2021 14:30:41 +0200 Subject: [PATCH] [StumpWM] Simpler modeline generation --- org/config/stumpwm.org | 51 +++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/org/config/stumpwm.org b/org/config/stumpwm.org index ebdd002..94d7a62 100644 --- a/org/config/stumpwm.org +++ b/org/config/stumpwm.org @@ -441,33 +441,34 @@ the font I am using (see §[[#Theme-Fonts-28pc8141v5j0]]). : (("%g") ("%W") ("^>") ("mu-unread" . t) ("%I") ("%C") ("%M") ("%B") ("%d")) #+begin_src lisp :noweb yes +(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 +formatter or the shell command to run, and their `cdr' is either nil +when the `car' is a formatter and t when it is a shell command." + (when elements + (cons (if not-invertedp + (format nil + " ^(:fg \"~A\")^(:bg \"~A\")^f1^f0^(:fg \"~A\") " + phundrak-nord1 + phundrak-nord15 + phundrak-nord3) + (format nil + " ^(:fg \"~A\")^(:bg \"~A\")^f1^f0^** " + phundrak-nord15 + phundrak-nord1)) + (let* ((current-element (car elements)) + (formatter (car current-element)) + (commandp (cdr current-element))) + (cons (if commandp + `(:eval (run-shell-command ,formatter t)) + (format nil "~A" formatter)) + (generate-modeline (cdr elements) (not not-invertedp))))))) + (defcommand reload-modeline () () "Reload modeline." - (setq *screen-mode-line-format* nil) - (let ((invertedp nil)) - (dolist (element '<>) - (setf invertedp (not invertedp)) - (setf *screen-mode-line-format* - (cons (if invertedp - (format nil - " ^(:fg \"~A\")^(:bg \"~A\")^f1^f0^** " - phundrak-nord15 - phundrak-nord1) - (format nil - " ^(:fg \"~A\")^(:bg \"~A\")^f1^f0^(:fg \"~A\") " - phundrak-nord1 - phundrak-nord15 - phundrak-nord3)) - ,*screen-mode-line-format*)) - (let ((formatter (car element)) - (commandp (cdr element))) - (setf *screen-mode-line-format* - (cons (if commandp - `(:eval (run-shell-command ,formatter t)) - (format nil "~A" formatter)) - ,*screen-mode-line-format*))))) - (setf *screen-mode-line-format* (reverse (cons " " *screen-mode-line-format*))) - (pop *screen-mode-line-format*)) + (setf *screen-mode-line-format* + (cdr (generate-modeline '<>)))) (reload-modeline) #+end_src