Created
May 7, 2013 10:19
-
-
Save tsdh/5531651 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 69a786ad268c83df30b5c30c5ad23630b17a0aaa Mon Sep 17 00:00:00 2001 | |
From: Tassilo Horn <tsdh@gnu.org> | |
Date: Tue, 7 May 2013 12:15:40 +0200 | |
Subject: [PATCH] Handle undefined face. (fixes #31) | |
--- | |
powerline-separators.el | 41 ++++++++++++++++++----------------------- | |
1 file changed, 18 insertions(+), 23 deletions(-) | |
diff --git a/powerline-separators.el b/powerline-separators.el | |
index c37a08b..5c06d10 100644 | |
--- a/powerline-separators.el | |
+++ b/powerline-separators.el | |
@@ -17,36 +17,31 @@ | |
(require 'cl) | |
-(defun pl/interpolate (color1 color2) | |
- "Interpolate between COLOR1 and COLOR2. | |
+(defun pl/hex-color (color) | |
+ "Gets the hexadecimal value COLOR." | |
+ (cond | |
+ ((not (color-defined-p color)) | |
+ (pl/hex-color (face-attribute 'default :foreground))) | |
+ ((string= "#" (substring color 0 1)) | |
+ (upcase color)) | |
+ ((color-defined-p color) | |
+ (concat "#" | |
+ (mapconcat | |
+ (lambda(val) | |
+ (format "%02X" (* val 255))) | |
+ (color-name-to-rgb color) ""))) | |
+ (t nil))) | |
-COLOR1 and COLOR2 must be supplied as hex strings with leading #." | |
- (let* ((c1 (replace-regexp-in-string "#" "" color1)) | |
- (c2 (replace-regexp-in-string "#" "" color2)) | |
+(defun pl/interpolate (color1 color2) | |
+ "Interpolate between COLOR1 and COLOR2." | |
+ (let* ((c1 (replace-regexp-in-string "#" "" (pl/hex-color color1))) | |
+ (c2 (replace-regexp-in-string "#" "" (pl/hex-color color2))) | |
(c1r (string-to-number (substring c1 0 2) 16)) (c1b (string-to-number (substring c1 2 4) 16)) (c1g (string-to-number (substring c1 4 6) 16)) | |
(c2r (string-to-number (substring c2 0 2) 16)) (c2b (string-to-number (substring c2 2 4) 16)) (c2g (string-to-number (substring c2 4 6) 16)) | |
(red (/ (+ c1r c2r) 2)) (grn (/ (+ c1g c2g) 2)) (blu (/ (+ c1b c2b) 2))) | |
(format "#%02X%02X%02X" red grn blu))) | |
- | |
-(defun pl/hex-color (color) | |
- "Gets the hexadecimal value COLOR." | |
- (let ((ret color)) | |
- (cond | |
- ((string= "#" (substring color 0 1)) | |
- (setq ret (upcase ret))) | |
- ((color-defined-p color) | |
- (setq ret (concat "#" | |
- (mapconcat | |
- (lambda(val) | |
- (format "%02X" (* val 255))) | |
- (color-name-to-rgb color) "")))) | |
- (t (setq ret nil))) | |
- (symbol-value 'ret))) | |
- | |
- | |
- | |
(defun pl/pattern (lst) | |
"Turn LST into an infinite pattern." | |
(when lst | |
-- | |
1.8.2.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment