Skip to content

Instantly share code, notes, and snippets.

@To1ne
Last active December 18, 2015 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save To1ne/5865848 to your computer and use it in GitHub Desktop.
Save To1ne/5865848 to your computer and use it in GitHub Desktop.
negativ-faces: give all faces their negative color
;; negativ-faces
;; give all faces their negative color.
;;
;; Works great on the default theme:
;; * Just remove all `(load-theme xzy)' from your .emacs.d
;; * Restart emacs
;; * Run `(negativ-negative-all-faces)'
;; * To undo, run `(negativ-negative-all-faces)' again
;;
;; based on http://www.emacswiki.org/emacs/AngryFruitSalad
;; TODO unit test
;; TODO defface hook?
;; TODO smart undo
(defvar negativ--faces '()
"List of faces that are already 'negativ'")
(defun negativ--negative-color (color)
"Return the negative color for the given color."
(let* ((col (color-values color))
(neg (mapcar (lambda (c)
(/ (- (expt 2 16) c 1)
(expt 2 8)))
col)))
(apply 'format "#%02x%02x%02x" neg)))
;(face-attribute 'default :foreground)
;(negativ--negative-color "#dcdccc")
;(negativ--negative-color "#010203")
;(negativ--negative-color "#0a0b0C")
;(negativ--negative-color "#102030")
;(negativ--negative-color "#405060")
;(negativ--negative-color "#4f5f6f")
;(negativ--negative-color "#708090")
;(negativ--negative-color "#a0b0c0")
;(negativ--negative-color "#d0e0f0")
;(eq (face-attribute 'hl-line :foreground) 'unspecified)
(defun negativ--negative-face (face)
"Make the face color negative."
(let* ((fg (face-attribute face :foreground))
(bg (face-attribute face :background)))
(unless (eq fg 'unspecified)
(set-face-attribute face nil
:foreground (negativ--negative-color fg)))
(unless (eq bg 'unspecified)
(set-face-attribute face nil
:background (negativ--negative-color bg)))
)
)
;(negativ--negative-face 'font-lock-function-name-face)
(defun negativ-negative-all-faces ()
"Turn all faces negative."
(mapc 'negativ--negative-face (face-list)))
(defun negativ-smart-negative-all ()
"Turn all faces negative, but skip those that are already done."
(mapc (lambda (face)
(unless (member face negativ--faces)
(negativ--negative-face face)
(add-to-list 'negativ--faces face))) ;; TODO this has to be done also by the other functions
(face-list)))
;(negativ--negative-face 'default)
;(negativ-negative-all-faces)
(negativ-smart-negative-all)
@To1ne
Copy link
Author

To1ne commented Jul 2, 2013

The problem still are autoloads. For example, ediff.

So maybe I should keep a list of faces that are turned negative, and add a refresh function that only does faces that are not in that list.

@To1ne
Copy link
Author

To1ne commented Oct 31, 2013

negativ-smart-negative-all implemented.
Still some work to do.

@To1ne
Copy link
Author

To1ne commented Nov 14, 2013

I also would like to have "modifications": a list of small changes, e.g.:

  • Do not make background #000000 but #111111
  • Do not negative the foreground color compilation-error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment