[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to add pseudo vector types
From: |
Yuan Fu |
Subject: |
Re: How to add pseudo vector types |
Date: |
Sat, 24 Jul 2021 11:04:35 -0400 |
I wrote a simple interface between font-lock and tree-sitter, and it works
pretty well: using tree-sitter for fontification, xdisp.c opens a lot faster,
and scrolling through the buffer is also perceivably faster. My simple
interface works like this: tree-sitter allow you to “pattern match” nodes in
the parse tree with a DSL, and assign names to the matched nodes, e.g., given a
pattern, you get back a list of (NAME . MATCHED-NODE). And if we use font-lock
faces as names for those nodes, we get back a list of (FACE . MATCHED-NODE)
from tree-sitter, and Emacs can simply look at the beginning and end of the
node, and apply FACE to that range. For flexibility, FACE can also be a
function, in which case the function is called with the node. This interface is
basically what emacs-tree-sitter does (I don’t know if they allow a capture
name to be a function, though.)
I have an example major-mode for C that uses tree-sitter for font-locking at
the end of tree-sitter.el.
Main functions to look at: tree-sitter-query-capture in tree_sitter.c, and
tree-sitter-fontify-region-function in tree-sitter.el.
On the font-lock front, tree-sitter-fontify-region-function replaces
font-lock-default-fontify-region, and tree-sitter-font-lock-settings replaces
font-lock-defaults and font-lock-keywords. I should support
font-lock-maximum-decoration but haven’t came up with a good way to do that.
Maybe I should somehow reuse font-lock-defaults, and make it able to configure
for tree-sitter font-locking? Apart from font-lock-maximum-decoration, what
else should tree-sitter share with font-lock?
BTW, what is the best way to signal a lisp error from C? I tried xsignal2,
signal_error, error and friends but they seem to crash Emacs. Maybe I wasn’t
using them correctly.
IIUC if we want tree-sitter to use our malloc, we need to build it with Emacs,
where should I put the source of tree-sitter?
What’s the different between make_string and make_pure_c_string? I’ve seen this
“pure” thing else where, what does “pure” mean?
Yuan
ts.4.patch
Description: Binary data
- Re: How to add pseudo vector types, (continued)
- Re: How to add pseudo vector types, Yuan Fu, 2021/07/23
- Re: How to add pseudo vector types, Eli Zaretskii, 2021/07/24
- Re: How to add pseudo vector types, Stephen Leake, 2021/07/25
- Re: How to add pseudo vector types, Eli Zaretskii, 2021/07/25
- Re: How to add pseudo vector types, Stephen Leake, 2021/07/26
- Re: How to add pseudo vector types, Eli Zaretskii, 2021/07/26
- Re: How to add pseudo vector types,
Yuan Fu <=
- Re: How to add pseudo vector types, Eli Zaretskii, 2021/07/24
- Re: How to add pseudo vector types, Yuan Fu, 2021/07/24
- Re: How to add pseudo vector types, Eli Zaretskii, 2021/07/24
- Re: How to add pseudo vector types, Yuan Fu, 2021/07/24
- Re: How to add pseudo vector types, Eli Zaretskii, 2021/07/24
- Re: How to add pseudo vector types, Yuan Fu, 2021/07/24
- Re: How to add pseudo vector types, Eli Zaretskii, 2021/07/24
- Re: How to add pseudo vector types, Stefan Monnier, 2021/07/24
- Re: How to add pseudo vector types, Stephen Leake, 2021/07/25
- Re: How to add pseudo vector types, Perry E. Metzger, 2021/07/26