]> git.eshelyaron.com Git - emacs.git/commitdiff
More changes for treesitter support of outline-minor-mode (bug#68824)
authorJuri Linkov <juri@linkov.net>
Tue, 13 Feb 2024 17:02:21 +0000 (19:02 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 14 Feb 2024 08:15:03 +0000 (09:15 +0100)
* lisp/treesit.el (treesit-outline-level): Set NAMED arg of
'treesit-node-at' to t.  Don't set IGNORE-MISSING arg of
'treesit-node-match-p' to t.

* lisp/progmodes/ruby-ts-mode.el (ruby-ts-mode):
Add "singleton_method" to 'treesit-thing-settings'.
Set 'treesit-outline-predicate'.  Kill local variables
'outline-regexp' and 'outline-level'.

(cherry picked from commit d61145cc8cfb31ca170cd1b5deab59f0a5cbea63)

lisp/progmodes/ruby-ts-mode.el
lisp/treesit.el

index c3e8c217a835346381b518c9ae8907bba07f4279..0c0f720dc9b79c9a746282b1d97d023938f95621 100644 (file)
@@ -1133,6 +1133,7 @@ leading double colon is not added."
                                 "singleton_class"
                                 "module"
                                 "method"
+                                "singleton_method"
                                 "array"
                                 "hash"
                                 "parenthesized_statements"
@@ -1178,6 +1179,19 @@ leading double colon is not added."
   ;; Imenu.
   (setq-local imenu-create-index-function #'ruby-ts--imenu)
 
+  ;; Outline minor mode.
+  (setq-local treesit-outline-predicate
+              (rx bos (or "singleton_method"
+                          "method"
+                          "alias"
+                          "class"
+                          "module")
+                  eos))
+  ;; Restore default values of outline variables
+  ;; to use `treesit-outline-predicate'.
+  (kill-local-variable 'outline-regexp)
+  (kill-local-variable 'outline-level)
+
   (setq-local treesit-simple-indent-rules (ruby-ts--indent-rules))
 
   ;; Font-lock.
index 25ac582276b28d16acfb2b5937f1da05d27ae0c9..f811b8090bc1cb9332889af20e0cf8fdd1038265 100644 (file)
@@ -2918,8 +2918,8 @@ See the descriptions of arguments in `outline-search-function'."
 
 (defun treesit-outline-level ()
   "Return the depth of the current outline heading."
-  (let* ((node (treesit-node-at (point)))
-         (level (if (treesit-node-match-p node treesit-outline-predicate t)
+  (let* ((node (treesit-node-at (point) nil t))
+         (level (if (treesit-node-match-p node treesit-outline-predicate)
                     1 0)))
     (while (setq node (treesit-parent-until node treesit-outline-predicate))
       (setq level (1+ level)))