Skip to content

Commit

Permalink
Add dynamic query for coloring n-depth headlines (nvim-orgmode#780)
Browse files Browse the repository at this point in the history
accomplished using predicate

Co-authored-by: qaptoR <rocco.ruscitti@outlook.com>
  • Loading branch information
qaptoR and qaptoR authored Jul 24, 2024
1 parent 25967ed commit 884d2b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
11 changes: 11 additions & 0 deletions lua/orgmode/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,17 @@ function Config:setup_ts_predicates()
end
metadata['injection.language'] = utils.detect_filetype(text)
end, { force = true })

vim.treesitter.query.add_predicate('org-is-headline-level?', function(match, _, _, predicate)
---@type TSNode
local node = match[predicate[2]]
local level = tonumber(predicate[3])
if not node then
return false
end
local _, _, _, node_end_col = node:range()
return ((node_end_col - 1) % 8) + 1 == level
end, { force = true })
end

---@param content table
Expand Down
16 changes: 8 additions & 8 deletions queries/org/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
(timestamp "<") @org.timestamp.active
(timestamp "[") @org.timestamp.inactive
(headline (stars) @stars (#eq? @stars "*")) @org.headline.level1
(headline (stars) @stars (#eq? @stars "**")) @org.headline.level2
(headline (stars) @stars (#eq? @stars "***")) @org.headline.level3
(headline (stars) @stars (#eq? @stars "****")) @org.headline.level4
(headline (stars) @stars (#eq? @stars "*****")) @org.headline.level5
(headline (stars) @stars (#eq? @stars "******")) @org.headline.level6
(headline (stars) @stars (#eq? @stars "*******")) @org.headline.level7
(headline (stars) @stars (#eq? @stars "********")) @org.headline.level8
(headline (item) @spell)
(headline (stars) @stars (#org-is-headline-level? @stars "1")) @org.headline.level1
(headline (stars) @stars (#org-is-headline-level? @stars "2")) @org.headline.level2
(headline (stars) @stars (#org-is-headline-level? @stars "3")) @org.headline.level3
(headline (stars) @stars (#org-is-headline-level? @stars "4")) @org.headline.level4
(headline (stars) @stars (#org-is-headline-level? @stars "5")) @org.headline.level5
(headline (stars) @stars (#org-is-headline-level? @stars "6")) @org.headline.level6
(headline (stars) @stars (#org-is-headline-level? @stars "7")) @org.headline.level7
(headline (stars) @stars (#org-is-headline-level? @stars "8")) @org.headline.level8
(item . (expr) @org.keyword.todo @nospell (#org-is-todo-keyword? @org.keyword.todo "TODO"))
(item . (expr) @org.keyword.done @nospell (#org-is-todo-keyword? @org.keyword.done "DONE"))
(item (expr "[" "#" "str" @_priority "]") @org.priority.highest (#org-is-valid-priority? @_priority "highest"))
Expand Down

0 comments on commit 884d2b1

Please sign in to comment.