emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to add pseudo vector types


From: Eli Zaretskii
Subject: Re: How to add pseudo vector types
Date: Sat, 24 Jul 2021 18:48:41 +0300

> From: Yuan Fu <casouri@gmail.com>
> Date: Sat, 24 Jul 2021 11:04:35 -0400
> Cc: Stefan Monnier <monnier@iro.umontreal.ca>,
>  Clément Pit-Claudel <cpitclaudel@gmail.com>,
>  emacs-devel@gnu.org
> 
> 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.

Thanks!

> 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.

xsignal2 should work, as should xsignal.  Please show the code which
crashed.

> 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?

tree-sitter itself should be a library we link against.  If you meant
the tree-sitter support code, then it should go on a separate file in
src/.  Or did I misunderstand your question?

> What’s the different between make_string and make_pure_c_string? I’ve seen 
> this “pure” thing else where, what does “pure” mean?

I suggest to read the node "Pure Storage" in the ELisp manual.  It
explains that.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]