Subject: bug#74412: 31.0.50; Treesit-outline conflict with outli in Emacs 31

From: Juri Linkov <[email-masked]>
Date: Thu, 21 Nov 2024 19:58:16 +0200

> The above is my use of outline-minor-mode, maybe other people have
> different use cases. treesit.el makes the configuration harder by the
> additional variable setting. I wish there's a hook like
> treesit-after-major-mode-setup-hook to let people fine-tune or even undo
> settings, but of course treesit-disable-features to prevent any
> execution from the start is still better.

If a ts-mode doesn't allow using a hook to override
mode's default settings, this would be a serious limitation.
But does such a limitation really exist?
It seems there is no need to add treesit-after-major-mode-setup-hook,
since I see no problem with using the existing hooks.
For example, such customization correctly overrides outline settings
for both non-ts and ts-modes:

  ;; non-ts
  (add-hook 'ruby-base-mode-hook
            (lambda ()
              ;; Add more Rails spec keywords
              (setq-local outline-regexp
                          (concat "^\\s *"
                                  (regexp-opt '("module" "class" "def" "private"
                                                "describe" "feature" "context" "before" "after"
                                                "it" "fit" "xit"))
                                  "\\_>"))))
  ;; same for ts-mode
  (add-hook 'ruby-ts-mode-hook
            (lambda ()
              ;; Add more Rails spec keywords
              (setq-local
               treesit-outline-predicate
               (lambda (node)
                 (or (string-match-p
                      (rx bos (or "module"
                                  "class"
                                  "singleton_class"
                                  "method"
                                  "singleton_method"
                                  "alias")
                          eos)
                      (treesit-node-type node))
                     (and (equal (treesit-node-type node) "call")
                          (if-let ((method (treesit-node-child-by-field-name
                                            node "method")))
                              (string-match-p
                               (rx bos (or "describe"
                                           "feature"
                                           "context"
                                           "before"
                                           "after"
                                           "it"
                                           "fit"
                                           "test")
                                   eos)
                               (treesit-node-text method)))))))))