From 73e28c92567764be9fee6bf66b05c3e172206708 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Wed, 12 Feb 2025 20:31:22 +0200 Subject: [PATCH] Fix treesit-outline related settings * 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 | 99 +++++++++++++++++----------------- lisp/treesit.el | 5 +- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el index 15394f28b27..551271275d7 100644 --- a/lisp/progmodes/ruby-ts-mode.el +++ b/lisp/progmodes/ruby-ts-mode.el @@ -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) diff --git a/lisp/treesit.el b/lisp/treesit.el index 917a19c7a3f..2c9ec62dc34 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -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))) -- 2.39.5