2

I use pywal on Linux which is really cool and works on everything I use except for Firefox (gotta tinker with it) and (GTK) Emacs.
For Emacs the author recommends this which is awesome but requires me to restart Emacs whenever I change my wallpaper (and my global colorscheme).
For terminal Neovim with the wal vim theme it just works, I reload my colorscheme and wallpaper and the terminal AND Neovim change colors, but for Emacs I must restart it for it to use the new .Xresources, which is a PITA since I use Spacemacs.
Now I'd like to know if there's any way at all to make Emacs reload it's .Xresources data on the fly (if there isn't any way then I'll seriously consider switching full-time to Neovim because with some configuration it can be really, really good. One thing I really like about it is the terminal, lightyears better than ansi-term)

0

PART-1: modifying xresources-theme.el

The problem with xresources-theme.el is that it uses x-get-resource to get the Xresources colors and it doesn't refresh (even if .Xresources has been updated using xrdb) until emacs is closed and restarted.

So my solution relies on parsing .Xresources file directly. To do this replace the function xresources-theme-color in xresources-theme.el with the following:

(defun xresources-theme-color (name)
  "Read the color NAME (e.g. color5) from the X resources."
  (shell-command-to-string (format
                "xrdb -q | grep \"%s\" | awk '{print $2}' | tr -d \"\\n\""
                   (concat "*\\(.*\\)" name ":")))
  )

Now you can reload the xresources-theme.el using M-x load-file /path/to/file/xresource-theme.el.

(CAUTION: The above code uses grep which can be tricky as different users have different styles while writing .Xresources and grep can end up matching to something not intended. So you would have to customize the grep part in a manner that is appropriate for your .Xresources. Also, I will like to hear about any ideas you have about how to make grep command more universal in above.)

PART-2: (optional) using SIGUSR1 for hot-reloading xresources-theme.el

Add the following to your .emacs

;; SIGUSR1 to reload config files
(defun sigusr1-handler ()
  (interactive)
  (load "xresources-theme.el"))
(define-key special-event-map [sigusr1] 'sigusr1-handler)

Now you can hot-reload xresoures-theme.el by executing kill -USR1 $(pgrep emacs) at bash prompt.

(One takes a similar approach to reload the config for URxvt as in this github-project.)

(CAUTION: Sane thing to do: make sure you have (add-to-list 'load-path "~/path/to/xresources-theme")in your .emacs)

PART-3: (optional) suggested workflow

I would recommend creating a bash script called apply-themes.sh with the content:

#!/bin/bash

xrdb .Xresources 
kill -1 $(pgrep urxvt)
kill -USR1 $(pgrep emacs)

and use it to update your .Xresources so that URxvt and emacs get updated along with it as well. If you use pywal or similar you could still adapt your workflow to accomodate the above.

Hope this helps. Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.