Subject: Re: bug#19080: 24.4; wish: enable show-paren-mode to highlight matching same-level keywords

From: Eli Zaretskii <[email-masked]>
Date: Fri, 13 May 2022 08:52:50 +0300

> From: Yuan Fu <[email-masked]>
> Date: Thu, 12 May 2022 15:52:14 -0700
> Cc: Lars Ingebrigtsen <[email-masked]>,
>  [email-masked],
>  [email-masked]
> 
> > We could perhaps add a new feature, based on tree-sitter, to highlight
> > a block of code, where the block is defined by PL rules, not by
> > parens, braces, and similar simple syntactic elements.
> > 
> > Yuan, WDYT?  Can this be added to the tree-sitter branch perhaps?
> 
> That sounds interesting, and it should be easy. But what do we want the API be? First of all, should we make a separate mode or extend show-paren-mode? Extending show-paren-mode entails doing some non-trivial refactoring to paren.el.

IMO, it should be a separate minor mode; show-paren-mode is not
necessarily about program blocks, since parentheses appear not only
(and mostly not) as block delimiters.

The API should be probably: given a buffer POSITION, return the 2
positions of the innermost enclosing block, or nil if POSITION is not
in any block.  A possible extension could be to return a list of
position pairs that provide also the blocks enclosed inside the
POSITION's block.

> I think, that adding tree-sitter “backend” needs refactoring existing code non-trivially.

If show-paren-mode would want to use tree-sitter, it will need
refactoring, yes.  Which other packages you envision could benefit
from using tree-sitter?