From bc9f5584c7b164ff69926db93c864ac628954946 Mon Sep 17 00:00:00 2001 From: ema2159 Date: Thu, 11 Jul 2019 14:31:26 -0700 Subject: [PATCH 1/5] Add base16-darken-color --- base16-theme.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/base16-theme.el b/base16-theme.el index cfca663..d07a084 100644 --- a/base16-theme.el +++ b/base16-theme.el @@ -177,6 +177,23 @@ return the actual color value. Otherwise return the value unchanged." (base16-transform-face face colors)) faces))) +(defun base16-hex-to-rgb (hexcolor) + "Convert HEXCOLOR to rgb format in a 0 to 1 scale." + `(,(/ (string-to-number (substring hexcolor 1 3) 16) 255.0) + ,(/ (string-to-number (substring hexcolor 3 5) 16) 255.0) + ,(/ (string-to-number (substring hexcolor 5 7) 16) 255.0))) + + +(defun base16-darken-color (hexcolor factor) + "Darken HEXCOLOR by FACTOR." + (if (string= (substring hexcolor 0 1) "#") + (let ((rgb-color (base16-hex-to-rgb hexcolor))) + (color-rgb-to-hex + (color-clamp (* (nth 0 rgb-color) factor)) + (color-clamp (* (nth 1 rgb-color) factor)) + (color-clamp (* (nth 2 rgb-color) factor)))) + hexcolor)) + (defun base16-theme-define (theme-name theme-colors) "Define the faces for a base16 colorscheme given a `THEME-NAME' and a plist of `THEME-COLORS'." (base16-set-faces From 52f6c5bc0625afcca93baf0346d1ad14ea9a0f5b Mon Sep 17 00:00:00 2001 From: Kaleb Elwert Date: Thu, 11 Jul 2019 14:31:49 -0700 Subject: [PATCH 2/5] Add a way to transform color values --- base16-theme.el | 60 ++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/base16-theme.el b/base16-theme.el index d07a084..31e5994 100644 --- a/base16-theme.el +++ b/base16-theme.el @@ -14,6 +14,8 @@ ;;; Code: +(require 'color) + (defcustom base16-theme-256-color-source 'terminal "Where to get the colors in a 256-color terminal. @@ -102,31 +104,39 @@ This function is meant for transforming symbols to valid colors. If the value refers to a setting then return whatever is appropriate. If not a setting but is found in the valid list of colors then return the actual color value. Otherwise return the value unchanged." - (if (symbolp key) - (cond - - ((string= (symbol-name key) "base16-settings-fringe-bg") - (if base16-distinct-fringe-background - (plist-get colors :base01) - (plist-get colors :base00))) - - ((string= (symbol-name key) "base16-settings-mode-line-box") - (if (eq base16-highlight-mode-line 'box) - (list :line-width 1 :color (plist-get colors :base04)) - nil)) - - ((string= (symbol-name key) "base16-settings-mode-line-fg") - (if (eq base16-highlight-mode-line 'contrast) - (plist-get colors :base05) - (plist-get colors :base04))) - - (t - (let ((maybe-color (plist-get colors (intern (concat ":" (symbol-name key)))))) - (if maybe-color - maybe-color - key)))) - key)) - + (cond ((symbolp key) + (cond + ((string= (symbol-name key) "base16-settings-fringe-bg") + (if base16-distinct-fringe-background + (plist-get colors :base01) + (plist-get colors :base00))) + + ((string= (symbol-name key) "base16-settings-mode-line-box") + (if (eq base16-highlight-mode-line 'box) + (list :line-width 1 :color (plist-get colors :base04)) + nil)) + + ((string= (symbol-name key) "base16-settings-mode-line-fg") + (if (eq base16-highlight-mode-line 'contrast) + (plist-get colors :base05) + (plist-get colors :base04))) + + (t + (let ((maybe-color (plist-get colors (intern (concat ":" (symbol-name key)))))) + (if maybe-color + maybe-color + key))))) + + ;; If it's a list, there's a chance it's a call to one of our magical + ;; functions. In general, these will only work well in the gui version + ;; of the themes. + ((and (listp key) (symbolp (car key))) + (cond ((string= (symbol-name (car key)) ":darken") + (base16-darken-color (base16-transform-color-key (cadr key) colors) (caddr key))) + (t key))) + + ;; Fall back to passing through the key + (t key))) (defun base16-transform-spec (spec colors) "Transform a theme `SPEC' into a face spec using `COLORS'." From 62659a89941e465b65324c5c9eea40b16218a40a Mon Sep 17 00:00:00 2001 From: Kaleb Elwert Date: Thu, 11 Jul 2019 14:35:59 -0700 Subject: [PATCH 3/5] Theme now requires emacs 24.1 for the color package --- base16-theme.el | 1 + 1 file changed, 1 insertion(+) diff --git a/base16-theme.el b/base16-theme.el index 31e5994..a4b37d3 100644 --- a/base16-theme.el +++ b/base16-theme.el @@ -4,6 +4,7 @@ ;; Neil Bhakta ;; Maintainer: Kaleb Elwert ;; Version: 1.1 +;; Package-Requires: ((emacs "24.1")) ;; Homepage: https://github.com/belak/base16-emacs ;;; Commentary: From 0c3b8c2f0a54f7dc7f0ad58f421d9a571de93a36 Mon Sep 17 00:00:00 2001 From: Kaleb Elwert Date: Mon, 15 Jul 2019 15:08:24 -0700 Subject: [PATCH 4/5] Make modifier functions more generic --- base16-theme.el | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/base16-theme.el b/base16-theme.el index a4b37d3..2529eed 100644 --- a/base16-theme.el +++ b/base16-theme.el @@ -51,6 +51,12 @@ There are two choices for applying the emphasis: (const :tag "Contrast" contrast)) :group 'base16) +(defvar base16-color-modifiers + '(:darken color-darken-name + :lighten color-lighten-name + :saturate color-saturate-name) + "Modifier functions which can be used in spec declarations.") + (defvar base16-shell-colors '(:base00 "black" :base01 "brightgreen" @@ -128,13 +134,15 @@ return the actual color value. Otherwise return the value unchanged." maybe-color key))))) - ;; If it's a list, there's a chance it's a call to one of our magical - ;; functions. In general, these will only work well in the gui version - ;; of the themes. - ((and (listp key) (symbolp (car key))) - (cond ((string= (symbol-name (car key)) ":darken") - (base16-darken-color (base16-transform-color-key (cadr key) colors) (caddr key))) - (t key))) + ;; If it's a list, there's a chance it's a call to one of our + ;; magical functions. In general, these will only work well in + ;; the gui version of the themes. + ((and (listp key) (plist-get base16-color-modifiers (car key))) + (apply + (plist-get base16-color-modifiers (car key)) + (mapcar #'(lambda (x) + (base16-transform-color-key x colors)) + (cdr key)))) ;; Fall back to passing through the key (t key))) @@ -188,21 +196,9 @@ return the actual color value. Otherwise return the value unchanged." (base16-transform-face face colors)) faces))) -(defun base16-hex-to-rgb (hexcolor) - "Convert HEXCOLOR to rgb format in a 0 to 1 scale." - `(,(/ (string-to-number (substring hexcolor 1 3) 16) 255.0) - ,(/ (string-to-number (substring hexcolor 3 5) 16) 255.0) - ,(/ (string-to-number (substring hexcolor 5 7) 16) 255.0))) - - -(defun base16-darken-color (hexcolor factor) - "Darken HEXCOLOR by FACTOR." +(defun base16-modify-hex (modifier hexcolor &rest args) (if (string= (substring hexcolor 0 1) "#") - (let ((rgb-color (base16-hex-to-rgb hexcolor))) - (color-rgb-to-hex - (color-clamp (* (nth 0 rgb-color) factor)) - (color-clamp (* (nth 1 rgb-color) factor)) - (color-clamp (* (nth 2 rgb-color) factor)))) + (apply modifier hexcolor args) hexcolor)) (defun base16-theme-define (theme-name theme-colors) From 5e95e9ba3549aced37283bdfa4d74908937f0d30 Mon Sep 17 00:00:00 2001 From: Kaleb Elwert Date: Mon, 15 Jul 2019 15:10:36 -0700 Subject: [PATCH 5/5] Use base16-modify-hex rather than apply as a simple terminal fix --- base16-theme.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base16-theme.el b/base16-theme.el index 2529eed..c165b7a 100644 --- a/base16-theme.el +++ b/base16-theme.el @@ -138,7 +138,7 @@ return the actual color value. Otherwise return the value unchanged." ;; magical functions. In general, these will only work well in ;; the gui version of the themes. ((and (listp key) (plist-get base16-color-modifiers (car key))) - (apply + (base16-modify-hex (plist-get base16-color-modifiers (car key)) (mapcar #'(lambda (x) (base16-transform-color-key x colors))