Skip to content
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

Fix character font lock #588

Merged
merged 1 commit into from May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@
* [#574](https://github.com/clojure-emacs/clojure-mode/issues/574): Remove `clojure-view-grimoire` command.
* Stop `clojure-sort-ns` from calling `redisplay`.
* [#584](https://github.com/clojure-emacs/clojure-mode/issues/584): Align to recent `pcase` changes on Emacs master.
* [#588](https://github.com/clojure-emacs/clojure-mode/pull/588): Fix font-lock for character literals.

## 5.12.0 (2020-08-13)

Expand Down
20 changes: 10 additions & 10 deletions clojure-mode.el
Expand Up @@ -801,8 +801,6 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
"\\(\\sw+\\)?" )
(1 font-lock-keyword-face)
(2 font-lock-function-name-face nil t))
;; lambda arguments - %, %&, %1, %2, etc
("\\<%[&1-9]?" (0 font-lock-variable-name-face))
;; Special forms
(,(concat
"("
Expand Down Expand Up @@ -862,14 +860,16 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
"\\>")
0 font-lock-constant-face)
;; Character literals - \1, \a, \newline, \u0000
(,(rx "\\" (or any
"newline" "space" "tab" "formfeed" "backspace"
"return"
(: "u" (= 4 (char "0-9a-fA-F")))
(: "o" (repeat 1 3 (char "0-7"))))
word-boundary)
0 'clojure-character-face)

(,(rx (group "\\" (or any
"newline" "space" "tab" "formfeed" "backspace"
"return"
(: "u" (= 4 (char "0-9a-fA-F")))
(: "o" (repeat 1 3 (char "0-7")))))
(or (not word) word-boundary))
1 'clojure-character-face)
;; lambda arguments - %, %&, %1, %2, etc
;; must come after character literals for \% to be handled properly
("\\<%[&1-9]?" (0 font-lock-variable-name-face))
;; namespace definitions: (ns foo.bar)
(,(concat "(\\<ns\\>[ \r\n\t]*"
;; Possibly metadata, shorthand and/or longhand
Expand Down
2 changes: 1 addition & 1 deletion test.clj
Expand Up @@ -51,7 +51,7 @@
minnow))

;; character literals
[\a \newline \u0032 \/ \+ \,, \;]
[\a \newline \u0032 \/ \+ \,, \; \( \% \)]

;; TODO change font-face for sexps starting with @,#
(comment ;; examples
Expand Down
16 changes: 16 additions & 0 deletions test/clojure-mode-font-lock-test.el
Expand Up @@ -942,6 +942,22 @@ DESCRIPTION is the description of the spec."
("\\ク"
(1 2 clojure-character-face)))

(when-fontifying-it "should handle characters not by themselves"
("[\\,,]"
(1 1 nil)
(2 3 clojure-character-face)
(4 5 nil))

("[\\[]"
(1 1 nil)
(2 3 clojure-character-face)
(4 4 nil)))

(when-fontifying-it "should handle % character literal"
("#(str \\% %)"
(7 8 clojure-character-face)
(10 10 font-lock-variable-name-face)))

(when-fontifying-it "should handle referred vars"
("foo/var"
(1 3 font-lock-type-face))
Expand Down