Skip to content

Commit

Permalink
Prioritize patterns that appear earlier in the highlighting query
Browse files Browse the repository at this point in the history
  • Loading branch information
ubolonton committed Apr 20, 2020
1 parent 916f071 commit 5a9a841
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lisp/tree-sitter-hl.el
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,22 @@ It also expects VALUE to be a single value, not a list."
(ts--point-from-position beg)
(ts--point-from-position end))
(let* ((root-node (ts-root-node tree-sitter-tree))
;; TODO: Use `ts-query-matches', for pattern priority.
(captures (ts-query-captures
(matches (ts-query-matches
tree-sitter-hl--query
root-node
tree-sitter-hl--query-cursor
nil
#'ts--node-text)))
(sort matches (lambda (m1 m2)
(< (car m1) (car m2))))
;; TODO: Handle quitting.
(with-silent-modifications
(font-lock-unfontify-region beg end)
;; TODO: Handle uncaptured nodes.
(seq-do #'tree-sitter-hl--highlight-capture captures))
(let ((inhibit-point-motion-hooks t))
(with-silent-modifications
(font-lock-unfontify-region beg end)
;; TODO: Handle uncaptured nodes.
(seq-doseq (match matches)
(pcase-let ((`(_ . ,captures) match))
(seq-do #'tree-sitter-hl--highlight-capture captures)))))
;; TODO: Return the actual region being fontified.
`(jit-lock-bounds ,beg . ,end))))

Expand Down

0 comments on commit 5a9a841

Please sign in to comment.