diff --git a/CHANGELOG.md b/CHANGELOG.md index d8f864bb..ac6e3d13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### Bugs fixed + +* [#581](https://github.com/clojure-emacs/clojure-mode/issues/581): Fix font locking not working for keywords starting with a number + ## 5.15.1 (2022-07-30) ### Bugs fixed diff --git a/clojure-mode.el b/clojure-mode.el index 5b6c7f79..33ebc6d0 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -780,6 +780,15 @@ definition of 'macros': URL `http://git.io/vRGLD'.") (concat "[^" clojure--sym-forbidden-1st-chars "][^" clojure--sym-forbidden-rest-chars "]*") "A regexp matching a Clojure symbol or namespace alias. Matches the rule `clojure--sym-forbidden-1st-chars' followed by +any number of matches of `clojure--sym-forbidden-rest-chars'.") + (defconst clojure--keyword-sym-forbidden-1st-chars + (concat clojure--sym-forbidden-rest-chars ":'") + "A list of chars that a Clojure keyword symbol cannot start with.") + (defconst clojure--keyword-sym-regexp + (concat "[^" clojure--keyword-sym-forbidden-1st-chars "]" + "[^" clojure--sym-forbidden-rest-chars "]*") + "A regexp matching a Clojure keyword name or keyword namespace. +Matches the rule `clojure--keyword-sym-forbidden-1st-chars' followed by any number of matches of `clojure--sym-forbidden-rest-chars'.")) (defconst clojure-font-lock-keywords @@ -974,13 +983,14 @@ any number of matches of `clojure--sym-forbidden-rest-chars'.")) ;; TODO dedupe the code for matching of keywords, type-hints and unmatched symbols ;; keywords: {:oneword/ve/yCom|pLex.stu-ff 0} - (,(concat "\\(:\\{1,2\\}\\)\\(" clojure--sym-regexp "?\\)\\(/\\)\\(" clojure--sym-regexp "\\)") + (,(concat "\\(:\\{1,2\\}\\)\\(" clojure--keyword-sym-regexp "?\\)\\(/\\)" + "\\(" clojure--keyword-sym-regexp "\\)") (1 'clojure-keyword-face) (2 font-lock-type-face) ;; (2 'clojure-keyword-face) (3 'default) (4 'clojure-keyword-face)) - (,(concat "\\(:\\{1,2\\}\\)\\(" clojure--sym-regexp "\\)") + (,(concat "\\(:\\{1,2\\}\\)\\(" clojure--keyword-sym-regexp "\\)") (1 'clojure-keyword-face) (2 'clojure-keyword-face)) diff --git a/test.clj b/test.clj index 8ec9b947..221380e8 100644 --- a/test.clj +++ b/test.clj @@ -163,6 +163,11 @@ {:oneword/ve/yCom|pLex.stu-ff 0} {:oneword/.ve/yCom|pLex.stu-ff 0} + :1oneword + :ns/1word + :1ns/word + :1ns/1word + {:seg.mnt 0} ;; {:@seg.mnt 0} ; not allowed {:#seg.mnt 0} diff --git a/test/clojure-mode-font-lock-test.el b/test/clojure-mode-font-lock-test.el index b3687aaf..c8304a05 100644 --- a/test/clojure-mode-font-lock-test.el +++ b/test/clojure-mode-font-lock-test.el @@ -487,11 +487,17 @@ DESCRIPTION is the description of the spec." (when-fontifying-it "should handle oneword keywords" (" :oneword" - (3 9 clojure-keyword-face )) + (3 9 clojure-keyword-face)) + + (" :1oneword" + (3 10 clojure-keyword-face)) ("{:oneword 0}" (3 9 clojure-keyword-face)) + ("{:1oneword 0}" + (3 10 clojure-keyword-face)) + ("{:#oneword 0}" (3 10 clojure-keyword-face)) @@ -563,7 +569,22 @@ DESCRIPTION is the description of the spec." (10 17 clojure-keyword-face)) (":_:_:foo/bar_:_:foo" - (10 19 clojure-keyword-face))) + (10 19 clojure-keyword-face)) + + (":1foo/bar" + (2 5 font-lock-type-face) + (6 6 default) + (7 9 clojure-keyword-face)) + + (":foo/1bar" + (2 4 font-lock-type-face) + (5 5 default) + (6 9 clojure-keyword-face)) + + (":1foo/1bar" + (2 5 font-lock-type-face) + (6 6 default) + (7 10 clojure-keyword-face))) (when-fontifying-it "should handle segment keywords" (" :seg.mnt"