[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 eb26872837 8/9: Fix imenu for c-ts-mode (bug#60296)
From: |
Yuan Fu |
Subject: |
emacs-29 eb26872837 8/9: Fix imenu for c-ts-mode (bug#60296) |
Date: |
Mon, 26 Dec 2022 04:48:08 -0500 (EST) |
branch: emacs-29
commit eb268728376db081b61f47c635b7316938e63d5d
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Fix imenu for c-ts-mode (bug#60296)
* lisp/progmodes/c-ts-mode.el (c-ts-mode--imenu-1): Use
c-ts-mode--defun-valid-p to filter out nested matches.
(c-ts-mode--defun-valid-p): Handle more types of nodes.
---
lisp/progmodes/c-ts-mode.el | 51 ++++++++++++++++++++++++---------------------
1 file changed, 27 insertions(+), 24 deletions(-)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 1bd5036be2..2847d65daf 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -510,21 +510,10 @@ the subtrees."
(set-marker (make-marker)
(treesit-node-start ts-node)))))
(cond
- ;; A struct_specifier could be inside a parameter list, another
- ;; struct definition, a variable declaration, a function
- ;; declaration. In those cases we don't include it.
- ((string-match-p
- (rx (or "parameter_declaration" "field_declaration"
- "declaration" "function_definition"))
- (or (treesit-node-type (treesit-node-parent ts-node))
- ""))
+ ((or (null ts-node) (null name))
+ subtrees)
+ ((null (c-ts-mode--defun-valid-p ts-node))
nil)
- ;; Ignore function local variable declarations.
- ((and (equal (treesit-node-type ts-node) "declaration")
- (not (equal (treesit-node-type (treesit-node-parent ts-node))
- "translation_unit")))
- nil)
- ((or (null ts-node) (null name)) subtrees)
(subtrees
`((,name ,(cons name marker) ,@subtrees)))
(t
@@ -550,16 +539,30 @@ the subtrees."
;;; Defun navigation
(defun c-ts-mode--defun-valid-p (node)
- (if (string-match-p
- (rx (or "struct_specifier"
- "enum_specifier"
- "union_specifier"))
- (treesit-node-type node))
- (null
- (treesit-node-top-level
- node (rx (or "function_definition"
- "type_definition"))))
- t))
+ "Return non-nil if NODE is a valid defun node.
+Ie, NODE is not nested."
+ (not (or (and (member (treesit-node-type node)
+ '("struct_specifier"
+ "enum_specifier"
+ "union_specifier"
+ "declaration"))
+ ;; If NODE's type is one of the above, make sure it is
+ ;; top-level.
+ (treesit-node-top-level
+ node (rx (or "function_definition"
+ "type_definition"
+ "struct_specifier"
+ "enum_specifier"
+ "union_specifier"
+ "declaration"))))
+
+ (and (equal (treesit-node-type node) "declaration")
+ ;; If NODE is a declaration, make sure it is not a
+ ;; function declaration.
+ (equal (treesit-node-type
+ (treesit-node-child-by-field-name
+ node "declarator"))
+ "function_declarator")))))
(defun c-ts-mode--defun-skipper ()
"Custom defun skipper for `c-ts-mode' and friends.
- emacs-29 updated (2608e5edcc -> d90d7d15f2), Yuan Fu, 2022/12/26
- emacs-29 2bcd1e9a99 3/9: ; * doc/lispref/parsing.texi (Retrieving Nodes): Add notice., Yuan Fu, 2022/12/26
- emacs-29 7c7950fe00 2/9: Add maintainer stub for tree-sitter files, Yuan Fu, 2022/12/26
- emacs-29 c6b0282645 5/9: ; Remove unused function in c-ts-mode, Yuan Fu, 2022/12/26
- emacs-29 6e52a9fcad 4/9: ; * doc/lispref/modes.texi (Parser-based Font Lock): Minor fixes., Yuan Fu, 2022/12/26
- emacs-29 8f68b6497e 7/9: Clean up python-ts-mode font-lock features, Yuan Fu, 2022/12/26
- emacs-29 eb26872837 8/9: Fix imenu for c-ts-mode (bug#60296),
Yuan Fu <=
- emacs-29 d90d7d15f2 9/9: ; Fix vindexes in parsing.texi, Yuan Fu, 2022/12/26
- emacs-29 cf32776622 1/9: ; * doc/lispref/parsing.texi (Using Parser): Remove deleted function., Yuan Fu, 2022/12/26
- emacs-29 28f26b11a1 6/9: Add comment indent and filling to other tree-sitter major modes, Yuan Fu, 2022/12/26