Skip to content

Commit f8dc91b

Browse files
committed
Make three font-lock faces customizable
Introduce `clojure-global-constant-face`, `clojure-def-symbol-face`, `clojure-lambda-arg-face`
1 parent 118c197 commit f8dc91b

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### New features
66

7+
* Introduce `clojure-global-constant-face`, `clojure-def-symbol-face`, `clojure-lambda-arg-face`.
78
* Add imenu support for multimethods.
89
* Make imenu recognize indented def-forms.
910
* New interactive command `clojure-cycle-when`.

clojure-mode.el

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@
9797
"Face used to font-lock interop method names (camelCase)."
9898
:package-version '(clojure-mode . "3.0.0"))
9999

100+
(defface clojure-global-constant-face
101+
'((t (:inherit font-lock-constant-face)))
102+
"Face used to font-lock the Clojure global constants: nil, true, false."
103+
:package-version '(clojure-mode . "3.0.0"))
104+
105+
(defface clojure-def-symbol-face
106+
'((t (:inherit font-lock-keyword-face)))
107+
"Face used to font-lock the symbols `def`, `defn`, and all detected variants (be them from clojure.core or not)."
108+
:package-version '(clojure-mode . "3.0.0"))
109+
110+
(defface clojure-lambda-arg-face
111+
'((t (:inherit font-lock-variable-name-face)))
112+
"Face used to font-lock the function literal args: %, %&, %1 and so on."
113+
:package-version '(clojure-mode . "3.0.0"))
114+
100115
(defcustom clojure-indent-style :always-align
101116
"Indentation style to use for function forms and macro forms.
102117
There are two cases of interest configured by this variable.
@@ -750,7 +765,7 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
750765
;; Possibly type or metadata
751766
"\\(?:#?^\\(?:{[^}]*}\\|\\sw+\\)[ \r\n\t]*\\)*"
752767
"\\(\\sw+\\)?")
753-
(1 font-lock-keyword-face)
768+
(1 'clojure-def-symbol-face)
754769
(2 font-lock-variable-name-face nil t))
755770
;; Type definition
756771
(,(concat "(\\(?:clojure.core/\\)?\\("
@@ -763,7 +778,7 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
763778
;; Possibly type or metadata
764779
"\\(?:#?^\\(?:{[^}]*}\\|\\sw+\\)[ \r\n\t]*\\)*"
765780
"\\(\\sw+\\)?")
766-
(1 font-lock-keyword-face)
781+
(1 'clojure-def-symbol-face)
767782
(2 font-lock-type-face nil t))
768783
;; Function definition (anything that starts with def and is not
769784
;; listed above)
@@ -776,7 +791,7 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
776791
;; Possibly type or metadata
777792
"\\(?:#?^\\(?:{[^}]*}\\|\\sw+\\)[ \r\n\t]*\\)*"
778793
"\\(\\sw+\\)?")
779-
(1 font-lock-keyword-face)
794+
(1 'clojure-def-symbol-face)
780795
(2 font-lock-function-name-face nil t))
781796
;; (fn name? args ...)
782797
(,(concat "(\\(?:clojure.core/\\)?\\(fn\\)[ \t]+"
@@ -787,7 +802,7 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
787802
(1 font-lock-keyword-face)
788803
(2 font-lock-function-name-face nil t))
789804
;; lambda arguments - %, %&, %1, %2, etc
790-
("\\<%[&1-9]?" (0 font-lock-variable-name-face))
805+
("\\<%[&1-9]?" (0 'clojure-lambda-arg-face))
791806
;; Special forms
792807
(,(concat
793808
"("
@@ -844,7 +859,7 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
844859
(regexp-opt
845860
'("true" "false" "nil") t)
846861
"\\>")
847-
0 font-lock-constant-face)
862+
0 'clojure-global-constant-face)
848863
;; Character literals - \1, \a, \newline, \u0000
849864
("\\\\\\([[:punct:]]\\|[a-z0-9]+\\>\\)" 0 'clojure-character-face)
850865
;; foo/ Foo/ @Foo/ /FooBar

test/clojure-mode-font-lock-test.el

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -221,48 +221,48 @@ POS."
221221
(clojure-test-with-temp-buffer "(_c4/defconstrainedfn bar [] nil)"
222222
(should (eq (clojure-test-face-at 2 4) 'font-lock-type-face))
223223
(should (eq (clojure-test-face-at 5 5) 'default))
224-
(should (eq (clojure-test-face-at 6 18) 'font-lock-keyword-face))
224+
(should (eq (clojure-test-face-at 6 18) 'clojure-def-symbol-face))
225225
(should (eq (clojure-test-face-at 23 25) 'font-lock-function-name-face)))
226226
(clojure-test-with-temp-buffer "(clo/defbar foo nil)"
227227
(should (eq (clojure-test-face-at 2 4) 'font-lock-type-face))
228228
(should (eq (clojure-test-face-at 5 5) 'default))
229-
(should (eq (clojure-test-face-at 6 11) 'font-lock-keyword-face))
229+
(should (eq (clojure-test-face-at 6 11) 'clojure-def-symbol-face))
230230
(should (eq (clojure-test-face-at 13 15) 'font-lock-function-name-face))))
231231

232232
(ert-deftest clojure-mode-syntax-table/variable-def ()
233233
:tags '(fontification syntax-table)
234234
(clojure-test-with-temp-buffer "(def foo 10)"
235-
(should (eq (clojure-test-face-at 2 4) 'font-lock-keyword-face))
235+
(should (eq (clojure-test-face-at 2 4) 'clojure-def-symbol-face))
236236
(should (eq (clojure-test-face-at 6 8) 'font-lock-variable-name-face))))
237237

238238
(ert-deftest clojure-mode-syntax-table/type-def ()
239239
:tags '(fontification syntax-table)
240240
(clojure-test-with-temp-buffer "(deftype Foo)"
241-
(should (eq (clojure-test-face-at 2 8) 'font-lock-keyword-face))
241+
(should (eq (clojure-test-face-at 2 8) 'clojure-def-symbol-face))
242242
(should (eq (clojure-test-face-at 10 12) 'font-lock-type-face))))
243243

244244
(ert-deftest clojure-mode-syntax-table/function-def ()
245245
:tags '(fontification syntax-table)
246246
(clojure-test-with-temp-buffer "(defn foo [x] x)"
247-
(should (eq (clojure-test-face-at 2 5) 'font-lock-keyword-face))
247+
(should (eq (clojure-test-face-at 2 5) 'clojure-def-symbol-face))
248248
(should (eq (clojure-test-face-at 7 9) 'font-lock-function-name-face))))
249249

250250
(ert-deftest clojure-mode-syntax-table/custom-def-with-special-chars1 ()
251251
:tags '(fontification syntax-table)
252252
(clojure-test-with-temp-buffer "(defn* foo [x] x)"
253-
(should (eq (clojure-test-face-at 2 6) 'font-lock-keyword-face))
253+
(should (eq (clojure-test-face-at 2 6) 'clojure-def-symbol-face))
254254
(should (eq (clojure-test-face-at 8 10) 'font-lock-function-name-face))))
255255

256256
(ert-deftest clojure-mode-syntax-table/custom-def-with-special-chars2 ()
257257
:tags '(fontification syntax-table)
258258
(clojure-test-with-temp-buffer "(defsomething! foo [x] x)"
259-
(should (eq (clojure-test-face-at 2 14) 'font-lock-keyword-face))
259+
(should (eq (clojure-test-face-at 2 14) 'clojure-def-symbol-face))
260260
(should (eq (clojure-test-face-at 16 18) 'font-lock-function-name-face))))
261261

262262
(ert-deftest clojure-mode-syntax-table/custom-def-with-special-chars3 ()
263263
:tags '(fontification syntax-table)
264264
(clojure-test-with-temp-buffer "(def-something foo [x] x)"
265-
(should (eq (clojure-test-face-at 2 14) 'font-lock-keyword-face))
265+
(should (eq (clojure-test-face-at 2 14) 'clojure-def-symbol-face))
266266
(should (eq (clojure-test-face-at 16 18) 'font-lock-function-name-face))))
267267

268268
(ert-deftest clojure-mode-syntax-table/fn ()
@@ -274,23 +274,23 @@ POS."
274274
(ert-deftest clojure-mode-syntax-table/lambda-params ()
275275
:tags '(fontification syntax-table)
276276
(clojure-test-with-temp-buffer "#(+ % %2 %3 %&)"
277-
(should (eq (clojure-test-face-at 5 5) 'font-lock-variable-name-face))
278-
(should (eq (clojure-test-face-at 7 8) 'font-lock-variable-name-face))
279-
(should (eq (clojure-test-face-at 10 11) 'font-lock-variable-name-face))
280-
(should (eq (clojure-test-face-at 13 14) 'font-lock-variable-name-face))))
277+
(should (eq (clojure-test-face-at 5 5) 'clojure-lambda-arg-face))
278+
(should (eq (clojure-test-face-at 7 8) 'clojure-lambda-arg-face))
279+
(should (eq (clojure-test-face-at 10 11) 'clojure-lambda-arg-face))
280+
(should (eq (clojure-test-face-at 13 14) 'clojure-lambda-arg-face))))
281281

282282
(ert-deftest clojure-mode-syntax-table/nil ()
283283
:tags '(fontification syntax-table)
284-
(should (eq (clojure-test-face-at 4 6 "(= nil x)") 'font-lock-constant-face))
285-
(should-not (eq (clojure-test-face-at 3 5 "(fnil x)") 'font-lock-constant-face)))
284+
(should (eq (clojure-test-face-at 4 6 "(= nil x)") 'clojure-global-constant-face))
285+
(should-not (eq (clojure-test-face-at 3 5 "(fnil x)") 'clojure-global-constant-face)))
286286

287287
(ert-deftest clojure-mode-syntax-table/true ()
288288
:tags '(fontification syntax-table)
289-
(should (eq (clojure-test-face-at 4 7 "(= true x)") 'font-lock-constant-face)))
289+
(should (eq (clojure-test-face-at 4 7 "(= true x)") 'clojure-global-constant-face)))
290290

291291
(ert-deftest clojure-mode-syntax-table/false ()
292292
:tags '(fontification syntax-table)
293-
(should (eq (clojure-test-face-at 4 8 "(= false x)") 'font-lock-constant-face)))
293+
(should (eq (clojure-test-face-at 4 8 "(= false x)") 'clojure-global-constant-face)))
294294

295295
(ert-deftest clojure-mode-syntax-table/keyword-meta ()
296296
:tags '(fontification syntax-table)

0 commit comments

Comments
 (0)