This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
paper-theme.el
360 lines (324 loc) · 14.4 KB
/
paper-theme.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
;;; paper-theme.el --- A minimal Emacs colour theme. -*- lexical-binding: t; -*-
;; Copyright (C) 2015, 2018, 2019, 2022, 2023 Göktuğ Kayaalp
;;
;; Author: Göktuğ Kayaalp
;; Keywords: theme paper
;; Package-Version: 2.1
;; Package-Requires: ((emacs "24"))
;; URL: https://dev.gkayaalp.com/elisp/index.html#paper
;;
;; Permission is hereby granted, free of charge, to any person
;; obtaining a copy of this software and associated documentation
;; files (the "Software"), to deal in the Software without
;; restriction, including without limitation the rights to use, copy,
;; modify, merge, publish, distribute, sublicense, and/or sell copies
;; of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:
;;
;; The above copyright notice and this permission notice shall be
;; included in all copies or substantial portions of the Software.
;;
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.
;;
;;; Commentary:
;;
;; Paper is a little, minimal emacs theme that is meant to be simple
;; and consistent.
;;
;; It was first intended to resemble the look of paper, but has
;; diverged from that objective. Still, though, I keep calling it
;; Paper, as I like that name.
;;
;; Paper uses a small colour palette over all the elements. Org
;; headings are specially treated with a palette of equidistant
;; colours. The colours and heading font sizes are calculated using
;; base and factor values which can be edited. See source.
;;
;; It's most adapted for ELisp-Org users, as I'm one such user, though
;; it works fine with Markdown, Textile, Python, JavaScript, Html,
;; Diff, Magit, etc.
;;
;;; Installation:
;;
;; Install it into a directory that's in the `custom-theme-load-path'.
;; I recommend that you put that directory also in `load-path', so
;; that you can `require' the `paper-theme'. Then adapt this snippet
;; to your configuration.
;;
;; ;; Not necessary, but silences flycheck errors for referencing free
;; ;; variables.
;; (require 'paper-theme)
;; ;; It's not necessary to modify these variables, they all have sane
;; ;; defaults.
;; (setf paper-paper-colour 'paper-parchment ; Custom background.
;; paper-tint-factor 45) ; Tint factor for org-level-* faces
;; ;; Activate the theme.
;; (load-theme 'paper t)
;;
;;; Customisation:
;;
;; It is possible to modify the base font size and the scaling factor
;; for `org-level-faces' via the variables `paper-base-font-size' and
;; `paper-font-factor' respectively.
;;
;; The factor for org-level-* colours are also configurable, adjust
;; the variable `paper-tint-factor'.
;;
;; Various background colours are provided, see the docstring of the
;; variable `paper-paper-colour' in order to find out how to switch
;; them. You can add your custom colour for background without
;; modifying this module:
;;
;; (push (list 'my-bgcolour "#000000") paper-colours-alist)
;; (setf paper-paper-colour 'my-bgcolour)
;;
;; The following snippet will modify org-level-* faces so that initial
;; stars in org headings are hidden and a Sans-serif font is used.
;; Because the combination of heading font sizes and colours make
;; levels obvious, it may be considered superfluous to have stars
;; indicating depth:
;;
;; (setq org-hide-leading-stars nil)
;; (set-face-attribute
;; 'org-hide nil
;; :height 0.1 :weight 'light :width 'extracondensed)
;; (dolist (face org-level-faces)
;; (set-face-attribute
;; face nil
;; :family "Sans Serif"))
;;
;;; Code:
;;
(require 'cl-lib)
;;; Code from hexrgb.el:
;; On 25 Dec 2018 I was informed that Melpa was about to drop support
;; for Emacswiki packages, which includes hexrgb.el too. This means
;; that I needed to remove the dependency on the package, so I include
;; here the functions needed by paper-theme from that package. Below,
;; I reproduce information on copyright and some other things from the
;; version I have of it:
;; Copyright (C) 2004-2015, Drew Adams, all rights reserved.
;; Last-Updated: Wed Jul 8 18:32:29 2015 (-0700)
;; By: dradams
;; Update #: 985
;; URL: http://www.emacswiki.org/hexrgb.el
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
(if (featurep 'hexrgb)
(require 'hexrgb)
(progn
;; Originally, I used the code from `int-to-hex-string' in `float.el'.
;; This version is thanks to Juri Linkov <juri@jurta.org>.
;;
(defun hexrgb-int-to-hex (int &optional nb-digits)
"Convert integer arg INT to a string of NB-DIGITS hexadecimal digits.
If INT is too large to be represented with NB-DIGITS, then the result
is truncated from the left. So, for example, INT=256 and NB-DIGITS=2
returns \"00\", since the hex equivalent of 256 decimal is 100, which
is more than 2 digits."
(setq nb-digits (or nb-digits 4))
(substring (format (concat "%0" (int-to-string nb-digits) "X") int) (- nb-digits)))
;; From `hexl.el'. This is the same as `hexl-hex-char-to-integer' defined there.
(defun hexrgb-hex-char-to-integer (character)
"Take a CHARACTER and return its value as if it were a hex digit."
(if (and (>= character ?0) (<= character ?9))
(- character ?0)
(let ((ch (logior character 32)))
(if (and (>= ch ?a) (<= ch ?f))
(- ch (- ?a 10))
(error "Invalid hex digit `%c'" ch)))))
(defun hexrgb-hex-to-int (hex)
"Convert HEX string argument to an integer.
The characters of HEX must be hex characters."
(let* ((factor 1)
(len (length hex))
(indx (1- len))
(int 0))
(while (>= indx 0)
(setq int (+ int (* factor (hexrgb-hex-char-to-integer (aref hex indx))))
indx (1- indx)
factor (* 16 factor)))
int))
(defun hexrgb-increment-hex (hex nb-digits increment &optional wrap-p)
"Increment hexadecimal-digits string HEX by INCREMENT.
Only the first NB-DIGITS of HEX are used.
If optional arg WRAP-P is non-nil then the result wraps around zero.
For example, with NB-DIGITS 3, incrementing \"fff\" by 1 causes it
to wrap around to \"000\"."
(let* ((int (hexrgb-hex-to-int hex))
(new-int (+ increment int)))
(if (or wrap-p
(and (>= int 0) ; Not too large for the machine.
(>= new-int 0) ; For the case where increment < 0.
(<= (length (format (concat "%X") new-int)) nb-digits))) ; Not too long.
(hexrgb-int-to-hex new-int nb-digits) ; Use incremented number.
hex))) ; Don't increment.
(defun hexrgb-increment-equal-rgb (hex nb-digits increment &optional wrap-p)
"Increment each color component (r,g,b) of rgb string HEX by INCREMENT.
String HEX starts with \"#\". Each color is NB-DIGITS hex digits long.
If optional arg WRAP-P is non-nil then the result wraps around zero.
For example, with NB-DIGITS 3, incrementing \"#fffffffff\" by 1
causes it to wrap around to \"#000000000\"."
(concat
"#"
(hexrgb-increment-hex (substring hex 1 (1+ nb-digits)) nb-digits increment wrap-p)
(hexrgb-increment-hex (substring hex (1+ nb-digits) (1+ (* nb-digits 2)))
nb-digits
increment
wrap-p)
(hexrgb-increment-hex (substring hex (1+ (* nb-digits 2))) nb-digits increment wrap-p)))))
;;; Paper theme:
(deftheme paper
"An Emacs colour theme that resembles the look of paper.")
(defvar paper-colours-alist
'((text "#070A01")
(paper-grey "#FAFAFA")
(paper-old-dark "#F8ECC2")
(paper-parchment "#F1F1D4")
(paper-old-light "#F2EECB")
(white "#EEEEEE")
(magenta "#8C0D40")
(pen "#000F55")
(light-shadow "#D9DDD9"))
"The colours used in Paper theme.
The alist of colours where for each pair p (car p) is a
symbol identifying the colour and (cdr p) is the string, the
hexedecimal notation of the colour (i.e. #RRGGBB where R, G and B
are hexedecimal digits).")
(defvar paper-paper-colour 'paper-grey
"Which paper colour to use.
The variable `paper-colours-alist' contains a suit of colours
with prefix `paper-'. This variable's value is supposed to be
set to one of those symbols to specify the colour used for
background.")
(defvar paper-use-varying-heights-for-org-title-headlines nil
"Whether to use varying heights for Org headlines.")
(defvar paper-base-font-size 100
"The base size for fonts.")
(defvar paper-font-factor 0.1
"The font factor for calculating level fonts from base.")
(defvar paper-tint-factor 20
"The factor for computing tints for org levels.")
(defun paper-colour (colour-identifier)
"Get colour for COLOUR-IDENTIFIER."
(cadr (assoc colour-identifier paper-colours-alist)))
(defun paper-colour-paper ()
"Get the colour for paper.
See `paper-paper-colour' and `paper-colours-alist'."
(paper-colour paper-paper-colour))
(defconst paper-normal-face
`((t (:foreground ,(paper-colour 'text) :background ,(paper-colour-paper))))
"The base colours of Paper theme.")
(defconst paper-inverse-face
`((t (:foreground ,(paper-colour-paper) :background ,(paper-colour 'text))))
"The inverse of base colours of Paper theme.")
(defconst paper-pen-face
`((t (:foreground ,(paper-colour 'pen) :background ,(paper-colour-paper))))
"Colour couple that resembles pen colour on paper.")
(defconst paper-light-shadow-face
`((t (:foreground ,(paper-colour 'text) :background ,(paper-colour 'light-shadow))))
"Colour couple that resembles a light shadow.")
(defconst paper-italicised-pen-face
`((t (:foreground ,(paper-colour 'pen) :background ,(paper-colour-paper)
:slant italic)))
"Colour couple that resembles pen colour on paper, italicised.")
(defconst paper-magenta-on-paper-face
`((t (:foreground ,(paper-colour 'magenta) :background ,(paper-colour-paper)))))
(defun paper-tints (hex n &optional darken)
"Compute equidistant tints of a given colour.
HEX is the hexedecimal RRGGBB string representation of the colour.
N is an integer denoting how many tints to compute.
If DARKEN is non-nil, compute darker tints, otherwise, lighter."
(cl-loop
for i from 0 to n
collect (hexrgb-increment-equal-rgb
hex 2
(* i
(funcall
(if darken #'- #'identity)
paper-tint-factor)))))
(defun paper--set-faces ()
"Set up faces.
May be used to refresh after tweaking some variables."
(eval
(let* ((b paper-base-font-size) ; base
(f paper-font-factor) ; factor
(o "org-level-")
(org-faces)
(n 8)
(tints (paper-tints (paper-colour 'magenta) n)))
(dolist (n (number-sequence 1 n))
(push
`(quote
(,(intern
(concat o (number-to-string n)))
((t (:slant normal
:weight light
:foreground ,(pop tints)
,@(when paper-use-varying-heights-for-org-title-headlines
(list
:height
(truncate (+ b (- (* b (+ 1 f)) (* b (* f n))))))))))))
org-faces))
`(custom-theme-set-faces
(quote paper)
;; === Frame ===
(quote (default ,paper-normal-face))
(quote (cursor ,paper-inverse-face))
(quote (mode-line ((t (:foreground ,(paper-colour 'white)
:background ,(paper-colour 'magenta)
:box nil)))))
(quote (mode-line-inactive ,paper-light-shadow-face))
(quote (mode-line-highlight ((t (:foreground ,(paper-colour 'text)
:box nil)))))
(quote (fringe ,paper-normal-face))
(quote (region ((t (:background ,(paper-colour 'magenta)
:foreground ,(paper-colour 'white))))))
;; === Syntax ===
(quote (font-lock-builtin-face ,paper-normal-face))
(quote (font-lock-comment-face ,paper-italicised-pen-face))
(quote (font-lock-string-face ,paper-pen-face))
(quote (font-lock-function-name-face ,paper-pen-face))
(quote (font-lock-variable-name-face ,paper-pen-face))
(quote (font-lock-keyword-face ,paper-magenta-on-paper-face))
(quote (font-lock-type-face ,paper-magenta-on-paper-face))
(quote (font-lock-constant-face ,paper-magenta-on-paper-face))
(quote (font-lock-preprocessor-face ,paper-magenta-on-paper-face))
;; === Org titles ===
,(when paper-use-varying-heights-for-org-title-headlines
(quote (quote (org-tag ((t (:height 90 :weight light)))))))
,@org-faces
;; === Line numbers ===
(quote (line-number ,paper-light-shadow-face))
(quote (line-number-current-line ((t (:inherit highlight)))))
;; === Various faces ===
;;
;; Faces which do not sensibly inherit from font-lock.
(quote (sh-heredoc ((t (:inherit font-lock-string-face)))))))))
(paper--set-faces)
;;;###autoload
(and load-file-name
(boundp 'custom-theme-load-path)
(add-to-list 'custom-theme-load-path
(file-name-as-directory
(file-name-directory load-file-name))))
(provide 'paper-theme)
(provide-theme 'paper)
;;; paper-theme.el ends here