Skip to content

Commit

Permalink
Don't highlight vars with colons as keywords (#670)
Browse files Browse the repository at this point in the history
Changes syntax highlighting regexp for keywords to match a colon/double-colon
only at the beginning of a word, not in the middle. This allows local vars like
`foo:bar` to be highlighted correctly instead of like an unknown symbol for the
part before the colon and a keyword for the rest.

Fixes #653
  • Loading branch information
daveliepmann authored Nov 24, 2023
1 parent 481ca48 commit 825f9ab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 3 additions & 2 deletions clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1072,12 +1072,13 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
;; keywords: {:oneword/ve/yCom|pLex.stu-ff 0}
(,(concat "\\(:\\{1,2\\}\\)\\(" clojure--keyword-sym-regexp "?\\)\\(/\\)"
"\\(" clojure--keyword-sym-regexp "\\)")
;; with ns
(1 'clojure-keyword-face)
(2 font-lock-type-face)
;; (2 'clojure-keyword-face)
(3 'default)
(4 'clojure-keyword-face))
(,(concat "\\(:\\{1,2\\}\\)\\(" clojure--keyword-sym-regexp "\\)")
(,(concat "\\<\\(:\\{1,2\\}\\)\\(" clojure--keyword-sym-regexp "\\)")
;; without ns
(1 'clojure-keyword-face)
(2 'clojure-keyword-face))

Expand Down
25 changes: 24 additions & 1 deletion test/clojure-mode-font-lock-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ DESCRIPTION is the description of the spec."
(9 10 nil)
(11 16 nil))

("(colons:are:okay)"
(2 16 nil))

("(some-ns/colons:are:okay)"
(2 8 font-lock-type-face)
(9 24 nil))

("(oneword/ve/yCom|pLex.stu-ff)"
(2 8 font-lock-type-face)
(9 10 nil)
Expand Down Expand Up @@ -715,6 +722,19 @@ DESCRIPTION is the description of the spec."
(10 10 default)
(11 30 clojure-keyword-face)))

(when-fontifying-it "should handle keywords with colons"
(":a:a"
(1 4 clojure-keyword-face))

(":a:a/:a"
(1 7 clojure-keyword-face))

("::a:a"
(1 5 clojure-keyword-face))

("::a.a:a"
(1 7 clojure-keyword-face)))

(when-fontifying-it "should handle very complex keywords"
(" :ve/yCom|pLex.stu-ff"
(3 4 font-lock-type-face)
Expand Down Expand Up @@ -824,7 +844,10 @@ DESCRIPTION is the description of the spec."
(when-fontifying-it "should handle variables defined with def"
("(def foo 10)"
(2 4 font-lock-keyword-face)
(6 8 font-lock-variable-name-face)))
(6 8 font-lock-variable-name-face))
("(def foo:bar 10)"
(2 4 font-lock-keyword-face)
(6 12 font-lock-variable-name-face)))

(when-fontifying-it "should handle variables definitions of type string"
("(def foo \"hello\")"
Expand Down

0 comments on commit 825f9ab

Please sign in to comment.