emacs-devel
[Top][All Lists]
Advanced

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

Re: Average-user-facing interface for tree-sitter


From: Yuan Fu
Subject: Re: Average-user-facing interface for tree-sitter
Date: Fri, 14 Oct 2022 13:10:42 -0700


> On Oct 14, 2022, at 4:22 AM, Stephen Leake <stephen_leake@stephe-leake.org> 
> wrote:
> 
> Lars Ingebrigtsen <larsi@gnus.org> writes:
> 
>> Yuan Fu <casouri@gmail.com> writes:
>> 
>>> I wonder if we can have a major mode hook that runs before the body
>>> runs, like xxx-mode-before-hook. Then user can set
>>> feature-provider-alist in that hook. This way major modes can decide
>>> what backend (provider) to use for each features.
> 
> +1
> 
> I needed something similar in ada-mode; I implemented it by moving have
> of the major mode function into a post-local-vars hook; that runs
> after the major mode function.

I think the best way to allow users to alter major mode’s setup is to have such 
a hook run after clearing local variable but before major mode setup. Currently 
since major mode hook run after the setup, setting local variable in the hook 
doesn’t do anything. Example:

(defvar-local treesit-activate nil)

;; Enable for python-mode, TBH this looks a bit awkward.
(add-hook 'python-mode-before-hook
          (lambda () (setq treesit-activate t)))

(define-minor-mode global-treesit-mode ""
  :global t
  (if global-treesit-mode
      (setq-default treesit-activate t)
    (setq-default treesit-activate nil)))

;; Not sure about minor mode yet.

Yuan


reply via email to

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