Skip to content

Commit 9ac4fa0

Browse files
committed
Make three font-lock faces customizable
1 parent 610d1f6 commit 9ac4fa0

File tree

3 files changed

+45
-24
lines changed

3 files changed

+45
-24
lines changed

CHANGELOG.md

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

55
### Changes
66

7+
* Introduce `clojure-global-constant-face`, `clojure-def-symbol-face`, `clojure-lambda-arg-face`.
78
* Indent `fdef` (clojure.spec) like a `def`.
89
* The results of `clojure-project-dir` are cached by default to optimize performance.
910
* Add `shadow-cljs.edn` to the default list of build tool files.

clojure-mode.el

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,26 @@
9292
"Face used to font-lock Clojure character literals."
9393
:package-version '(clojure-mode . "3.0.0"))
9494

95+
(defface clojure-interop-method-face
96+
'((t (:inherit font-lock-preprocessor-face)))
97+
"Face used to font-lock interop method names (camelCase)."
98+
:package-version '(clojure-mode . "3.0.0"))
99+
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+
95115
(defcustom clojure-indent-style :always-align
96116
"Indentation style to use for function forms and macro forms.
97117
There are two cases of interest configured by this variable.
@@ -754,7 +774,7 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
754774
;; Possibly type or metadata
755775
"\\(?:#?^\\(?:{[^}]*}\\|\\sw+\\)[ \r\n\t]*\\)*"
756776
"\\(\\sw+\\)?")
757-
(1 font-lock-keyword-face)
777+
(1 'clojure-def-symbol-face)
758778
(2 font-lock-variable-name-face nil t))
759779
;; Type definition
760780
(,(concat "(\\(?:clojure.core/\\)?\\("
@@ -767,7 +787,7 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
767787
;; Possibly type or metadata
768788
"\\(?:#?^\\(?:{[^}]*}\\|\\sw+\\)[ \r\n\t]*\\)*"
769789
"\\(\\sw+\\)?")
770-
(1 font-lock-keyword-face)
790+
(1 'clojure-def-symbol-face)
771791
(2 font-lock-type-face nil t))
772792
;; Function definition (anything that starts with def and is not
773793
;; listed above)
@@ -780,7 +800,7 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
780800
;; Possibly type or metadata
781801
"\\(?:#?^\\(?:{[^}]*}\\|\\sw+\\)[ \r\n\t]*\\)*"
782802
"\\(\\sw+\\)?")
783-
(1 font-lock-keyword-face)
803+
(1 'clojure-def-symbol-face)
784804
(2 font-lock-function-name-face nil t))
785805
;; (fn name? args ...)
786806
(,(concat "(\\(?:clojure.core/\\)?\\(fn\\)[ \t]+"
@@ -791,7 +811,7 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
791811
(1 font-lock-keyword-face)
792812
(2 font-lock-function-name-face nil t))
793813
;; lambda arguments - %, %&, %1, %2, etc
794-
("\\<%[&1-9]?" (0 font-lock-variable-name-face))
814+
("\\<%[&1-9]?" (0 'clojure-lambda-arg-face))
795815
;; Special forms
796816
(,(concat
797817
"("
@@ -848,7 +868,7 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
848868
(regexp-opt
849869
'("true" "false" "nil") t)
850870
"\\>")
851-
0 font-lock-constant-face)
871+
0 'clojure-global-constant-face)
852872
;; Character literals - \1, \a, \newline, \u0000
853873
("\\\\\\([[:punct:]]\\|[a-z0-9]+\\>\\)" 0 'clojure-character-face)
854874

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ POS."
113113
(ert-deftest clojure-mode-syntax-table/fontify-let-when-while-type-forms ()
114114
:tags '(fontification syntax-table)
115115
(should (equal (clojure-test-face-at 2 11 "(when-alist [x 1]\n ())")
116-
'font-lock-keyword-face))
116+
'clojure-def-symbol-face))
117117
(should (equal (clojure-test-face-at 2 12 "(while-alist [x 1]\n ())")
118-
'font-lock-keyword-face))
118+
'clojure-def-symbol-face))
119119
(should (equal (clojure-test-face-at 2 10 "(let-alist [x 1]\n ())")
120-
'font-lock-keyword-face)))
120+
'clojure-def-symbol-face)))
121121

122122
(ert-deftest clojure-mode-syntax-table/comment-macros ()
123123
:tags '(fontification syntax-table)
@@ -702,49 +702,49 @@ POS."
702702
(clojure-test-with-temp-buffer "(_c4/defconstrainedfn bar [] nil)"
703703
(should (eq (clojure-test-face-at 2 4) 'font-lock-type-face))
704704
(should (eq (clojure-test-face-at 5 5) nil))
705-
(should (eq (clojure-test-face-at 6 18) 'font-lock-keyword-face))
705+
(should (eq (clojure-test-face-at 6 18) 'clojure-def-symbol-face))
706706
(should (eq (clojure-test-face-at 23 25) 'font-lock-function-name-face)))
707707
(clojure-test-with-temp-buffer "(clo/defbar foo nil)"
708708
(should (eq (clojure-test-face-at 2 4) 'font-lock-type-face))
709709
(should (eq (clojure-test-face-at 5 5) nil))
710-
(should (eq (clojure-test-face-at 6 11) 'font-lock-keyword-face))
710+
(should (eq (clojure-test-face-at 6 11) 'clojure-def-symbol-face))
711711
(should (eq (clojure-test-face-at 13 15) 'font-lock-function-name-face))))
712712

713713
(ert-deftest clojure-mode-syntax-table/variable-def ()
714714
:tags '(fontification syntax-table)
715715
(should (eq (clojure-test-face-at 2 4 "(def foo 10)")
716-
'font-lock-keyword-face))
716+
'clojure-def-symbol-face))
717717
(should (eq (clojure-test-face-at 6 8 "(def foo 10)")
718-
'font-lock-variable-name-face)))
718+
'clojure-lambda-arg-face)))
719719

720720
(ert-deftest clojure-mode-syntax-table/type-def ()
721721
:tags '(fontification syntax-table)
722722
(clojure-test-with-temp-buffer "(deftype Foo)"
723-
(should (eq (clojure-test-face-at 2 8) 'font-lock-keyword-face))
723+
(should (eq (clojure-test-face-at 2 8) 'clojure-def-symbol-face))
724724
(should (eq (clojure-test-face-at 10 12) 'font-lock-type-face))))
725725

726726
(ert-deftest clojure-mode-syntax-table/function-def ()
727727
:tags '(fontification syntax-table)
728728
(clojure-test-with-temp-buffer "(defn foo [x] x)"
729-
(should (eq (clojure-test-face-at 2 5) 'font-lock-keyword-face))
729+
(should (eq (clojure-test-face-at 2 5) 'clojure-def-symbol-face))
730730
(should (eq (clojure-test-face-at 7 9) 'font-lock-function-name-face))))
731731

732732
(ert-deftest clojure-mode-syntax-table/custom-def-with-special-chars1 ()
733733
:tags '(fontification syntax-table)
734734
(clojure-test-with-temp-buffer "(defn* foo [x] x)"
735-
(should (eq (clojure-test-face-at 2 6) 'font-lock-keyword-face))
735+
(should (eq (clojure-test-face-at 2 6) 'clojure-def-symbol-face))
736736
(should (eq (clojure-test-face-at 8 10) 'font-lock-function-name-face))))
737737

738738
(ert-deftest clojure-mode-syntax-table/custom-def-with-special-chars2 ()
739739
:tags '(fontification syntax-table)
740740
(clojure-test-with-temp-buffer "(defsomething! foo [x] x)"
741-
(should (eq (clojure-test-face-at 2 14) 'font-lock-keyword-face))
741+
(should (eq (clojure-test-face-at 2 14) 'clojure-def-symbol-face))
742742
(should (eq (clojure-test-face-at 16 18) 'font-lock-function-name-face))))
743743

744744
(ert-deftest clojure-mode-syntax-table/custom-def-with-special-chars3 ()
745745
:tags '(fontification syntax-table)
746746
(clojure-test-with-temp-buffer "(def-something foo [x] x)"
747-
(should (eq (clojure-test-face-at 2 14) 'font-lock-keyword-face))
747+
(should (eq (clojure-test-face-at 2 14) 'clojure-def-symbol-face))
748748
(should (eq (clojure-test-face-at 16 18) 'font-lock-function-name-face))))
749749

750750
(ert-deftest clojure-mode-syntax-table/fn ()
@@ -758,26 +758,26 @@ POS."
758758
(ert-deftest clojure-mode-syntax-table/lambda-params ()
759759
:tags '(fontification syntax-table)
760760
(clojure-test-with-temp-buffer "#(+ % %2 %3 %&)"
761-
(should (eq (clojure-test-face-at 5 5) 'font-lock-variable-name-face))
762-
(should (eq (clojure-test-face-at 7 8) 'font-lock-variable-name-face))
763-
(should (eq (clojure-test-face-at 10 11) 'font-lock-variable-name-face))
764-
(should (eq (clojure-test-face-at 13 14) 'font-lock-variable-name-face))))
761+
(should (eq (clojure-test-face-at 5 5) 'clojure-lambda-arg-face))
762+
(should (eq (clojure-test-face-at 7 8) 'clojure-lambda-arg-face))
763+
(should (eq (clojure-test-face-at 10 11) 'clojure-lambda-arg-face))
764+
(should (eq (clojure-test-face-at 13 14) 'clojure-lambda-arg-face))))
765765

766766
(ert-deftest clojure-mode-syntax-table/nil ()
767767
:tags '(fontification syntax-table)
768-
(should (eq (clojure-test-face-at 4 6 "(= nil x)") 'font-lock-constant-face))
768+
(should (eq (clojure-test-face-at 4 6 "(= nil x)") 'clojure-global-constant-face))
769769
(should-not (eq (clojure-test-face-at 3 5 "(fnil x)")
770770
'font-lock-constant-face)))
771771

772772
(ert-deftest clojure-mode-syntax-table/true ()
773773
:tags '(fontification syntax-table)
774774
(should (eq (clojure-test-face-at 4 7 "(= true x)")
775-
'font-lock-constant-face)))
775+
'clojure-global-constant-face)))
776776

777777
(ert-deftest clojure-mode-syntax-table/false ()
778778
:tags '(fontification syntax-table)
779779
(should (eq (clojure-test-face-at 4 8 "(= false x)")
780-
'font-lock-constant-face)))
780+
'clojure-global-constant-face)))
781781

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

0 commit comments

Comments
 (0)