]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix treesit-outline related settings
authorJuri Linkov <juri@linkov.net>
Wed, 12 Feb 2025 18:31:22 +0000 (20:31 +0200)
committerEshel Yaron <me@eshelyaron.com>
Thu, 13 Feb 2025 11:51:37 +0000 (12:51 +0100)
* lisp/treesit.el (treesit-outline-level): Use level 1 by default
since treesit-outline--at-point now always returns the current node.

* lisp/progmodes/ruby-ts-mode.el (ruby-ts-mode):
Use 'bos' instead of 'bol'.  Add "singleton_class" to
'treesit-outline-predicate'.  Use new condition 'named' in
'treesit-outline-predicate' (bug#74963).

(cherry picked from commit 44c11cd4241ffc8636135bc41ac718101666d34d)

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

index 15394f28b279e109c3c60a1abf02350b285bc9bb..551271275d7d46cbdc61e110013188444f564d56 100644 (file)
@@ -1168,7 +1168,7 @@ leading double colon is not added."
   (setq-local treesit-thing-settings
               `((ruby
                  (sexp ,(cons (rx
-                               bol
+                               bos
                                (or
                                 "class"
                                 "singleton_class"
@@ -1211,49 +1211,48 @@ leading double colon is not added."
                                 "instance_variable"
                                 "global_variable"
                                 )
-                               eol)
+                               eos)
                               #'ruby-ts--sexp-p))
-                 (list
-                  ,(cons (rx
-                          bol
-                          (or
-                           "begin_block"
-                           "end_block"
-                           "method"
-                           "singleton_method"
-                           "method_parameters"
-                           "parameters"
-                           "block_parameters"
-                           "class"
-                           "singleton_class"
-                           "module"
-                           "do"
-                           "case"
-                           "case_match"
-                           "array_pattern"
-                           "find_pattern"
-                           "hash_pattern"
-                           "parenthesized_pattern"
-                           "expression_reference_pattern"
-                           "if"
-                           "unless"
-                           "begin"
-                           "parenthesized_statements"
-                           "argument_list"
-                           "do_block"
-                           "block"
-                           "destructured_left_assignment"
-                           "interpolation"
-                           "string"
-                           "string_array"
-                           "symbol_array"
-                           "delimited_symbol"
-                           "regex"
-                           "heredoc_body"
-                           "array"
-                           "hash")
-                          eol)
-                         #'ruby-ts--list-p))
+                 (list ,(cons (rx
+                               bos
+                               (or
+                                "begin_block"
+                                "end_block"
+                                "method"
+                                "singleton_method"
+                                "method_parameters"
+                                "parameters"
+                                "block_parameters"
+                                "class"
+                                "singleton_class"
+                                "module"
+                                "do"
+                                "case"
+                                "case_match"
+                                "array_pattern"
+                                "find_pattern"
+                                "hash_pattern"
+                                "parenthesized_pattern"
+                                "expression_reference_pattern"
+                                "if"
+                                "unless"
+                                "begin"
+                                "parenthesized_statements"
+                                "argument_list"
+                                "do_block"
+                                "block"
+                                "destructured_left_assignment"
+                                "interpolation"
+                                "string"
+                                "string_array"
+                                "symbol_array"
+                                "delimited_symbol"
+                                "regex"
+                                "heredoc_body"
+                                "array"
+                                "hash")
+                               eos)
+                              #'ruby-ts--list-p))
                  (text ,(lambda (node)
                           (or (member (treesit-node-type node)
                                       '("comment" "string_content" "heredoc_content"))
@@ -1275,12 +1274,14 @@ leading double colon is not added."
 
   ;; Outline minor mode.
   (setq-local treesit-outline-predicate
-              (rx bos (or "singleton_method"
-                          "method"
-                          "alias"
-                          "class"
-                          "module")
-                  eos))
+              `(and ,(rx bos (or "singleton_method"
+                                 "method"
+                                 "alias"
+                                 "singleton_class"
+                                 "class"
+                                 "module")
+                         eos)
+                    named))
   ;; Restore default values of outline variables
   ;; to use `treesit-outline-predicate'.
   (kill-local-variable 'outline-regexp)
index 917a19c7a3f1802440fff67a5b4b86a5d38a4016..2c9ec62dc3462bf969ec577d15879b1903675bc8 100644 (file)
@@ -3494,7 +3494,7 @@ when a major mode sets it.")
    treesit-simple-imenu-settings))
 
 (defun treesit-outline--at-point ()
-  "Return the outline heading at the current line."
+  "Return the outline heading node at the current line."
   (let* ((pred treesit-outline-predicate)
          (bol (pos-bol))
          (eol (pos-eol))
@@ -3544,8 +3544,7 @@ For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in
 (defun treesit-outline-level ()
   "Return the depth of the current outline heading."
   (let* ((node (treesit-outline--at-point))
-         (level (if (treesit-node-match-p node treesit-outline-predicate)
-                    1 0)))
+         (level 1))
     (while (setq node (treesit-parent-until node treesit-outline-predicate))
       (setq level (1+ level)))
     (if (zerop level) 1 level)))