Skip to content

Commit 466465f

Browse files
committed
Add custom atom & attribute faces.
I am aware these are probably unbelievably hideous. Please forgive me.
1 parent 82321e7 commit 466465f

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

elixir-mode.el

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,27 @@
223223
"For use with escape characters."
224224
:group 'font-lock-faces)
225225

226+
(defvar elixir-attribute-face 'elixir-attribute-face)
227+
(defface elixir-attribute-face
228+
'((((class color) (min-colors 88) (background light))
229+
:foreground "MediumPurple4")
230+
(((class color) (background dark))
231+
(:foreground "thistle"))
232+
(t nil))
233+
"For use with escape characters."
234+
:group 'font-lock-faces)
235+
236+
(defvar elixir-atom-face 'elixir-atom-face)
237+
(defface elixir-atom-face
238+
'((((class color) (min-colors 88) (background light))
239+
:foreground "RoyalBlue4")
240+
(((class color) (background dark))
241+
(:foreground "light sky blue"))
242+
(t nil))
243+
"For use with escape characters."
244+
:group 'font-lock-faces)
245+
246+
226247
(eval-when-compile
227248
(defconst elixir-rx-constituents
228249
`(
@@ -343,7 +364,7 @@
343364
;; Module attributes
344365
(,(elixir-rx (group (or heredocs
345366
(and "@" (1+ identifiers)))))
346-
1 font-lock-builtin-face)
367+
1 elixir-attribute-face)
347368

348369
;; Keywords
349370
(,(elixir-rx (group (or builtin builtin-declaration builtin-namespace
@@ -396,11 +417,11 @@
396417

397418
;; Atoms and singleton-like words like true/false/nil.
398419
(,(elixir-rx (group atoms))
399-
1 font-lock-constant-face)
420+
1 elixir-atom-face)
400421

401422
;; Map keys
402423
(,(elixir-rx (group (and (one-or-more identifiers) ":")))
403-
1 font-lock-constant-face)
424+
1 elixir-atom-face)
404425

405426
;; Built-in modules and pseudovariables
406427
(,(elixir-rx (group (or builtin-modules pseudo-var)))

test/elixir-mode-font-tests.el

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,41 +104,41 @@ end"
104104
:tags '(fontification heredoc syntax-table)
105105
(elixir-test-with-temp-buffer
106106
"@doc \"\"\""
107-
(should (eq (elixir-test-face-at 1) 'font-lock-builtin-face))
108-
(should (eq (elixir-test-face-at 2) 'font-lock-builtin-face))
107+
(should (eq (elixir-test-face-at 1) 'elixir-attribute-face))
108+
(should (eq (elixir-test-face-at 2) 'elixir-attribute-face))
109109
(should (eq (elixir-test-face-at 6) 'font-lock-string-face))))
110110

111111
(ert-deftest elixir-mode-syntax-table/fontify-heredoc/2 ()
112112
:tags '(fontification heredoc syntax-table)
113113
(elixir-test-with-temp-buffer
114114
"@moduledoc \"\"\""
115-
(should (eq (elixir-test-face-at 1) 'font-lock-builtin-face))
116-
(should (eq (elixir-test-face-at 2) 'font-lock-builtin-face))
115+
(should (eq (elixir-test-face-at 1) 'elixir-attribute-face))
116+
(should (eq (elixir-test-face-at 2) 'elixir-attribute-face))
117117
(should (eq (elixir-test-face-at 12) 'font-lock-string-face))))
118118

119119
(ert-deftest elixir-mode-syntax-table/fontify-heredoc/3 ()
120120
:tags '(fontification heredoc syntax-table)
121121
(elixir-test-with-temp-buffer
122122
"~s\"\"\""
123-
(should (eq (elixir-test-face-at 1) 'font-lock-builtin-face))
124-
(should (eq (elixir-test-face-at 2) 'font-lock-builtin-face))
123+
(should (eq (elixir-test-face-at 1) 'elixir-attribute-face))
124+
(should (eq (elixir-test-face-at 2) 'elixir-attribute-face))
125125
(should (eq (elixir-test-face-at 3) 'font-lock-string-face))))
126126

127127
(ert-deftest elixir-mode-syntax-table/fontify-atoms ()
128128
:tags '(fontification atom syntax-table)
129129
(elixir-test-with-temp-buffer
130130
":oriole
131131
:andale"
132-
(should (eq (elixir-test-face-at 3) 'font-lock-constant-face))
133-
(should (eq (elixir-test-face-at 5) 'font-lock-constant-face))
134-
(should (eq (elixir-test-face-at 10) 'font-lock-constant-face))
135-
(should (eq (elixir-test-face-at 13) 'font-lock-constant-face))))
132+
(should (eq (elixir-test-face-at 3) 'elixir-atom-face))
133+
(should (eq (elixir-test-face-at 5) 'elixir-atom-face))
134+
(should (eq (elixir-test-face-at 10) 'elixir-atom-face))
135+
(should (eq (elixir-test-face-at 13) 'elixir-atom-face))))
136136

137137
(ert-deftest elixir-mode-syntax-table/fontify-map-keys ()
138138
:tags '(fontification map syntax-table)
139139
(elixir-test-with-temp-buffer
140140
"%{a: 1, b: 2}"
141-
(should (eq (elixir-test-face-at 3) 'font-lock-constant-face))
142-
(should (eq (elixir-test-face-at 4) 'font-lock-constant-face))
143-
(should (eq (elixir-test-face-at 9) 'font-lock-constant-face))
144-
(should (eq (elixir-test-face-at 10) 'font-lock-constant-face))))
141+
(should (eq (elixir-test-face-at 3) 'elixir-atom-face))
142+
(should (eq (elixir-test-face-at 4) 'elixir-atom-face))
143+
(should (eq (elixir-test-face-at 9) 'elixir-atom-face))
144+
(should (eq (elixir-test-face-at 10) 'elixir-atom-face))))

0 commit comments

Comments
 (0)