Skip to content

[Fix #581] Fix font locking for keywords starting with a number #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
14 changes: 12 additions & 2 deletions clojure-mode.el
Original file line number Diff line number Diff line change
@@ -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))

5 changes: 5 additions & 0 deletions test.clj
Original file line number Diff line number Diff line change
@@ -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}
25 changes: 23 additions & 2 deletions test/clojure-mode-font-lock-test.el
Original file line number Diff line number Diff line change
@@ -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"