Skip to content

Commit 731d6f5

Browse files
committed
Namespace font-locking according to clojure.lang.LispReader
Fix namespace alias font-locking for aliases containing non-letter charactes like $, 0-9, _, etc.
1 parent 20b0b34 commit 731d6f5

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### New features
66

77
* Indent and font-lock forms that start with `let-`, `while-` or `when-` like their counterparts.
8+
* Namespace font-locking according to clojure.lang.LispReader
89

910
### Bugs fixed
1011

clojure-mode.el

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,13 @@ Called by `imenu--generic-function'."
352352
(set-match-data (list def-beg def-end)))))
353353
(goto-char start)))))
354354

355+
(eval-when-compile
356+
;; See clojure.lang.LispReader definition and getMacro invocation(s)
357+
(defconst clojure-sym-rest-chars "^][\";\'@\\^`~\(\)\{\}\\")
358+
(defconst clojure-sym-1st-chars (concat clojure-sym-rest-chars "0-9"))
359+
(defconst clojure-sym
360+
(concat "[" clojure-sym-1st-chars "][" clojure-sym-rest-chars "]+")))
361+
355362
(defconst clojure-font-lock-keywords
356363
(eval-when-compile
357364
`(;; Top-level variable definition
@@ -381,7 +388,8 @@ Called by `imenu--generic-function'."
381388
(2 font-lock-type-face nil t))
382389
;; Function definition (anything that starts with def and is not
383390
;; listed above)
384-
(,(concat "(\\(?:[a-z\.-]+/\\)?\\(def[^ \r\n\t]*\\)"
391+
(,(concat "(\\(?:" clojure-sym "/\\)?"
392+
"\\(def[^ \r\n\t]*\\)"
385393
;; Function declarations
386394
"\\>"
387395
;; Any whitespace
@@ -461,7 +469,8 @@ Called by `imenu--generic-function'."
461469
;; Character literals - \1, \a, \newline, \u0000
462470
("\\\\\\([[:punct:]]\\|[a-z0-9]+\\>\\)" 0 'clojure-character-face)
463471
;; foo/ Foo/ @Foo/ /FooBar
464-
("\\(?:\\<:?\\|\\.\\)@?\\([a-zA-Z][.a-zA-Z0-9$_-]*\\)\\(/\\)" (1 font-lock-type-face) (2 'default))
472+
(,(concat "\\(?:\\<:?\\|\\.\\)@?\\(" clojure-sym "\\)\\(/\\)")
473+
(1 font-lock-type-face) (2 'default))
465474
;; Constant values (keywords), including as metadata e.g. ^:static
466475
("\\<^?\\(:\\(\\sw\\|\\s_\\)+\\(\\>\\|\\_>\\)\\)" 1 'clojure-keyword-face append)
467476
;; Java interop highlighting

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ POS."
196196

197197
(ert-deftest clojure-mode-syntax-table/namespaced-def ()
198198
:tags '(fontification syntax-table)
199+
(clojure-test-with-temp-buffer "(_c4/defconstrainedfn bar [] nil)"
200+
(should (eq (clojure-test-face-at 2 4) 'font-lock-type-face))
201+
(should (eq (clojure-test-face-at 5 5) 'default))
202+
(should (eq (clojure-test-face-at 6 18) 'font-lock-keyword-face))
203+
(should (eq (clojure-test-face-at 23 25) 'font-lock-function-name-face)))
199204
(clojure-test-with-temp-buffer "(clo/defbar foo nil)"
200205
(should (eq (clojure-test-face-at 2 4) 'font-lock-type-face))
201206
(should (eq (clojure-test-face-at 5 5) 'default))

0 commit comments

Comments
 (0)