Skip to content

Commit 0be365a

Browse files
authored
[Fix #581] Fix font locking for keywords starting with a number (#628)
1 parent ad322e9 commit 0be365a

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## master (unreleased)
44

5+
### Bugs fixed
6+
7+
* [#581](https://github.com/clojure-emacs/clojure-mode/issues/581): Fix font locking not working for keywords starting with a number
8+
59
## 5.15.1 (2022-07-30)
610

711
### Bugs fixed

Diff for: clojure-mode.el

+12-2
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,15 @@ definition of 'macros': URL `http://git.io/vRGLD'.")
780780
(concat "[^" clojure--sym-forbidden-1st-chars "][^" clojure--sym-forbidden-rest-chars "]*")
781781
"A regexp matching a Clojure symbol or namespace alias.
782782
Matches the rule `clojure--sym-forbidden-1st-chars' followed by
783+
any number of matches of `clojure--sym-forbidden-rest-chars'.")
784+
(defconst clojure--keyword-sym-forbidden-1st-chars
785+
(concat clojure--sym-forbidden-rest-chars ":'")
786+
"A list of chars that a Clojure keyword symbol cannot start with.")
787+
(defconst clojure--keyword-sym-regexp
788+
(concat "[^" clojure--keyword-sym-forbidden-1st-chars "]"
789+
"[^" clojure--sym-forbidden-rest-chars "]*")
790+
"A regexp matching a Clojure keyword name or keyword namespace.
791+
Matches the rule `clojure--keyword-sym-forbidden-1st-chars' followed by
783792
any number of matches of `clojure--sym-forbidden-rest-chars'."))
784793

785794
(defconst clojure-font-lock-keywords
@@ -974,13 +983,14 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
974983
;; TODO dedupe the code for matching of keywords, type-hints and unmatched symbols
975984

976985
;; keywords: {:oneword/ve/yCom|pLex.stu-ff 0}
977-
(,(concat "\\(:\\{1,2\\}\\)\\(" clojure--sym-regexp "?\\)\\(/\\)\\(" clojure--sym-regexp "\\)")
986+
(,(concat "\\(:\\{1,2\\}\\)\\(" clojure--keyword-sym-regexp "?\\)\\(/\\)"
987+
"\\(" clojure--keyword-sym-regexp "\\)")
978988
(1 'clojure-keyword-face)
979989
(2 font-lock-type-face)
980990
;; (2 'clojure-keyword-face)
981991
(3 'default)
982992
(4 'clojure-keyword-face))
983-
(,(concat "\\(:\\{1,2\\}\\)\\(" clojure--sym-regexp "\\)")
993+
(,(concat "\\(:\\{1,2\\}\\)\\(" clojure--keyword-sym-regexp "\\)")
984994
(1 'clojure-keyword-face)
985995
(2 'clojure-keyword-face))
986996

Diff for: test.clj

+5
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@
163163
{:oneword/ve/yCom|pLex.stu-ff 0}
164164
{:oneword/.ve/yCom|pLex.stu-ff 0}
165165

166+
:1oneword
167+
:ns/1word
168+
:1ns/word
169+
:1ns/1word
170+
166171
{:seg.mnt 0}
167172
;; {:@seg.mnt 0} ; not allowed
168173
{:#seg.mnt 0}

Diff for: test/clojure-mode-font-lock-test.el

+23-2
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,17 @@ DESCRIPTION is the description of the spec."
487487

488488
(when-fontifying-it "should handle oneword keywords"
489489
(" :oneword"
490-
(3 9 clojure-keyword-face ))
490+
(3 9 clojure-keyword-face))
491+
492+
(" :1oneword"
493+
(3 10 clojure-keyword-face))
491494

492495
("{:oneword 0}"
493496
(3 9 clojure-keyword-face))
494497

498+
("{:1oneword 0}"
499+
(3 10 clojure-keyword-face))
500+
495501
("{:#oneword 0}"
496502
(3 10 clojure-keyword-face))
497503

@@ -563,7 +569,22 @@ DESCRIPTION is the description of the spec."
563569
(10 17 clojure-keyword-face))
564570

565571
(":_:_:foo/bar_:_:foo"
566-
(10 19 clojure-keyword-face)))
572+
(10 19 clojure-keyword-face))
573+
574+
(":1foo/bar"
575+
(2 5 font-lock-type-face)
576+
(6 6 default)
577+
(7 9 clojure-keyword-face))
578+
579+
(":foo/1bar"
580+
(2 4 font-lock-type-face)
581+
(5 5 default)
582+
(6 9 clojure-keyword-face))
583+
584+
(":1foo/1bar"
585+
(2 5 font-lock-type-face)
586+
(6 6 default)
587+
(7 10 clojure-keyword-face)))
567588

568589
(when-fontifying-it "should handle segment keywords"
569590
(" :seg.mnt"

0 commit comments

Comments
 (0)