Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for :darken color modifier #101

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 49 additions & 25 deletions base16-theme.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
;; Neil Bhakta
;; Maintainer: Kaleb Elwert <[email protected]>
;; Version: 1.1
;; Package-Requires: ((emacs "24.1"))
;; Homepage: https://github.com/belak/base16-emacs

;;; Commentary:
Expand All @@ -14,6 +15,8 @@

;;; Code:

(require 'color)

(defcustom base16-theme-256-color-source 'terminal
"Where to get the colors in a 256-color terminal.

Expand Down Expand Up @@ -48,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"
Expand Down Expand Up @@ -102,31 +111,41 @@ 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) (plist-get base16-color-modifiers (car key)))
(base16-modify-hex
(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)))

(defun base16-transform-spec (spec colors)
"Transform a theme `SPEC' into a face spec using `COLORS'."
Expand Down Expand Up @@ -177,6 +196,11 @@ return the actual color value. Otherwise return the value unchanged."
(base16-transform-face face colors))
faces)))

(defun base16-modify-hex (modifier hexcolor &rest args)
(if (string= (substring hexcolor 0 1) "#")
(apply modifier hexcolor args)
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
Expand Down