Skip to content

Instantly share code, notes, and snippets.

@schellj
Created August 5, 2019 23:58
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 schellj/3a0ff288936322b59006d497bf607351 to your computer and use it in GitHub Desktop.
Save schellj/3a0ff288936322b59006d497bf607351 to your computer and use it in GitHub Desktop.
(defun schellj/try-insert-test-image (r g b)
"Insert XPM with colors r g b"
(ignore-errors
(insert-image (create-image (format "/* XPM */
static char * XFACE[] = {
\"77 16 1 1\",
\"a c %s\",
\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"
};" (color-rgb-to-hex r g b)) 'xpm t))))
(defun schellj/insert-color-info (r g b)
"Insert color info"
(let ((indent 26))
(dolist
(color-component `(,r ,g ,b))
(indent-to indent)
(insert (if (eq (type-of color-component) 'float)
(number-to-string color-component)
color-component))
(setq indent (+ indent 23)))))
(defun schellj/insert-test-info (r g b)
"Insert color test info"
(schellj/insert-color-info r g b)
(indent-to 95)
(schellj/try-insert-test-image r g b)
(indent-to 97)
(condition-case err
(progn
(insert (color-rgb-to-hex r g b)))
(overflow-error (progn
(indent-to 107)
(insert (error-message-string err)))))
(insert "\n"))
(defun schellj/color-test ()
"macOS gamma color test"
(interactive ())
(dolist (color (defined-colors))
(insert color)
(indent-to 26)
(insert (apply 'color-rgb-to-hex (color-name-to-rgb color)))
(insert "\n")
(insert "Method")
(schellj/insert-color-info "R" "G" "B")
(indent-to 95)
(insert "Test Swatch")
(indent-to 107)
(insert "Hex\n")
(insert "color-rgb-to-hex face bg")
(apply 'schellj/insert-color-info (color-name-to-rgb color))
(indent-to 95)
(setq opoint (point))
(indent-to 106)
(put-text-property opoint (point) 'face `(:background ,color :foreground "#000000"))
(insert " ")
(insert (apply 'color-rgb-to-hex (color-name-to-rgb color)))
(insert "\n")
(insert "Powerline apple rgb xpm")
(apply 'schellj/insert-test-info
(apply 'pl/color-xyz-to-apple-rgb
(apply 'color-srgb-to-xyz (color-name-to-rgb color))))
(insert "PR apple rgb xpm")
(apply 'schellj/insert-test-info
(apply 'schellj/color-xyz-to-apple-rgb
(apply 'color-srgb-to-xyz (color-name-to-rgb color))))
(insert "\n")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment