Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Conversation

ohmree
Copy link
Contributor

@ohmree ohmree commented Jul 11, 2017

I tried to add an emacs colorscheme, it's basically xresources-theme but with the xresources bits ripped out of it and replaced with pywal templates.
It does look a bit weird but it's better than no color-hot-swapping:

image

Usage is simply (load-file "~/.cache/wal/colors.el") in ielm and/or .emacs.el, M-x load-file or from the command line (can also be automated after wal is executed), something like $ emacs -batch --eval='(load-file "~/.cache/wal/colors.el")'

@dylanaraps
Copy link
Owner

Isn't this identical to the xresources-theme? (They'll both load the same color codes)

@ohmree
Copy link
Contributor Author

ohmree commented Jul 11, 2017

This can be done on the fly while hot-reloading Xresources would require forking emacs

@ohmree
Copy link
Contributor Author

ohmree commented Jul 11, 2017

As you can see this is the previous theme I had, and some of the colors stayed even after I loaded colors.el. I'll try and figure out what causes this.
image

@dylanaraps
Copy link
Owner

dylanaraps commented Jul 11, 2017

wal doesn't set {red}, {green} etc. It sets {color1}, {color2} etc. This is probably why some of the colors aren't changing.

@ohmree
Copy link
Contributor Author

ohmree commented Jul 11, 2017

Oh whoops, you're right about the color names. But I didn't use wal to create the theme in the screenshot, I used a shell script that sourced colors.sh (a temporary hack), so the names aren't the problem.

@dylanaraps
Copy link
Owner

Can you also rename the file to colors-emacs.el?

@ohmree
Copy link
Contributor Author

ohmree commented Jul 11, 2017

Hmm, I'm getting remains of the wal theme after switching to the spacemacs-dark theme. I'll try and get some help on Stack Exchange.
image

@ohmree
Copy link
Contributor Author

ohmree commented Jul 11, 2017

Something weird's going on. After switching to the spacemacs-dark theme I switched to the wal theme and it looked fine (I think, unless some of the colors were from the previous theme, then it's weird) but then I changed my wallpaper and emacs only had a consistent theme after I restarted it and loaded the new el file. Then I switched to the wal theme (turns out I wasn't using it) and it got red again (except for some parts which were behaving correctly). I'll see if anyone on Stack Exchange and /r/emacs knows what's going on

FINAL EDIT: Seems like it works perfectly in a config-less Emacs and the problem is with Spacemacs.

@dylanaraps
Copy link
Owner

I don't think that we should add themes for programs to wal especially text editor themes. They tend to require regular changes to add support for new plugins or to fix bugs in languages etc.

This is the exact reason why I removed the vim theme from this repo and instead moved it to it's own repo. User's kept opening bug reports about making changes to it.

Would it be possible to add an export file that just contained the color values? Inside emacs you could then use (load "~/.cache/wal/colors-emacs.cl") inside your colorscheme to get the colors.

@ohmree
Copy link
Contributor Author

ohmree commented Jul 23, 2017

Maybe we could make it a theme and also export a function to refresh the colors, and simply have the users execute something like emacs --batch --eval (refresh-wal-theme) after wal.

Although it still has problems with Spacemacs, I'm gonna look into that once the Antergos installer stops being goofy.

@sebastiencs
Copy link

sebastiencs commented Jul 24, 2017

+1 for a file with only the colors values.
I use this file and it's enough for me:

(setq wal-foreground "{foreground}"
      wal-background "{background}"
      wal-cursor "{cursor}"
      wal-black "{color1}"
      wal-red "{color1}"
      wal-green "{color2}"
      wal-yellow "{color3}"
      wal-blue "{color4}"
      wal-magenta "{color5}"
      wal-cyan "{color6}"
      wal-gray "{color7}"
      wal-light-gray "{color8}"
      wal-light-red "{color9}"
      wal-light-green "{color10}"
      wal-light-yellow "{color11}"
      wal-light-blue "{color12}"
      wal-light-magenta "{color13}"
      wal-light-cyan "{color14}"
      wal-white "{color15}")

@ohmree
Copy link
Contributor Author

ohmree commented Jul 24, 2017

@sebastiencs Do you change your Emacs colors on the fly using these colors?

@sebastiencs
Copy link

@omrisim210 Depends what you mean by "on the fly" but I have this code in my emacs init file:

(add-hook
 'before-make-frame-hook
 (lambda ()
   (when (file-readable-p "~/.cache/wal/colors-emacs.el")
     (load-file "~/.cache/wal/my-colors-emacs.el")
     (set-face-attribute 'what-ever-face nil :background wal-foreground :foreground "black"))))

The colors are reloaded every times I open a frame

@ohmree
Copy link
Contributor Author

ohmree commented Jul 24, 2017

@sebastiencs So from what I understand you have to eval the function every time you start a buffer, kind of like adding (wal -r &) to your shell rc file, right?
If I am correct than it also would be necessary to have Emacs eval the function every time you change your wallpaper & colorscheme using wal (in your wal -o script) in order to get my intended result (one command/keypress to make the whole system change colors, even programs that are already running).

BTW, do you use Spacemacs? Because my previous attempts at this (which you can see above) didn't work that well in Spacemacs and I'm not sure how well this will work (I'll test it when I'll be able to)

@dylanaraps
Copy link
Owner

You can use -o to get wal to run an external script on finish. That script could call the eval.

@ohmree
Copy link
Contributor Author

ohmree commented Jul 25, 2017 via email

@sebastiencs
Copy link

So from what I understand you have to eval the function every time you start a buffer, kind of like adding (wal -r &) to your shell rc file, right?
If I am correct than it also would be necessary to have Emacs eval the function every time you change your wallpaper & colorscheme using wal (in your wal -o script) in order to get my intended result (one command/keypress to make the whole system change colors, even programs that are already running).

With the code I wrote the colors are changed automatically when I open a frame, not a buffer. But yes you got the idea.
Yes you could use wal -o to make emacs evaluate a function, it can be done this way also.
But I don't think that this work and the theming part belong to wal. I mean, wal should provide only the colors, then the user can use them as he wish

@ohmree
Copy link
Contributor Author

ohmree commented Jul 25, 2017

So we should open a new project for the Emacs theme

@tkamat
Copy link

tkamat commented Jul 28, 2017

I am also a spacemacs user, so I think I might know what is causing the problem @omrisim210 . Do you have some colors defined in the very bottom of your .spacemacs file? This was causing issues for me too, to fix it just delete all of the lines defining colors at the end and you should be good to go.

@ohmree
Copy link
Contributor Author

ohmree commented Jul 28, 2017

@tkamat I'll only be at home in a few days, then I'll definitely check if I have colors defined. If that's the only thing that's preventing my Emacs from reloading colors on the fly it'll be wonderful.
(Also: I should leave my PC on while I'm away so I can ssh into it from my phone for these kind of things, or maybe just have my dotfiles on GitHub)

@savoie
Copy link

savoie commented Nov 6, 2017

As an alternative option, I've got an emacs that reloads colours from wal on the fly using a custom base16-emacs theme. I didn't really feel like writing my own theme mapping the wal colours to specific emacs attributes, so the base16 package was perfect.

Effectively, I generate the following base16-wal-theme.el on wal reload (right now I literally have a script echoing it to a file, I'd like to make something somewhat more elegant at some point):

(require 'base16-theme)

;; colours generated dynamically by wal
(defun set-wal-colors () (setq base16-wal-colors
			       '(:base00 "#352224"
					 :base01 "#8F8F92"
					 :base02 "#A39A9B"
					 :base03 "#ACAFB3"
					 :base04 "#C6B1AF"
					 :base05 "#B6BCC1"
					 :base06 "#BBC2C7"
					 :base07 "#C8CACD"
					 :base08 "#857a7b"
					 :base09 "#8F8F92"
					 :base0A "#A39A9B"
					 :base0B "#ACAFB3"
					 :base0C "#C6B1AF"
					 :base0D "#B6BCC1"
					 :base0E "#BBC2C7"
					 :base0F "#C8CACD")))

(defvar base16-wal-colors nil "All colors for base16-wal are defined here.")
(set-wal-colors)

;; Define the theme
(deftheme base16-wal)

;; Add all the faces to the theme
(base16-theme-define 'base16-wal base16-wal-colors)

;; Mark the theme as provided
(provide-theme 'base16-wal)

(provide 'base16-wal)

And have in my .emacs:

(defun refresh-theme ()
  (progn
    (load-theme 'base16-wal t)
(refresh-theme)

Now evaling (refresh-theme) reloads the theme. I run emacs as a daemon, so I get my wal-set script to call emacsclient --eval '(refresh-theme)' for me, but you could probably get the same effect using file-notify.

@BonesawMcGraw
Copy link

BonesawMcGraw commented Feb 14, 2018

In case anyone is wondering about the "file-notify" method, I got it to work using the same base16-wal-theme.el file as above, but put this in my .emacs instead:

(defun refresh-theme ()
  (progn
    (load-theme 'base16-wal t)))

(defun theme-callback (event)
  (refresh-theme))

(require 'filenotify)
(file-notify-add-watch
  "/home/[USER]/.emacs.d/base16-wal-theme.el" '(change) 'theme-callback)

Essentially, you define the same refresh-theme variable above, but use another variable theme-callback to satisfy the callback argument for file-notify.

Adding in the template functionality from pywal, "on the fly" theme switching for emacs is now possible by adding a template file called base16-wal-theme.el in ~/.config/wal/templates/.

You can then use the command wal -g -i /path/to/wallpapers && cp /home/${USER}/.cache/wal/base16-wal-theme.el /home/${USER}/.emacs.d/base16-wal-theme.el to apply the new theme. It takes about an extra second, but it's completely automated---I trigger mine with either a keyboard shortcut with sxhkd or with acpid when I open my laptop lid. Hope this helps someone!

@jcaw jcaw mentioned this pull request May 7, 2019
@madalu
Copy link

madalu commented Aug 4, 2019

Chiming in late here, but since this is still open, I thought I'd add another solution in case it helps others. One easy way to hot reload the xresources theme is to use emacs' advice functionality to override the function in the xresources theme that retrieves the color. That way, you aren't stuck with the x database emacs creates at launch but rather can grab fresh data from the json file that wal generates. (You could also of course use a custom template to put the data into a emacs lisp expression, but since the json file already exists, we can just be lazy and use that.) Here's an example:

 (defvar my-wal-colors nil)

 (defun my-refresh-wal-colors ()
   (setq my-wal-colors
         (with-temp-buffer
           (insert-file-contents "~/.cache/wal/colors.json")
           (goto-char (point-min))
           (json-read))))

 (defun my-xresources-theme-color (name)
   (let ((category
          (if (or (string= name "background")
                  (string= name "foreground"))
              'special
            'colors)))
     (cdr
      (assoc (intern name)
             (assoc category my-wal-colors)))))

 (advice-add 'xresources-theme-color :override 'my-xresources-theme-color)

 (defun my-load-xresources ()
   (my-refresh-wal-colors)
   (load-theme 'xresources t))

Then just add "emacsclient -e '(my-load-xresources)'" to the script you run with the "-o" option in wal.

@dylanaraps dylanaraps closed this Jan 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants