0

I'm trying to build an interactive query builder for tree-sitter in Emacs with highlight for matches as underlined text instead of overlays.

So far I nailed most of the code to accomplish this, the only pain point is getting the match in the target buffer underlined.

Assume we have the following face:

(defface tree-sitter-query-faces-match-1
  '((t
     (:underline
      (:color "#00ffff" :style line))))
  "face for match highlight")

This is the function that applies the text properties to the match in buffer:

(defun example--highlight-node (node match-face)
  "Highlight a NODE match in the current buffer with face MATCH-FACE."
  (let* ((capture-name (car node))
         (captured-node (cdr node))
         (node-start (ts-node-start-position captured-node))
         (node-end (ts-node-end-position captured-node))
         (font-lock-face-property `(font-lock-face ,match-face))
         (help-echo-property `(help-echo ,capture-name)))
    ;; add the font-lock face
    (add-text-properties node-start node-end font-lock-face-property)
    ;; and add the name of the capture node, if any.
    (unless (string= capture-name "")
      (add-to-list 'tree-sitter-query--match-highlight-text-property-used help-echo-property)
      (add-text-properties node-start node-end help-echo-property))))

and called like this:

;;; ...
(example--highlight-node a-node tree-sitter-query-faces-match-1)

the help-echo is applied to the match (name is displayed in the echo area as expected), but not so the underlined face:

Emacs running the query builder

My question is, what I'm doing wrong here and how can I apply this other font-lock face on the match in the target buffer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.