Skip to content

Commit a44e4f2

Browse files
author
Vadim Rodionov
committed
Fix font locking for def forms; Add variable 'clojure-font-lock-def-forms' to add custom def forms
1 parent 0af29f4 commit a44e4f2

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

clojure-mode.el

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -823,9 +823,46 @@ any number of matches of `clojure--sym-forbidden-rest-chars'.")
823823
Matches the rule `clojure--keyword-sym-forbidden-1st-chars' followed by
824824
any number of matches of `clojure--sym-forbidden-rest-chars'."))
825825

826+
(defcustom clojure-font-lock-def-forms
827+
'("def"
828+
"defonce"
829+
"defn"
830+
"defn-"
831+
"defmacro"
832+
"definline"
833+
"defmulti"
834+
"defmethod"
835+
"defprotocol"
836+
"definterface"
837+
"defrecord"
838+
"deftype"
839+
"defstruct"
840+
;; clojure.test
841+
"deftest"
842+
"deftest-"
843+
;; clojure.logic
844+
"defne"
845+
"defnm"
846+
"defnu"
847+
"defnc"
848+
"defna"
849+
;; Third party
850+
"deftask"
851+
"defstate")
852+
"List of strings identifying def forms."
853+
:package-version '(clojure-mode . "5.16")
854+
:safe #'listp
855+
:type '(repeat string))
856+
826857
(defconst clojure-font-lock-keywords
827858
(eval-when-compile
828-
`( ;; Top-level variable definition
859+
`(;; Any def form
860+
(,(concat "(\\(?:" clojure--sym-regexp "/\\)?"
861+
"\\("
862+
(regexp-opt clojure-font-lock-def-forms)
863+
"\\)\\>")
864+
(1 font-lock-keyword-face))
865+
;; Top-level variable definition
829866
(,(concat "(\\(?:clojure.core/\\)?\\("
830867
(regexp-opt '("def" "defonce"))
831868
;; variable declarations
@@ -835,7 +872,6 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
835872
;; Possibly type or metadata
836873
"\\(?:#?^\\(?:{[^}]*}\\|\\sw+\\)[ \r\n\t]*\\)*"
837874
"\\(\\sw+\\)?")
838-
(1 font-lock-keyword-face)
839875
(2 font-lock-variable-name-face nil t))
840876
;; Type definition
841877
(,(concat "(\\(?:clojure.core/\\)?\\("
@@ -848,7 +884,6 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
848884
;; Possibly type or metadata
849885
"\\(?:#?^\\(?:{[^}]*}\\|\\sw+\\)[ \r\n\t]*\\)*"
850886
"\\(\\sw+\\)?")
851-
(1 font-lock-keyword-face)
852887
(2 font-lock-type-face nil t))
853888
;; Function definition (anything that starts with def and is not
854889
;; listed above)
@@ -861,21 +896,19 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
861896
;; Possibly type or metadata
862897
"\\(?:#?^\\(?:{[^}]*}\\|\\sw+\\)[ \r\n\t]*\\)*"
863898
(concat "\\(" clojure--sym-regexp "\\)?"))
864-
(1 font-lock-keyword-face)
865899
(2 font-lock-function-name-face nil t))
866900
;; (fn name? args ...)
867901
(,(concat "(\\(?:clojure.core/\\)?\\(fn\\)[ \t]+"
868902
;; Possibly type
869903
"\\(?:#?^\\sw+[ \t]*\\)?"
870904
;; Possibly name
871905
"\\(\\sw+\\)?" )
872-
(1 font-lock-keyword-face)
873906
(2 font-lock-function-name-face nil t))
874907
;; Special forms
875908
(,(concat
876909
"("
877910
(regexp-opt
878-
'("def" "do" "if" "let*" "var" "fn" "fn*" "loop*"
911+
'("do" "if" "let*" "var" "fn" "fn*" "loop*"
879912
"recur" "throw" "try" "catch" "finally"
880913
"set!" "new" "."
881914
"monitor-enter" "monitor-exit" "quote") t)

0 commit comments

Comments
 (0)