Skip to content

Commit 2670ae1

Browse files
committed
Merge pull request #353 from Bost/font-locking
Namespace font-locking according to clojure.lang.LispReader
2 parents 20b0b34 + fc5e092 commit 2670ae1

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Bugs fixed
1010

1111
* Namespaces can now use the full palette of legal symbol characters.
12+
* Namespace font-locking according to clojure.lang.LispReader.
1213

1314
## 5.0.1 (15/11/2015)
1415

clojure-mode.el

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

355+
(eval-and-compile
356+
(defconst clojure-sym-rest-chars "^][\";\'@\\^`~\(\)\{\}\\"
357+
"A black list of chars a clojure symbol must not contain. See
358+
definiton of 'macros': URL `http://git.io/vRGLD'.")
359+
(defconst clojure-sym-1st-chars (concat clojure-sym-rest-chars "0-9")
360+
"A black list of chars a clojure symbol must not start with. See
361+
the for-loop: URL `http://git.io/vRGTj' lines:
362+
URL `http://git.io/vRGIh', URL `http://git.io/vRGLE'
363+
and value definition of 'macros': URL `http://git.io/vRGLD'.")
364+
(defconst clojure-sym
365+
(concat "[" clojure-sym-1st-chars "][" clojure-sym-rest-chars "]+")
366+
"A concatenation of black lists:
367+
`clojure-sym-1st-chars', `clojure-sym-rest-chars'."))
368+
355369
(defconst clojure-font-lock-keywords
356370
(eval-when-compile
357371
`(;; Top-level variable definition
@@ -381,7 +395,8 @@ Called by `imenu--generic-function'."
381395
(2 font-lock-type-face nil t))
382396
;; Function definition (anything that starts with def and is not
383397
;; listed above)
384-
(,(concat "(\\(?:[a-z\.-]+/\\)?\\(def[^ \r\n\t]*\\)"
398+
(,(concat "(\\(?:" clojure-sym "/\\)?"
399+
"\\(def[^ \r\n\t]*\\)"
385400
;; Function declarations
386401
"\\>"
387402
;; Any whitespace
@@ -461,7 +476,8 @@ Called by `imenu--generic-function'."
461476
;; Character literals - \1, \a, \newline, \u0000
462477
("\\\\\\([[:punct:]]\\|[a-z0-9]+\\>\\)" 0 'clojure-character-face)
463478
;; foo/ Foo/ @Foo/ /FooBar
464-
("\\(?:\\<:?\\|\\.\\)@?\\([a-zA-Z][.a-zA-Z0-9$_-]*\\)\\(/\\)" (1 font-lock-type-face) (2 'default))
479+
(,(concat "\\(?:\\<:?\\|\\.\\)@?\\(" clojure-sym "\\)\\(/\\)")
480+
(1 font-lock-type-face) (2 'default))
465481
;; Constant values (keywords), including as metadata e.g. ^:static
466482
("\\<^?\\(:\\(\\sw\\|\\s_\\)+\\(\\>\\|\\_>\\)\\)" 1 'clojure-keyword-face append)
467483
;; 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)