aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaúl Benencia <id@rbenencia.name>2024-10-28 08:25:22 -0700
committerRaúl Benencia <id@rbenencia.name>2024-10-28 08:25:22 -0700
commited2c73a9ef5fee74fc6c0c3f6dee176e9f2bdee9 (patch)
tree48bd6e8741b0497283c6d68b3423f9c2af5d6ec5
parent2b46480d66e0b3f26e19a4d12cd5236e43bb9817 (diff)
emacs: add rul-themes to literate config
-rw-r--r--.emacs.d/init.el3
-rw-r--r--.emacs.d/rul-emacs.org76
-rw-r--r--.emacs.d/rul-lisp/packages/rul-themes.el25
3 files changed, 87 insertions, 17 deletions
diff --git a/.emacs.d/init.el b/.emacs.d/init.el
index 8f6aa6a..7d7107d 100644
--- a/.emacs.d/init.el
+++ b/.emacs.d/init.el
@@ -56,13 +56,14 @@
(unless (server-running-p)
(server-start))
-(dolist (path '("~/.emacs.d/rul-lisp/config" "~/.emacs.d/rul-lisp/packages"))
+(dolist (path '("~/.emacs.d/rul-lisp/packages"))
(add-to-list 'load-path path))
(when-let* ((file (locate-user-emacs-file "rul-pre-init.el"))
((file-exists-p file)))
(load-file file))
+(require 'rul-themes)
(require 'rul-bindings)
(require 'rul-completion)
(require 'rul-elfeed)
diff --git a/.emacs.d/rul-emacs.org b/.emacs.d/rul-emacs.org
index 2fd6b4d..b2edae7 100644
--- a/.emacs.d/rul-emacs.org
+++ b/.emacs.d/rul-emacs.org
@@ -11,7 +11,7 @@ this file, and *not* at load time, as that would be too slow.
(org-babel-tangle)
#+end_src
-* Directory and file structure
+* Overview of files and directories
- =early-init.el=: quoting the [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Early-Init-File.html][Emacs documentation]], this file is "loaded
before the package system and GUI is initialized, so in it you can
@@ -29,7 +29,7 @@ this file, and *not* at load time, as that would be too slow.
needed in my work computer.
- =rul-emacs.org=: this file. It (will) generate the rest of the structure.
-* The early init
+* Early configuration file (=early-init.el=)
** Graphical aspects
Customization of graphical aspects of Emacs, such as size, panels, etc.
@@ -83,7 +83,7 @@ environment.
(setq inhibit-startup-echo-area-message user-login-name)
#+end_src
-* The init.el file
+* Main configuration file (=init.el=)
** Package matters
I use package from both stable and bleeding-edge Melpa.
@@ -172,13 +172,14 @@ Now, I simply start it from Emacs itself. This approach works well for me.
#+end_src
** Modules machinery
#+begin_src emacs-lisp :tangle "init.el"
-(dolist (path '("~/.emacs.d/rul-lisp/config" "~/.emacs.d/rul-lisp/packages"))
+(dolist (path '("~/.emacs.d/rul-lisp/packages"))
(add-to-list 'load-path path))
(when-let* ((file (locate-user-emacs-file "rul-pre-init.el"))
((file-exists-p file)))
(load-file file))
+(require 'rul-themes)
(require 'rul-bindings)
(require 'rul-completion)
(require 'rul-elfeed)
@@ -200,3 +201,70 @@ Now, I simply start it from Emacs itself. This approach works well for me.
;; init.el ends here
#+end_src
+
+* Modules
+I group my configuration in logical modules. In general, a module
+contains configuration for more than one package.
+
+** The =themes= module
+The =themes= module contains code pertaining to Emacs themes.
+
+#+begin_src emacs-lisp :tangle "rul-lisp/packages/rul-themes.el"
+(use-package ef-themes :ensure t)
+(use-package modus-themes
+ :ensure t
+ :config
+ (setq
+ modus-themes-mode-line '(accented borderless padded)
+ modus-themes-region '(bg-only)
+ modus-themes-bold-constructs t
+ modus-themes-italic-constructs t
+ modus-themes-paren-match '(bold intense)
+ modus-themes-headings (quote ((1 . (rainbow variable-pitch 1.3))
+ (2 . (rainbow 1.1))
+ (t . (rainbow))))
+ modus-themes-org-blocks 'tinted))
+#+end_src
+
+
+Additionally, this module subscribes to =org.freedesktop.appearance color-theme=
+to detect what color theme is preferred, and set our Emacs theme accordingly.
+
+#+begin_src emacs-lisp :tangle "rul-lisp/packages/rul-themes.el"
+(use-package dbus)
+(defun mf/set-theme-from-dbus-value (value)
+ "Set the appropiate theme according to the color-scheme setting value."
+ (message "value is %s" value)
+ (if (equal value '1)
+ (progn (message "Switch to dark theme")
+ (modus-themes-select 'modus-vivendi))
+ (progn (message "Switch to light theme")
+ (modus-themes-select 'modus-operandi))))
+
+(defun mf/color-scheme-changed (path var value)
+ "DBus handler to detect when the color-scheme has changed."
+ (when (and (string-equal path "org.freedesktop.appearance")
+ (string-equal var "color-scheme"))
+ (mf/set-theme-from-dbus-value (car value))
+ ))
+
+;; Register for future changes
+(dbus-register-signal
+ :session "org.freedesktop.portal.Desktop"
+ "/org/freedesktop/portal/desktop" "org.freedesktop.portal.Settings"
+ "SettingChanged"
+ #'mf/color-scheme-changed)
+
+;; Request the current color-scheme
+(dbus-call-method-asynchronously
+ :session "org.freedesktop.portal.Desktop"
+ "/org/freedesktop/portal/desktop" "org.freedesktop.portal.Settings"
+ "Read"
+ (lambda (value) (mf/set-theme-from-dbus-value (caar value)))
+ "org.freedesktop.appearance"
+ "color-scheme"
+ )
+
+
+(provide 'rul-themes)
+#+end_src
diff --git a/.emacs.d/rul-lisp/packages/rul-themes.el b/.emacs.d/rul-lisp/packages/rul-themes.el
index f3df8a8..2c696ec 100644
--- a/.emacs.d/rul-lisp/packages/rul-themes.el
+++ b/.emacs.d/rul-lisp/packages/rul-themes.el
@@ -1,16 +1,17 @@
-(use-package modus-themes :ensure t)
(use-package ef-themes :ensure t)
-
-(setq
- modus-themes-mode-line '(accented borderless padded)
- modus-themes-region '(bg-only)
- modus-themes-bold-constructs t
- modus-themes-italic-constructs t
- modus-themes-paren-match '(bold intense)
- modus-themes-headings (quote ((1 . (rainbow variable-pitch 1.3))
- (2 . (rainbow 1.1))
- (t . (rainbow))))
- modus-themes-org-blocks 'tinted)
+(use-package modus-themes
+ :ensure t
+ :config
+ (setq
+ modus-themes-mode-line '(accented borderless padded)
+ modus-themes-region '(bg-only)
+ modus-themes-bold-constructs t
+ modus-themes-italic-constructs t
+ modus-themes-paren-match '(bold intense)
+ modus-themes-headings (quote ((1 . (rainbow variable-pitch 1.3))
+ (2 . (rainbow 1.1))
+ (t . (rainbow))))
+ modus-themes-org-blocks 'tinted))
(use-package dbus)
(defun mf/set-theme-from-dbus-value (value)
nihil fit ex nihilo