config: add theme toggling to doom emacs

This commit is contained in:
xeruf 2022-06-27 11:55:43 +02:00
parent f6055fd6c3
commit 8c2c5c49ca
2 changed files with 18 additions and 3 deletions

View File

@ -22,8 +22,19 @@
doom-font (font-spec :family "monospace" :size 24 :weight 'semi-light)
doom-variable-pitch-font (font-spec :family "sans" :size 24))
; TODO how to treat sequencep as string? - theme toggle
;(s-chop-suffixes '("-light" "-dark") doom-theme)
(defun load-theme-string (theme)
(if (-contains? (custom-available-themes) (intern theme)) (load-theme (intern theme))))
(defun toggle-theme (&optional suffix)
"Heuristically toggle between light and dark themes."
(interactive)
(let* ((theme (s-replace-all '(("light" . "dark") ("dark" . "light")
("black" . "white") ("white" . "black")
("day" . "night") ("night" . "day"))
(symbol-name doom-theme)))
(theme-base (s-replace-regexp "-[^-]*$" "" theme)))
(or (if suffix (or (load-theme-string (concat theme "-" suffix)) (load-theme-string (concat theme-base "-" suffix)))) (load-theme-string (if (and (not suffix) (equal theme (symbol-name doom-theme))) (concat theme "-light") theme)) (load-theme-string theme-base))
)
)
(setq display-line-numbers-type 'relative
scroll-margin 6

View File

@ -40,7 +40,8 @@ test "$XDG_CURRENT_DESKTOP" = "KDE" || return 0
# Fix errors regarding broken mim database
alias fixmime='sudo rm /usr/share/mime/packages/kde.xml && sudo update-mime-database /usr/share/mime'
# Switch theme across KDE system and taskwarrior
# Switch theme across system: KDE, Konsole, taskwarrior, bat
# WIP: Emacs, Mozilla, diffr (git pager)
theme_save="$XDG_CACHE_HOME/theme"
#theme_default="$(d=$(date +%H) && test $d -gt 7 && test $d -lt 19 && echo light || echo dark)"
theme_default="dark"
@ -50,6 +51,9 @@ theme() {
then kcmshell5 kcm_lookandfeel
elif test "$theme" != "$THEME" -a "$2" != "q"
then kcmshell5 kcm_lookandfeel &
# TODO theme diffr
bak $XDG_CONFIG_HOME/git/diffr
emacsclient -e "(toggle-theme \"$theme\")"
fi
export THEME="$theme"
echo "$theme">"$theme_save"