Skip to content

Commit

Permalink
Fix font locking for def forms; Add variable 'clojure-font-lock-def-f…
Browse files Browse the repository at this point in the history
…orms' to add custom def forms
  • Loading branch information
Vadim Rodionov committed Aug 29, 2022
1 parent 0af29f4 commit a44e4f2
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,46 @@ any number of matches of `clojure--sym-forbidden-rest-chars'.")
Matches the rule `clojure--keyword-sym-forbidden-1st-chars' followed by
any number of matches of `clojure--sym-forbidden-rest-chars'."))

(defcustom clojure-font-lock-def-forms
'("def"
"defonce"
"defn"
"defn-"
"defmacro"
"definline"
"defmulti"
"defmethod"
"defprotocol"
"definterface"
"defrecord"
"deftype"
"defstruct"
;; clojure.test
"deftest"
"deftest-"
;; clojure.logic
"defne"
"defnm"
"defnu"
"defnc"
"defna"
;; Third party
"deftask"
"defstate")
"List of strings identifying def forms."
:package-version '(clojure-mode . "5.16")
:safe #'listp
:type '(repeat string))

(defconst clojure-font-lock-keywords
(eval-when-compile
`( ;; Top-level variable definition
`(;; Any def form
(,(concat "(\\(?:" clojure--sym-regexp "/\\)?"
"\\("
(regexp-opt clojure-font-lock-def-forms)
"\\)\\>")
(1 font-lock-keyword-face))
;; Top-level variable definition
(,(concat "(\\(?:clojure.core/\\)?\\("
(regexp-opt '("def" "defonce"))
;; variable declarations
Expand All @@ -835,7 +872,6 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
;; Possibly type or metadata
"\\(?:#?^\\(?:{[^}]*}\\|\\sw+\\)[ \r\n\t]*\\)*"
"\\(\\sw+\\)?")
(1 font-lock-keyword-face)
(2 font-lock-variable-name-face nil t))
;; Type definition
(,(concat "(\\(?:clojure.core/\\)?\\("
Expand All @@ -848,7 +884,6 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
;; Possibly type or metadata
"\\(?:#?^\\(?:{[^}]*}\\|\\sw+\\)[ \r\n\t]*\\)*"
"\\(\\sw+\\)?")
(1 font-lock-keyword-face)
(2 font-lock-type-face nil t))
;; Function definition (anything that starts with def and is not
;; listed above)
Expand All @@ -861,21 +896,19 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
;; Possibly type or metadata
"\\(?:#?^\\(?:{[^}]*}\\|\\sw+\\)[ \r\n\t]*\\)*"
(concat "\\(" clojure--sym-regexp "\\)?"))
(1 font-lock-keyword-face)
(2 font-lock-function-name-face nil t))
;; (fn name? args ...)
(,(concat "(\\(?:clojure.core/\\)?\\(fn\\)[ \t]+"
;; Possibly type
"\\(?:#?^\\sw+[ \t]*\\)?"
;; Possibly name
"\\(\\sw+\\)?" )
(1 font-lock-keyword-face)
(2 font-lock-function-name-face nil t))
;; Special forms
(,(concat
"("
(regexp-opt
'("def" "do" "if" "let*" "var" "fn" "fn*" "loop*"
'("do" "if" "let*" "var" "fn" "fn*" "loop*"
"recur" "throw" "try" "catch" "finally"
"set!" "new" "."
"monitor-enter" "monitor-exit" "quote") t)
Expand Down

0 comments on commit a44e4f2

Please sign in to comment.