GNU bug report logs - #62204
30.0.50; Feature Request: treesit-major-mode-hook

Previous Next

Package: emacs;

Reported by: Aleksandar Dimitrov <code <at> aleks.bg>

Date: Wed, 15 Mar 2023 13:11:02 UTC

Severity: wishlist

Found in version 30.0.50

Full log


View this message in rfc822 format

From: Aleksandar Dimitrov <code <at> aleks.bg>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 62204 <at> debbugs.gnu.org
Subject: bug#62204: 30.0.50; Feature Request: treesit-major-mode-hook
Date: Thu, 16 Mar 2023 01:35:17 +0100
>> Currently, I've found two ways to accomplish loading my functionality for all ts-modes:
>> 
>> - enumerate them all and use their respective hooks
>> - advise something like `treesit-major-mode-setup` to execute my code
>
> Isn't it enough to check that the buffer has a treesit parser?

I'm not sure I understand you, so I'll try to provide some code.

I'd like to be able to do something like this:

(defun my-setup ()
  "Code that depends on the presence of TS")
(add-hook 'treesit-major-mode-hook 'my-setup)

If I understand you correctly,  I could probably do something like this:

(defmacro add-ts-mode-hook (f)
  "Add mode hook that only executes in ts modes"
  `(add-hook 'prog-mode-hook
            (lambda ()
              (when (treesit-language-at (point))
                (,f)))))

I'd say there's bound to be more people who would like to configure a
certain behaviour whenever treesit is available, regardless of major
mode. A macro like the above could be a possible solution, but it
doesn't feel terribly ergonomic.

> A hooks sounds too blunt and ad-hoc for your purposes, AFAIU.

The reason I want to execute my function in a hook is that it sets
buffer local variables, and configures buffer-local behaviour, perhaps
even keybindings. I was under the impression that hooks are the correct
place to do this.






This bug report was last modified 2 years and 152 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.