diff --git a/Emacs/auto-color.el b/Emacs/auto-color.el new file mode 100644 index 0000000..e8143b6 --- /dev/null +++ b/Emacs/auto-color.el @@ -0,0 +1,54 @@ +(setq macoy-auto-color-executable "C:/Macoy/StagingSync/AutoColor.exe") + +(setq macoy-auto-color-theme-filename "~/.emacs.d/auto-color-theme.el") + +(setq macoy-auto-color-theme-template-preamble + "(require 'base16-theme) + +(defvar base16-auto-color-colors + '(") +(setq macoy-auto-color-theme-template-postamble + ") + \"All colors for Base16 Macoy are defined here.\") + +;; Define the theme +(deftheme base16-auto-color) + +;; Add all the faces to the theme +(base16-theme-define 'base16-auto-color base16-auto-color-colors) + +;; Mark the theme as provided +(provide-theme 'base16-auto-color) + +(provide 'base16-auto-color-theme)") + +(defun macoy-auto-color-finished (buffer msg) + (when (and + (string-match "^finished" msg) + (string= (buffer-name buffer) "*macoy-auto-color*")) + (let ((results (regex-matches-to-list + "\\(#......\\).*base.." ;; Match result colors + (buffer-string)))) + (when (get-buffer "*macoy-new-theme*") + (kill-buffer "*macoy-new-theme*")) + (get-buffer-create "*macoy-new-theme*") + (with-current-buffer "*macoy-new-theme*" + (let ((color-index 0)) + (insert macoy-auto-color-theme-template-preamble) + (dolist (color results) + (insert (format ":base%02X \"%s\"\n" color-index (first (split-string color)))) + (setq color-index (+ 1 color-index))) + (insert macoy-auto-color-theme-template-postamble)) + (write-region nil nil macoy-auto-color-theme-filename))))) + +(defun macoy-make-auto-color-theme-from-wallpaper () + "Use `macoy-auto-color-executable' to pick theme colors from the current desktop wallpaper. +You will need to restart Emacs to see the new theme." + (interactive) + (add-hook 'compilation-finish-functions 'macoy-auto-color-finished) + (compilation-start macoy-auto-color-executable + 'compilation-mode `(lambda (mode-name) , "*macoy-auto-color*"))) + + +(defun macoy-load-auto-color-theme () + (load-file macoy-auto-color-theme-filename))