From 88f75d0184e7b7024b2a4e45b66c4e6d2fad8ea2 Mon Sep 17 00:00:00 2001 From: Dave Liepmann Date: Tue, 21 Nov 2023 15:02:35 +0100 Subject: [PATCH 1/4] Don't highlight vars with colons as keywords 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 --- clojure-mode.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clojure-mode.el b/clojure-mode.el index e3d554de..a9a6a0b0 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -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)) From fc987b4b8e0f41f1287d143dd3a2ede96976f254 Mon Sep 17 00:00:00 2001 From: Dave Liepmann Date: Tue, 21 Nov 2023 19:53:06 +0100 Subject: [PATCH 2/4] tests: colons in the middle of a var name --- test/clojure-mode-font-lock-test.el | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/clojure-mode-font-lock-test.el b/test/clojure-mode-font-lock-test.el index bb6ef74d..0826cf44 100644 --- a/test/clojure-mode-font-lock-test.el +++ b/test/clojure-mode-font-lock-test.el @@ -262,6 +262,9 @@ DESCRIPTION is the description of the spec." (9 10 nil) (11 16 nil)) + ("(colons:are:okay)" + (2 16 nil)) + ("(oneword/ve/yCom|pLex.stu-ff)" (2 8 font-lock-type-face) (9 10 nil) @@ -824,7 +827,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\")" From cc955facdb170cbaa4c0c80e095cbfe442ab34e6 Mon Sep 17 00:00:00 2001 From: Dave Liepmann Date: Tue, 21 Nov 2023 19:56:56 +0100 Subject: [PATCH 3/4] test: font-lock on namespaced var w/middle colons --- test/clojure-mode-font-lock-test.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/clojure-mode-font-lock-test.el b/test/clojure-mode-font-lock-test.el index 0826cf44..5c7d6927 100644 --- a/test/clojure-mode-font-lock-test.el +++ b/test/clojure-mode-font-lock-test.el @@ -265,6 +265,10 @@ DESCRIPTION is the description of the spec." ("(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) From bb1c624b40e8c72a6b2d12975e2ed2beb9d40b9e Mon Sep 17 00:00:00 2001 From: Dave Liepmann Date: Wed, 22 Nov 2023 08:45:40 +0100 Subject: [PATCH 4/4] test: font-lock on keywords w/middle colons --- test/clojure-mode-font-lock-test.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/clojure-mode-font-lock-test.el b/test/clojure-mode-font-lock-test.el index 5c7d6927..5e578ba1 100644 --- a/test/clojure-mode-font-lock-test.el +++ b/test/clojure-mode-font-lock-test.el @@ -722,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)