From: Dmitry Gutov <dmitry@gutov.dev>
To: Juri Linkov <juri@linkov.net>, 75122@debbugs.gnu.org
Cc: Yuan Fu <casouri@gmail.com>
Subject: bug#75122: Treesit support for show-paren-mode
Date: Thu, 26 Dec 2024 22:07:12 +0200 [thread overview]
Message-ID: <6b729636-accf-4872-9b5e-627ec18bb255@gutov.dev> (raw)
In-Reply-To: <878qs2z477.fsf@mail.linkov.net>
Hi!
On 26/12/2024 20:31, Juri Linkov wrote:
> For example, ruby-mode used smie-setup that sets
> buffer-local show-paren-data-function.
>
> This patch does the same for ts-modes: when point at the start/end
> of the sexp list, then both "def" and "end" are highlighted
> as opening and closing nodes:
>
> def method
> puts "This is method definition"
> end-!-
This is working great, thanks!
Some comments below.
> treesit-show-paren-data.patch
>
> diff --git a/lisp/treesit.el b/lisp/treesit.el
> index 2616d16e800..a62f63d0d6c 100644
> --- a/lisp/treesit.el
> +++ b/lisp/treesit.el
> @@ -3331,6 +3333,34 @@ treesit-outline-level
> (setq level (1+ level)))
> (if (zerop level) 1 level)))
>
> +;;; Show paren mode
> +
> +(defun treesit-show-paren-data ()
> + "A function suitable for `show-paren-data-function' (which see)."
> + (let* ((node (treesit-thing-at (point) 'sexp-list))
> + (beg (when node (treesit-node-start node)))
> + (end (when node (treesit-node-end node))))
> + ;; When after the closing node, try the previous position inside the node
The comment doesn't seem to correspond to the code, or anyway to all the
cases the code might be handling? I might misunderstand, though.
> + (unless (or (eq (point) beg) (eq (point) end) (bobp))
> + (setq node (treesit-thing-at (1- (point)) 'sexp-list)
> + beg (when node (treesit-node-start node))
> + end (when node (treesit-node-end node))))
Without getting into more details, it seems the user options
show-paren-when-point-inside-paren and
show-paren-when-point-in-periphery are not handled (don't have any effect).
Not sure what's needed for that, but FWIW SMIE's show-paren integration
seems to react to the value of the first of these options (even though
it's never referenced directly in smie.el), while the second one is not
supported there either.
next prev parent reply other threads:[~2024-12-26 20:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-26 18:31 bug#75122: Treesit support for show-paren-mode Juri Linkov
2024-12-26 20:07 ` Dmitry Gutov [this message]
2024-12-27 7:37 ` Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6b729636-accf-4872-9b5e-627ec18bb255@gutov.dev \
--to=dmitry@gutov.dev \
--cc=75122@debbugs.gnu.org \
--cc=casouri@gmail.com \
--cc=juri@linkov.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.