solarized-emacs

a fork of Bozhidar Batsov's solarized-emacs
git clone https://git.trogloxene.org/solarized-emacs.git
Log | Files | Refs | README

solarized.el (23604B)


      1 ;;; solarized.el --- Solarized theme  -*- lexical-binding: t -*-
      2 
      3 ;; Copyright (C) 2011-2025 Bozhidar Batsov
      4 
      5 ;; Author: Bozhidar Batsov <bozhidar@batsov.dev>
      6 ;; Author: Thomas Frössman <thomasf@jossystem.se>
      7 
      8 ;; This program is free software; you can redistribute it and/or modify
      9 ;; it under the terms of the GNU General Public License as published by
     10 ;; the Free Software Foundation, either version 3 of the License, or
     11 ;; (at your option) any later version.
     12 
     13 ;; This program is distributed in the hope that it will be useful,
     14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 ;; GNU General Public License for more details.
     17 
     18 ;; You should have received a copy of the GNU General Public License
     19 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
     20 
     21 ;;; Commentary:
     22 
     23 ;; Main solarized file
     24 
     25 ;;; Code:
     26 
     27 (require 'cl-lib)
     28 (require 'color)
     29 (require 'solarized-faces)
     30 
     31 ;;; Options
     32 
     33 (defgroup solarized nil
     34   "Solarized theme options.
     35 The theme has to be reloaded after changing anything in this group."
     36   :group 'faces)
     37 
     38 (defcustom solarized-theme-dir (locate-user-emacs-file "themes/")
     39   "Directory to save theme file."
     40   :type 'directory
     41   :group 'solarized)
     42 
     43 (defcustom solarized-distinct-fringe-background nil
     44   "Make the fringe background different from the normal background color.
     45 Also affects `linum-mode' background."
     46   :type 'boolean
     47   :group 'solarized)
     48 
     49 (defcustom solarized-distinct-doc-face nil
     50   "Make `font-lock-doc-face' stand out more.
     51 Related discussion: https://github.com/bbatsov/solarized-emacs/issues/158"
     52   :type 'boolean
     53   :group 'solarized)
     54 
     55 (defcustom solarized-highlight-numbers nil
     56   "Highlight all numbers.
     57 Applies color to `font-lock-number-face' and `highlight-numbers' mode.
     58 Many tree-sitter based modes use `font-lock-number-face'."
     59   :type 'boolean
     60   :group 'solarized)
     61 
     62 (defcustom solarized-use-variable-pitch t
     63   "Use variable pitch face for some headings and titles."
     64   :type 'boolean
     65   :group 'solarized)
     66 
     67 (defcustom solarized-use-less-bold nil
     68   "Use bold weight less often."
     69   :type 'boolean
     70   :group 'solarized)
     71 
     72 (defcustom solarized-use-more-italic nil
     73   "Use italic slant more often."
     74   :type 'boolean
     75   :group 'solarized)
     76 
     77 (defcustom solarized-emphasize-indicators t
     78   "Use more colors for indicators such as git:gutter, flycheck and similar."
     79   :type 'boolean
     80   :group 'solarized)
     81 
     82 (defcustom solarized-high-contrast-mode-line nil
     83   "Make the active/inactive mode line stand out more."
     84   :type 'boolean
     85   :group 'solarized)
     86 
     87 (defcustom solarized-height-minus-1 0.8
     88   "Font size -1."
     89   :type 'number
     90   :group 'solarized)
     91 
     92 (defcustom solarized-height-plus-1 1.1
     93   "Font size +1."
     94   :type 'number
     95   :group 'solarized)
     96 
     97 (defcustom solarized-height-plus-2 1.15
     98   "Font size +2."
     99   :type 'number
    100   :group 'solarized)
    101 
    102 (defcustom solarized-height-plus-3 1.2
    103   "Font size +3."
    104   :type 'number
    105   :group 'solarized)
    106 
    107 (defcustom solarized-height-plus-4 1.3
    108   "Font size +4."
    109   :type 'number
    110   :group 'solarized)
    111 
    112 (defcustom solarized-scale-org-headlines t
    113   "Whether `org-mode' headlines should be scaled."
    114   :type 'boolean
    115   :group 'solarized)
    116 
    117 (defcustom solarized-scale-markdown-headlines nil
    118   "Whether `markdown-mode' headlines should be scaled."
    119   :type 'boolean
    120   :group 'solarized)
    121 
    122 (defcustom solarized-scale-outline-headlines t
    123   "Whether `outline-mode' headlines should be scaled."
    124   :type 'boolean
    125   :group 'solarized)
    126 
    127 ;;; Utilities
    128 
    129 (defun solarized-color-clamp-lab (lab)
    130   "Restricts a LAB colorspace color if it is out of bounds."
    131   (list (min (max (nth 0 lab) 0.0) 100.0)
    132         (min (max (nth 1 lab) -128) 127)
    133         (min (max (nth 2 lab) -128) 127)))
    134 
    135 (defun solarized-color-rgb-to-hex (red green blue &optional digits-per-component round)
    136   "Return hexadecimal #RGB notation for the color specified by RED GREEN BLUE.
    137 RED, GREEN, and BLUE should be numbers between 0.0 and 1.0, inclusive.
    138 Optional argument DIGITS-PER-COMPONENT can be either 4 (the default)
    139 or 2; use the latter if you need a 24-bit specification of a color.
    140 Optional argument ROUND rounds values which probably is what you usually want."
    141   (or digits-per-component (setq digits-per-component 4))
    142   (let* ((maxval (if (= digits-per-component 2) 255 65535))
    143          (fmt (if (= digits-per-component 2) "#%02x%02x%02x" "#%04x%04x%04x")))
    144     (if round
    145         (format fmt (+ 0.5 (* red maxval)) (+ 0.5 (* green maxval)) (+ 0.5 (* blue maxval)))
    146         (format fmt (* red maxval) (* green maxval) (* blue maxval)))))
    147 
    148 ;;;###autoload
    149 (defun solarized-color-blend (color1 color2 alpha &optional digits-per-component)
    150   "Blends COLOR1 onto COLOR2 with ALPHA.
    151 
    152 COLOR1 and COLOR2 should be color names (e.g. \"white\") or RGB
    153 triplet strings (e.g. \"#ff12ec\").
    154 
    155 Alpha should be a float between 0 and 1.
    156 
    157 Optional argument DIGITS-PER-COMPONENT can be either 4 (the default) or 2;
    158 use the latter if you need a 24-bit specification of a color."
    159   (let ((args (mapcar 'color-clamp
    160                       (apply 'color-lab-to-srgb
    161                              (solarized-color-clamp-lab
    162                               (cl-mapcar
    163                                (lambda (v1 v2) (+ v1 (* alpha (- v2 v1))))
    164                                (apply 'color-srgb-to-lab (color-name-to-rgb color2))
    165                                (apply 'color-srgb-to-lab (color-name-to-rgb color1))))))))
    166     (apply 'solarized-color-rgb-to-hex `(,@args ,digits-per-component t))))
    167 
    168 ;;;###autoload
    169 (defun solarized-create-color-palette (core-palette &optional variant)
    170   "Create color-palette from CORE-PALETTE.
    171 
    172 The returned color-palette has the same format as `solarized-color-palette'."
    173   (let* ((darkest-base   (nth 0 core-palette))
    174          (brightest-base (nth 1 core-palette))
    175          (yellow         (nth 2 core-palette))
    176          (orange         (nth 3 core-palette))
    177          (red            (nth 4 core-palette))
    178          (magenta        (nth 5 core-palette))
    179          (violet         (nth 6 core-palette))
    180          (blue           (nth 7 core-palette))
    181          (cyan           (nth 8 core-palette))
    182          (green          (nth 9 core-palette))
    183          (bg-base        (if (eq variant 'light) brightest-base darkest-base))
    184          (fg-base        (if (eq variant 'light) darkest-base brightest-base))
    185          (bg-1           (if (eq variant 'light) 0.82 0.85))
    186          (bg-2           (if (eq variant 'light) 0.68 0.60))
    187          (fg-1           (if (eq variant 'light) 0.38 0.30))
    188          (fg-2           (if (eq variant 'light) 0.30 0.45)))
    189 
    190     `((base03  . ,(solarized-color-blend darkest-base brightest-base 1.00 2))
    191       (base02  . ,(solarized-color-blend darkest-base brightest-base 0.97 2))
    192       (base01  . ,(solarized-color-blend darkest-base brightest-base 0.65 2))
    193       (base00  . ,(solarized-color-blend darkest-base brightest-base 0.60 2))
    194       (base0   . ,(solarized-color-blend darkest-base brightest-base 0.48 2))
    195       (base1   . ,(solarized-color-blend darkest-base brightest-base 0.42 2))
    196       (base2   . ,(solarized-color-blend darkest-base brightest-base 0.06 2))
    197       (base3   . ,(solarized-color-blend darkest-base brightest-base 0.00 2))
    198 
    199       ;; Solarized accented colors
    200       (yellow    . ,yellow)
    201       (orange    . ,orange)
    202       (red       . ,red)
    203       (magenta   . ,magenta)
    204       (violet    . ,violet)
    205       (blue      . ,blue)
    206       (cyan      . ,cyan)
    207       (green     . ,green)
    208 
    209       ;; Darker and lighter accented colors
    210       ;; Only use these in exceptional circumstances!
    211       (yellow-d  . ,(solarized-color-blend darkest-base   yellow  0.80 2))
    212       (yellow-l  . ,(solarized-color-blend brightest-base yellow  0.80 2))
    213       (orange-d  . ,(solarized-color-blend darkest-base   orange  0.80 2))
    214       (orange-l  . ,(solarized-color-blend brightest-base orange  0.80 2))
    215       (red-d     . ,(solarized-color-blend darkest-base   red     0.80 2))
    216       (red-l     . ,(solarized-color-blend brightest-base red     0.80 2))
    217       (magenta-d . ,(solarized-color-blend darkest-base   magenta 0.80 2))
    218       (magenta-l . ,(solarized-color-blend brightest-base magenta 0.80 2))
    219       (violet-d  . ,(solarized-color-blend darkest-base   violet  0.80 2))
    220       (violet-l  . ,(solarized-color-blend brightest-base violet  0.80 2))
    221       (blue-d    . ,(solarized-color-blend darkest-base   blue    0.80 2))
    222       (blue-l    . ,(solarized-color-blend brightest-base blue    0.80 2))
    223       (cyan-d    . ,(solarized-color-blend darkest-base   cyan    0.80 2))
    224       (cyan-l    . ,(solarized-color-blend brightest-base cyan    0.80 2))
    225       (green-d   . ,(solarized-color-blend darkest-base   green   0.80 2))
    226       (green-l   . ,(solarized-color-blend brightest-base green   0.80 2))
    227 
    228       (yellow-1bg  . ,(solarized-color-blend bg-base yellow  bg-1 2))
    229       (orange-1bg  . ,(solarized-color-blend bg-base orange  bg-1 2))
    230       (red-1bg     . ,(solarized-color-blend bg-base red     bg-1 2))
    231       (magenta-1bg . ,(solarized-color-blend bg-base magenta bg-1 2))
    232       (blue-1bg    . ,(solarized-color-blend bg-base blue    bg-1 2))
    233       (cyan-1bg    . ,(solarized-color-blend bg-base cyan    bg-1 2))
    234       (green-1bg   . ,(solarized-color-blend bg-base green   bg-1 2))
    235       (violet-1bg  . ,(solarized-color-blend bg-base violet  bg-1 2))
    236 
    237       (yellow-1fg  . ,(solarized-color-blend fg-base yellow  fg-1 2))
    238       (orange-1fg  . ,(solarized-color-blend fg-base orange  fg-1 2))
    239       (red-1fg     . ,(solarized-color-blend fg-base red     fg-1 2))
    240       (magenta-1fg . ,(solarized-color-blend fg-base magenta fg-1 2))
    241       (violet-1fg  . ,(solarized-color-blend fg-base violet  fg-1 2))
    242       (blue-1fg    . ,(solarized-color-blend fg-base blue    fg-1 2))
    243       (cyan-1fg    . ,(solarized-color-blend fg-base cyan    fg-1 2))
    244       (green-1fg   . ,(solarized-color-blend fg-base green   fg-1 2))
    245 
    246       (yellow-2bg  . ,(solarized-color-blend bg-base yellow  bg-2 2))
    247       (orange-2bg  . ,(solarized-color-blend bg-base orange  bg-2 2))
    248       (red-2bg     . ,(solarized-color-blend bg-base red     bg-2 2))
    249       (magenta-2bg . ,(solarized-color-blend bg-base magenta bg-2 2))
    250       (violet-2bg  . ,(solarized-color-blend bg-base violet  bg-2 2))
    251       (blue-2bg    . ,(solarized-color-blend bg-base blue    bg-2 2))
    252       (cyan-2bg    . ,(solarized-color-blend bg-base cyan    bg-2 2))
    253       (green-2bg   . ,(solarized-color-blend bg-base green   bg-2 2))
    254 
    255       (yellow-2fg  . ,(solarized-color-blend fg-base yellow  fg-2 2))
    256       (orange-2fg  . ,(solarized-color-blend fg-base orange  fg-2 2))
    257       (red-2fg     . ,(solarized-color-blend fg-base red     fg-2 2))
    258       (magenta-2fg . ,(solarized-color-blend fg-base magenta fg-2 2))
    259       (violet-2fg  . ,(solarized-color-blend fg-base violet  fg-2 2))
    260       (blue-2fg    . ,(solarized-color-blend fg-base blue    fg-2 2))
    261       (cyan-2fg    . ,(solarized-color-blend fg-base cyan    fg-2 2))
    262       (green-2fg   . ,(solarized-color-blend fg-base green   fg-2 2)))))
    263 
    264 ;;; Setup Start
    265 (defmacro solarized-with-color-variables (variant theme-name color-palette &optional childtheme-sexp)
    266   "Eval `solarized-definition' in solarized COLOR-PALETTE for THEME-NAME.
    267 VARIANT is \\='dark or \\='light.
    268 When optional argument CHILDTHEME-SEXP sexp is supplied it\\='s invoked to further
    269 customize the resulting theme."
    270   (declare (indent defun))
    271   (let ((color-palette* (eval color-palette)))
    272     `(let* ((class '((class color) (min-colors 89)))
    273             (light-class (append '((background light)) class))
    274             (dark-class (append '((background dark)) class))
    275             (theme-name ,theme-name)
    276             (variant ,variant)
    277             ,@(mapcar (lambda (elm) `(,(car elm) ,(cdr elm))) color-palette*)
    278 
    279             (s-base03 base03)
    280             (s-base02 base02)
    281             (s-base01 base01)
    282             (s-base00 base00)
    283             (s-base3 base3)
    284             (s-base2 base2)
    285             (s-base1 base1)
    286             (s-base0 base0)
    287 
    288             ;; Solarized palette names, use these instead of -fg -bg...
    289             (base03 (if (eq variant 'light) s-base3 s-base03))
    290             (base02 (if (eq variant 'light) s-base2 s-base02))
    291             (base01 (if (eq variant 'light) s-base1 s-base01))
    292             (base00 (if (eq variant 'light) s-base0 s-base00))
    293             (base0 (if (eq variant 'light) s-base00 s-base0))
    294             (base1 (if (eq variant 'light) s-base01 s-base1))
    295             (base2 (if (eq variant 'light) s-base02 s-base2))
    296             (base3 (if (eq variant 'light) s-base03 s-base3))
    297 
    298             ;; Line drawing color
    299             ;;
    300             ;; NOTE only use this for very thin lines that are hard to see using base02, in low
    301             ;; color displays base02 might be used instead
    302             (s-line (if (eq variant 'light) "#cccec4" "#284b54"))
    303 
    304             ;; Light/Dark adaptive higher/lower contrast accented colors
    305             ;;
    306             ;; NOTE Only use these in exceptional circumstances!
    307             (yellow-hc (if (eq variant 'light) yellow-d yellow-l))
    308             (yellow-lc (if (eq variant 'light) yellow-l yellow-d))
    309             (orange-hc (if (eq variant 'light) orange-d orange-l))
    310             (orange-lc (if (eq variant 'light) orange-l orange-d))
    311             (red-hc (if (eq variant 'light) red-d red-l))
    312             (red-lc (if (eq variant 'light) red-l red-d))
    313             (magenta-hc (if (eq variant 'light) magenta-d magenta-l))
    314             (magenta-lc (if (eq variant 'light) magenta-l magenta-d))
    315             (violet-hc (if (eq variant 'light) violet-d violet-l))
    316             (violet-lc (if (eq variant 'light) violet-l violet-d))
    317             (blue-hc (if (eq variant 'light) blue-d blue-l))
    318             (blue-lc (if (eq variant 'light) blue-l blue-d))
    319             (cyan-hc (if (eq variant 'light) cyan-d cyan-l))
    320             (cyan-lc (if (eq variant 'light) cyan-l cyan-d))
    321             (green-hc (if (eq variant 'light) green-d green-l))
    322             (green-lc (if (eq variant 'light) green-l green-d))
    323 
    324             ;; customize based face properties
    325             (s-maybe-bold (if solarized-use-less-bold
    326                               'unspecified 'bold))
    327             (s-maybe-italic (if solarized-use-more-italic
    328                                 'italic 'normal))
    329             (s-variable-pitch (if solarized-use-variable-pitch
    330                                   'variable-pitch 'default))
    331             (s-fringe-bg (if solarized-distinct-fringe-background
    332                              base02 base03))
    333             (s-fringe-fg base01)
    334 
    335             (s-header-line-fg (if solarized-high-contrast-mode-line
    336                                   base1 base0))
    337             (s-header-line-bg (if solarized-high-contrast-mode-line
    338                                   base02 base03))
    339             (s-header-line-underline (if solarized-high-contrast-mode-line
    340                                          nil base02))
    341 
    342             (s-mode-line-fg (if solarized-high-contrast-mode-line
    343                                 base03 base0))
    344             (s-mode-line-bg (if solarized-high-contrast-mode-line
    345                                 base0 base02))
    346             (s-mode-line-underline (if solarized-high-contrast-mode-line
    347                                        nil s-line))
    348 
    349             (s-mode-line-buffer-id-fg (if solarized-high-contrast-mode-line
    350                                           'unspecified base1))
    351             (s-mode-line-inactive-fg (if solarized-high-contrast-mode-line
    352                                          base0 base01))
    353             (s-mode-line-inactive-bg (if solarized-high-contrast-mode-line
    354                                          base02 base03))
    355             (s-mode-line-inactive-bc (if solarized-high-contrast-mode-line
    356                                          base02 base02))
    357 
    358             ;; diff colors
    359             (s-diff-A-bg red-1bg)
    360             (s-diff-A-fg red-1fg)
    361             (s-diff-fine-A-bg red-2bg)
    362             (s-diff-fine-A-fg red-2fg)
    363 
    364             (s-diff-B-bg green-1bg)
    365             (s-diff-B-fg green-1fg)
    366             (s-diff-fine-B-bg green-2bg)
    367             (s-diff-fine-B-fg green-2fg)
    368 
    369             (s-diff-Ancestor-bg yellow-1bg)
    370             (s-diff-Ancestor-fg yellow-1fg)
    371             (s-diff-fine-Ancestor-bg yellow-2bg)
    372             (s-diff-fine-Ancestor-fg yellow-2fg)
    373 
    374             (s-diff-C-bg blue-1bg)
    375             (s-diff-C-fg blue-1fg)
    376             (s-diff-fine-C-bg blue-2bg)
    377             (s-diff-fine-C-fg blue-2fg)
    378             (s-diff-context-fg base0)
    379             (s-diff-heading-bg base02)
    380 
    381             (s-diffstat-added-fg green)
    382             (s-diffstat-changed-fg blue)
    383             (s-diffstat-removed-fg red))
    384 
    385        ;; silence the byte compiler
    386        (ignore class light-class dark-class theme-name variant
    387                ,@(mapcar 'car color-palette*)
    388                s-base03 s-base02 s-base01 s-base00 s-base3 s-base2
    389                s-base1 s-base0 base03 base02 base01 base00 base0 base1
    390                base2 base3 s-line yellow-hc yellow-lc orange-hc
    391                orange-lc red-hc red-lc magenta-hc magenta-lc violet-hc
    392                violet-lc blue-hc blue-lc cyan-hc cyan-lc green-hc
    393                green-lc s-maybe-bold s-maybe-italic s-variable-pitch
    394                s-fringe-bg s-fringe-fg s-header-line-fg s-header-line-bg
    395                s-header-line-underline s-mode-line-fg s-mode-line-bg
    396                s-mode-line-underline s-mode-line-buffer-id-fg
    397                s-mode-line-inactive-fg s-mode-line-inactive-bg
    398                s-mode-line-inactive-bc s-diff-A-bg s-diff-A-fg
    399                s-diff-fine-A-bg s-diff-fine-A-fg s-diff-B-bg s-diff-B-fg
    400                s-diff-fine-B-bg s-diff-fine-B-fg s-diff-Ancestor-bg
    401                s-diff-Ancestor-fg s-diff-fine-Ancestor-bg
    402                s-diff-fine-Ancestor-fg s-diff-C-bg s-diff-C-fg
    403                s-diff-fine-C-bg s-diff-fine-C-fg s-diff-context-fg
    404                s-diff-heading-bg s-diffstat-added-fg
    405                s-diffstat-changed-fg s-diffstat-removed-fg)
    406        ;; Emit the child theme's faces *before* the base definition.
    407        ;; `custom-theme-set-faces' keeps the first spec it sees for a
    408        ;; given face, so this is what lets a child theme override the
    409        ;; base faces (#352).  Doing it through ordering, rather than by
    410        ;; binding `custom--inhibit-theme-enable' to nil, means we no
    411        ;; longer force the faces to apply during loading and thus honor
    412        ;; `load-theme's NO-ENABLE argument (#420, #325).
    413        ,@(eval childtheme-sexp)
    414        ,@solarized-definition)))
    415 
    416 (defmacro solarized-with-color-variables-with-palette (variant theme-name core-palette &optional childtheme-sexp)
    417   "Create a VARIANT of the theme named THEME-NAME with CORE-PALETTE.
    418 
    419 When optional argument CHILDTHEME-SEXP sexp is supplied it's invoked to further
    420 customize the resulting theme.
    421 
    422 CORE-PALETTE is core color-palette."
    423   (declare (indent 2))
    424   (let ((color-palette (solarized-create-color-palette (eval core-palette) (eval variant))))
    425     `(solarized-with-color-variables ,variant ,theme-name ',color-palette ,childtheme-sexp)))
    426 
    427 (defun solarized-create-theme-file (variant theme-name color-palette &optional childtheme-sexp overwrite)
    428   "Create a VARIANT of the theme named THEME-NAME with COLOR-PALETTE.
    429 
    430 When optional argument CHILDTHEME-SEXP sexp is supplied it's invoked to further
    431 customize the resulting theme.
    432 
    433 CORE-PALETTE is core color-palette.
    434 If OVERWRITE is non-nil, overwrite theme file if exist."
    435   (declare (indent 2))
    436   (add-to-list 'custom-theme-load-path solarized-theme-dir)
    437   (let ((path (expand-file-name (format "%s.el" theme-name)
    438                                 solarized-theme-dir)))
    439     (unless (file-directory-p solarized-theme-dir)
    440       (make-directory solarized-theme-dir))
    441     (when (or overwrite (not (file-readable-p path)))
    442       (with-temp-file (expand-file-name (format "%s-theme.el" theme-name)
    443                                         solarized-theme-dir)
    444         (mapc (lambda (elm)
    445                 (insert (pp-to-string elm)))
    446               `((require 'solarized)
    447                 (deftheme ,theme-name
    448                   ,(format "The %s colour theme of Solarized colour theme flavor." theme-name))
    449                 (solarized-with-color-variables ',variant ',theme-name ',color-palette ',childtheme-sexp)
    450                 (provide-theme ',theme-name)
    451                 (provide ',(intern (format "%s-theme" theme-name)))))))
    452     path))
    453 
    454 (defun solarized-create-theme-file-with-palette (variant theme-name core-palette &optional childtheme-sexp overwrite)
    455   "Create a VARIANT of the theme named THEME-NAME with CORE-PALETTE.
    456 
    457 When optional argument CHILDTHEME-SEXP sexp is supplied it's invoked to further
    458 customize the resulting theme.
    459 
    460 CORE-PALETTE is core color-palette.
    461 If OVERWRITE is non-nil, overwrite theme file if exist."
    462   (declare (indent 2))
    463   (let ((color-palette (solarized-create-color-palette core-palette variant)))
    464     (apply #'solarized-create-theme-file (list variant theme-name color-palette childtheme-sexp overwrite))))
    465 
    466 (define-obsolete-function-alias 'create-solarized-theme-file 'solarized-create-theme-file "1.3.0")
    467 
    468 (defconst solarized--themes
    469   '(solarized-dark
    470     solarized-light
    471     solarized-dark-high-contrast
    472     solarized-light-high-contrast
    473     solarized-gruvbox-dark
    474     solarized-gruvbox-light
    475     solarized-selenized-dark
    476     solarized-selenized-light
    477     solarized-selenized-black
    478     solarized-selenized-white
    479     solarized-zenburn
    480     solarized-wombat-dark)
    481   "List of all bundled Solarized theme variants.")
    482 
    483 (defvar solarized--current nil
    484   "The currently active Solarized theme, or nil.")
    485 
    486 (defun solarized--set-current (theme)
    487   "Record THEME as the active Solarized theme.
    488 Called from `enable-theme-functions'."
    489   (when (memq theme solarized--themes)
    490     (setq solarized--current theme)))
    491 
    492 (defun solarized--clear-current (theme)
    493   "Clear the active Solarized theme if THEME is being disabled.
    494 Called from `disable-theme-functions'."
    495   (when (eq theme solarized--current)
    496     (setq solarized--current nil)))
    497 
    498 (when (boundp 'enable-theme-functions)
    499   (add-hook 'enable-theme-functions #'solarized--set-current)
    500   (add-hook 'disable-theme-functions #'solarized--clear-current))
    501 
    502 (defun solarized-reload (&optional theme)
    503   "Reload the Solarized theme.
    504 You can specify the variant to reload manually with THEME.
    505 
    506 Useful after changing some configuration options or tweaking some colors."
    507   (interactive)
    508   (let ((theme (or theme solarized--current (car custom-enabled-themes))))
    509     (disable-theme theme)
    510     (load-theme theme t)))
    511 
    512 ;;;###autoload
    513 (defun solarized-toggle-theme ()
    514   "Toggle between the light and dark variants of Solarized."
    515   (interactive)
    516   (let ((current-theme (or solarized--current (car custom-enabled-themes))))
    517     (cond
    518      ((eq current-theme 'solarized-dark) (solarized-reload 'solarized-light))
    519      ((eq current-theme 'solarized-light) (solarized-reload 'solarized-dark))
    520      (t (message "You're not currently running a Solarized theme")))))
    521 
    522 ;;;###autoload
    523 (defun solarized-select-theme ()
    524   "Select and load a Solarized theme variant interactively."
    525   (interactive)
    526   (let* ((names (mapcar #'symbol-name solarized--themes))
    527          (choice (intern (completing-read "Solarized theme: " names nil t))))
    528     (mapc #'disable-theme solarized--themes)
    529     (load-theme choice t)))
    530 
    531 ;;; Footer
    532 
    533 ;;;###autoload
    534 (when (and (boundp 'custom-theme-load-path) load-file-name)
    535   (add-to-list 'custom-theme-load-path
    536                (file-name-as-directory (file-name-directory load-file-name))))
    537 
    538 (provide 'solarized)
    539 
    540 ;; Local Variables:
    541 ;; indent-tabs-mode: nil
    542 ;; End:
    543 
    544 ;;; solarized.el ends here