Skip to content

Commit 60f29c3

Browse files
qaptoRqaptoR
andauthored
Add dynamic query for coloring n-depth headlines (#780)
accomplished using predicate Co-authored-by: qaptoR <[email protected]>
1 parent 947850a commit 60f29c3

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

lua/orgmode/config/init.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,17 @@ function Config:setup_ts_predicates()
399399
end
400400
metadata['injection.language'] = utils.detect_filetype(text)
401401
end, { force = true })
402+
403+
vim.treesitter.query.add_predicate('org-is-headline-level?', function(match, _, _, predicate)
404+
---@type TSNode
405+
local node = match[predicate[2]]
406+
local level = tonumber(predicate[3])
407+
if not node then
408+
return false
409+
end
410+
local _, _, _, node_end_col = node:range()
411+
return ((node_end_col - 1) % 8) + 1 == level
412+
end, { force = true })
402413
end
403414

404415
---@param content table

queries/org/highlights.scm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
(timestamp "<") @org.timestamp.active
22
(timestamp "[") @org.timestamp.inactive
3-
(headline (stars) @stars (#eq? @stars "*")) @org.headline.level1
4-
(headline (stars) @stars (#eq? @stars "**")) @org.headline.level2
5-
(headline (stars) @stars (#eq? @stars "***")) @org.headline.level3
6-
(headline (stars) @stars (#eq? @stars "****")) @org.headline.level4
7-
(headline (stars) @stars (#eq? @stars "*****")) @org.headline.level5
8-
(headline (stars) @stars (#eq? @stars "******")) @org.headline.level6
9-
(headline (stars) @stars (#eq? @stars "*******")) @org.headline.level7
10-
(headline (stars) @stars (#eq? @stars "********")) @org.headline.level8
113
(headline (item) @spell)
4+
(headline (stars) @stars (#org-is-headline-level? @stars "1")) @org.headline.level1
5+
(headline (stars) @stars (#org-is-headline-level? @stars "2")) @org.headline.level2
6+
(headline (stars) @stars (#org-is-headline-level? @stars "3")) @org.headline.level3
7+
(headline (stars) @stars (#org-is-headline-level? @stars "4")) @org.headline.level4
8+
(headline (stars) @stars (#org-is-headline-level? @stars "5")) @org.headline.level5
9+
(headline (stars) @stars (#org-is-headline-level? @stars "6")) @org.headline.level6
10+
(headline (stars) @stars (#org-is-headline-level? @stars "7")) @org.headline.level7
11+
(headline (stars) @stars (#org-is-headline-level? @stars "8")) @org.headline.level8
1212
(item . (expr) @org.keyword.todo @nospell (#org-is-todo-keyword? @org.keyword.todo "TODO"))
1313
(item . (expr) @org.keyword.done @nospell (#org-is-todo-keyword? @org.keyword.done "DONE"))
1414
(item (expr "[" "#" "str" @_priority "]") @org.priority.highest (#org-is-valid-priority? @_priority "highest"))

0 commit comments

Comments
 (0)