Repository navigation
Highlight extra def forms as keywords at font-lock level 4 - #160
Merged
bbatsov merged 1 commit intoOct 29, 2026
Merged
Conversation
The rules built from `clojure-ts-extra-def-forms` are appended after the built-in font-lock queries, and without :override a later rule can't replace a face an earlier one already set. At level 4 the `function` feature matches the head of every list, so the head of an extra def form (`defelem`, `>defn`, ...) ends up in font-lock-function-call-face instead of font-lock-keyword-face. `defn` itself is unaffected because the `builtin` rule, which comes before `function`, already colors it. Give the extra `definition` rule :override t, like the `doc` rule that is computed next to it.
bbatsov
force-pushed
the
fix-extra-def-forms-level-4
branch
from
October 29, 2026 06:15
afd9d58 to
d0989b8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
treesit-font-lock-levelset to 4, the head of every form inclojure-ts-extra-def-forms(defelem,>defn, …) is colored as a function call (font-lock-function-call-face) instead of a keyword. The name after it is still colored as a function name.The rules built from
clojure-ts-extra-def-formsare appended after the built-in font-lock queries, and without:overridea later rule can't replace a face that an earlier rule already set. The level 4functionfeature matches the head of every list, so it wins.defnitself isn't affected, because thebuiltinrule comes beforefunctionand already colors it as a keyword.This PR gives the extra
definitionrule:override t, like thedocrule that is computed right next to it inclojure-ts--compute-extra-def-queries.Background
clojure-ts-extra-def-formscame out of #15, which was opened about Guardrails'>defn. The spec added with it runs at the default font-lock level 3, where thefunctionfeature is off, which is why this went unnoticed. Level 4 is opt-in, but it's what you get with e.g.(setq treesit-font-lock-level 4)in Doom Emacs.Examples
Faces at
treesit-font-lock-level4 with(setopt clojure-ts-extra-def-forms '("defelem" ">defn")), printed by a small batch script run against both checkouts.defelem(the README example)defelemfile-uploadmainfont-lock-function-call-facefont-lock-function-name-facefont-lock-keyword-facefont-lock-function-name-faceGuardrails
>defn(>defn f [x] x)>defnfmainfont-lock-function-call-facefont-lock-function-name-facefont-lock-keyword-facefont-lock-function-name-face>defnwith metadata before the name(>defn ^:private f [x] x)>defnfmainfont-lock-function-call-facefont-lock-function-name-facefont-lock-keyword-facefont-lock-function-name-faceTests
This PR adds a new spec,
should highlight extra def forms as keywords at font-lock level 4. It fails onmain(the head getsfont-lock-function-call-face) and passes with this PR.How it was checked locally, on Emacs 31.1.50:
It wasn't run locally on Emacs 30.1 this time, so that's left to CI.
Related
This is independent of the series #153–#159 and only touches font-lock. It conflicts with them only in
CHANGELOG.md, and we're happy to rebase.About this PR
The code, tests and this description were generated by an AI (Claude, by Anthropic), at @jasonjckn's request. If AI-generated contributions are a problem for this project, please feel free to close this PR right away.
M-x checkdocand fixed any warnings in the code you've written.