1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-30 19:53:09 +00:00

Add customizale faces for tree-sitter explorer

* lisp/treesit.el (treesit-explorer-anonymous-node)
(treesit-explorer-field-name): New face.
(treesit--explorer-draw-node): Use the new faces.
(treesit-explore-mode): Change playground to explorer.
This commit is contained in:
Yuan Fu 2022-12-11 14:43:58 -08:00
parent 3e349ee119
commit f2876014ad
No known key found for this signature in database
GPG Key ID: 56E19BC57664A442

View File

@ -1839,6 +1839,18 @@ to the offending pattern and highlight the pattern."
;;; Explorer
(defface treesit-explorer-anonymous-node
(let ((display t)
(atts '(:inherit shadow)))
`((,display . ,atts)))
"Face for anonymous nodes in tree-sitter explorer.")
(defface treesit-explorer-field-name
(let ((display t)
(atts nil))
`((,display . ,atts)))
"Face for field names in tree-sitter explorer.")
(defvar-local treesit--explorer-buffer nil
"Buffer used to display the syntax tree.")
@ -2017,7 +2029,8 @@ leaves point at the end of the last line of NODE."
;; draw everything in one line, other wise draw field name and the
;; rest of the node in two lines.
(when field-name
(insert field-name ": ")
(insert (propertize (concat field-name ": ")
'face 'treesit-explorer-field-name))
(when (and children (not all-children-inline))
(insert "\n")
(indent-to-column (1+ before-field-column))))
@ -2076,7 +2089,7 @@ leaves point at the end of the last line of NODE."
(overlay-put ov 'treesit-node node)
(overlay-put ov 'evaporate t)
(when (not named)
(overlay-put ov 'face 'shadow)))))
(overlay-put ov 'face 'treesit-explorer-anonymous-node)))))
(define-derived-mode treesit--explorer-tree-mode special-mode
"TS Explorer"
@ -2095,7 +2108,7 @@ window."
(unless (buffer-live-p treesit--explorer-buffer)
(setq-local treesit--explorer-buffer
(get-buffer-create
(format "*tree-sitter playground for %s*"
(format "*tree-sitter explorer for %s*"
(buffer-name))))
(setq-local treesit--explorer-language
(intern (completing-read