emacs-doom-themes/doom-themes.el

194 lines
6.7 KiB
EmacsLisp
Raw Normal View History

2016-09-12 14:06:43 +00:00
;;; doom-themes.el --- a pack of themes inspired by Atom One
;;
;; Copyright (C) 2016 Henrik Lissner
;;
;; Author: Henrik Lissner <http://github/hlissner>
;; Maintainer: Henrik Lissner <henrik@lissner.net>
;; Created: May 22, 2016
2017-04-11 22:23:51 +00:00
;; Modified: April 11, 2017
;; Version: 1.2.0
2017-01-11 09:40:29 +00:00
;; Keywords: dark blue atom one theme neotree nlinum icons
2016-09-12 14:24:50 +00:00
;; Homepage: https://github.com/hlissner/emacs-doom-theme
2017-01-11 01:03:29 +00:00
;; Package-Requires: ((emacs "24.4") (all-the-icons "1.0.0") (cl-lib "0.5"))
2016-09-12 14:06:43 +00:00
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;; An opinionated UI plugin/pack of themes extracted from my emacs.d, inspired
;; by the One Dark/Light UI and syntax themes in Atom.
;;
;; Includes optional dimming of non-source buffers, a neotree theme with font
;; icons, and (soon) a mode-line config.
;;
;; Currently available colorschemes:
;; + doom-one: inspired by Atom One Dark
;; + doom-dark: based on Molokai
;;
;; Soon to come:
2017-01-10 20:04:17 +00:00
;; + doom-one-light: inspired by Atom One Light
;; + doom-tron: doom-one, but with daylerees' Tron Legacy colorscheme
;; + doom-peacock: doom-one, but with daylerees' Peacock colorscheme
2016-09-12 14:06:43 +00:00
;;
;;
;; ## Configuration
;;
2017-01-10 20:04:17 +00:00
;; + global
;; + `doom-enable-bold` (default: `t`): if nil, bolding will be disabled
;; across all faces.
;; + `doom-enable-italic` (default: `t`): if nil, italicization will be
;; disabled across all faces.
;; + doom-one
;; + `doom-one-brighter-modeline` (default: `nil`): If non-nil, the
;; mode-line background is slightly brighter.
;; + `doom-one-brighter-comments` (default: `nil`): If non-nil, comments
;; are brighter and easier to see.
2016-09-12 14:06:43 +00:00
;;
;;
;; ## Installation
;;
2016-10-04 21:09:43 +00:00
;; 1. Install from MELPA `M-x package-install RET doom-themes`, or clone
;; the repo somewhere in your `load-path`.
2016-09-12 14:06:43 +00:00
;;
2016-10-04 21:09:43 +00:00
;; 2. If you want the neotree theme, download and install the fonts included
;; with all-the-icons.
;;
;; 3. `(require 'doom-themes)` and then load the theme you want.
;;
;; Example configuration:
2016-09-12 14:06:43 +00:00
;;
;; (require 'doom-themes)
;; (load-theme 'doom-one t) ;; or doom-dark, etc.
;;
2016-10-04 21:09:43 +00:00
;; ;;; OPTIONAL
;; ;; brighter source buffers
;; (add-hook 'find-file-hook 'doom-buffer-mode)
;; ;; brighter minibuffer when active
;; (add-hook 'minibuffer-setup-hook 'doom-brighten-minibuffer)
;; ;; Custom neotree theme
;; (require 'doom-neotree)
2016-09-12 14:06:43 +00:00
;;
;;; Code:
2017-01-11 01:03:29 +00:00
(require 'cl-lib)
(defgroup doom-themes nil
"Options for doom-themes"
:group 'faces)
(defface doom-default '((t (:inherit default)))
"Background face for source code windows."
:group 'doom-themes)
(defface doom-minibuffer-active '((t (:inherit mode-line)))
"Face for active minibuffer. See `doom-enable-bright-minibuffer'."
:group 'doom-themes)
(defface doom-linum '((t (:inherit linum)))
"Another linum face for darker windows (like popups)."
:group 'doom-themes)
(defface doom-nlinum-highlight '((t (:inherit linum)))
"A face for the nlinum overlay on the current line."
:group 'doom-themes)
(defface doom-hl-line '((t (:inherit hl-line)))
"A face for the current line highlight."
:group 'doom-themes)
(defface doom-org-hide '((t (:inherit org-hide)))
"A face for hidden elements in org-mode. Only active if `doom-buffer-mode' is active."
:group 'doom-themes)
;;
(defcustom doom-enable-bold t
"If nil, bold will remove removed from all faces."
:group 'doom-themes
:type 'boolean)
(defcustom doom-enable-italic t
"If nil, italics will remove removed from all faces."
:group 'doom-themes
:type 'boolean)
;; Color helper functions
;; Shamelessly *borrowed* from solarized
(defun doom-name-to-rgb (color &optional frame)
(mapcar (lambda (x) (/ x (float (car (color-values "#ffffff")))))
(color-values color frame)))
(defun doom-blend (color1 color2 alpha)
(apply (lambda (r g b) (format "#%02x%02x%02x" (* r 255) (* g 255) (* b 255)))
2017-01-11 01:03:29 +00:00
(cl-mapcar (lambda (it other) (+ (* alpha it) (* other (- 1 alpha))))
(doom-name-to-rgb color1)
(doom-name-to-rgb color2))))
(defun doom-darken (color alpha)
(doom-blend color "#000000" (- 1 alpha)))
(defun doom-lighten (color alpha)
(doom-blend color "#FFFFFF" (- 1 alpha)))
(defun doom--face-remap-add-relative (orig-fn &rest args)
"Advice function "
(when (and (display-graphic-p) doom-buffer-mode)
(let ((remap (assq (nth 0 args) face-remapping-alist)))
(when remap (setf (nth 0 args) (cadr remap)))))
(apply orig-fn args))
(advice-add 'face-remap-add-relative :around 'doom--face-remap-add-relative)
;;;###autoload
(defun doom-brighten-minibuffer ()
(with-selected-window (minibuffer-window)
(setq-local face-remapping-alist
(append face-remapping-alist '((default doom-minibuffer-active))))))
;;;###autoload
(define-minor-mode doom-buffer-mode
"Brighten source buffers by remapping common faces (like default, hl-line and
linum) to their doom-theme variants."
:lighter " doom"
:init-value nil
(if doom-buffer-mode
(progn
;; Don't reset remapped faces on `kill-all-local-variables'
(make-variable-buffer-local 'face-remapping-alist)
(put 'face-remapping-alist 'permanent-local t)
;; Brighten up file buffers; darken special and popup buffers
(set-face-attribute 'fringe nil :background (face-attribute 'doom-default :background))
;; Update `doom-org-hide'
(when (eq major-mode 'org-mode)
(set-face-attribute 'org-hide nil
:background (face-attribute 'doom-default :background)
:foreground (face-attribute 'doom-default :background)))
(setq-local face-remapping-alist
(append face-remapping-alist
'((default doom-default)
(hl-line doom-hl-line)
(linum doom-linum)))))
(set-face-attribute 'fringe nil :background (face-attribute 'default :background))
(put 'face-remapping-alist 'permanent-local nil)
(set-face-attribute 'org-hide nil
:background (face-attribute 'default :background)
:foreground (face-attribute 'default :background))
;; Remove face remaps
(mapc (lambda (key) (setq-local face-remapping-alist (assq-delete-all key face-remapping-alist)))
'(default hl-line linum))))
;;;###autoload
(defun doom-buffer-mode-maybe ()
"Enable `doom-buffer-mode' in the current buffer, if it isn't already and the
buffer represents a real file."
(when (and (not doom-buffer-mode)
buffer-file-name)
(doom-buffer-mode +1)))
;;;###autoload
(when (and (boundp 'custom-theme-load-path) load-file-name)
(add-to-list 'custom-theme-load-path
(file-name-as-directory (file-name-directory load-file-name))))
2016-09-12 14:06:43 +00:00
(provide 'doom-themes)
;;; doom-themes.el ends here