emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 6b6761d5342: Recognize functions and macros as defuns in 'cmake-t


From: Eli Zaretskii
Subject: master 6b6761d5342: Recognize functions and macros as defuns in 'cmake-ts-mode'
Date: Thu, 22 Feb 2024 08:03:33 -0500 (EST)

branch: master
commit 6b6761d534259ab4d5409e72754e46af13623dda
Author: Jörg Bornemann <foss@jbornemann.de>
Commit: Eli Zaretskii <eliz@gnu.org>

    Recognize functions and macros as defuns in 'cmake-ts-mode'
    
    * lisp/progmodes/cmake-ts-mode.el (cmake-ts-mode--function-name):
    Renamed to 'cmake-ts-mode--defun-name' since the function handles
    now functions and macros.
    (cmake-ts-mode--defun-name): Return text of the first 'argument'
    node below 'function_def' and 'macro_def' nodes.
    (cmake-ts-mode): Set up treesit-defun-type-regexp and
    'treesit-defun-name-function'.  Change the imenu setup to
    recognize macros too.  Since we have set up
    'treesit-defun-name-function', we don't have to
    pass 'cmake-ts-mode--function-name' anymore.  (Bug#69186)
    
    To make `treesit-defun-at-point' work properly, we have to recognize
    function_def/macro_def nodes, not the lower-level *_command nodes.
---
 lisp/progmodes/cmake-ts-mode.el | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/cmake-ts-mode.el b/lisp/progmodes/cmake-ts-mode.el
index 29c9e957d3c..45c4882d873 100644
--- a/lisp/progmodes/cmake-ts-mode.el
+++ b/lisp/progmodes/cmake-ts-mode.el
@@ -193,13 +193,13 @@ Check if a node type is available, then return the right 
font lock rules."
    '((ERROR) @font-lock-warning-face))
   "Tree-sitter font-lock settings for `cmake-ts-mode'.")
 
-(defun cmake-ts-mode--function-name (node)
-  "Return the function name of NODE.
-Return nil if there is no name or if NODE is not a function node."
+(defun cmake-ts-mode--defun-name (node)
+  "Return the defun name of NODE.
+Return nil if there is no name or if NODE is not a defun node."
   (pcase (treesit-node-type node)
-    ("function_command"
+    ((or "function_def" "macro_def")
      (treesit-node-text
-      (treesit-search-subtree node "^argument$" nil nil 2)
+      (treesit-search-subtree node "^argument$" nil nil 3)
       t))))
 
 ;;;###autoload
@@ -216,9 +216,15 @@ Return nil if there is no name or if NODE is not a 
function node."
     (setq-local comment-end "")
     (setq-local comment-start-skip (rx "#" (* (syntax whitespace))))
 
+    ;; Defuns.
+    (setq-local treesit-defun-type-regexp (rx (or "function" "macro")
+                                              "_def"))
+    (setq-local treesit-defun-name-function #'cmake-ts-mode--defun-name)
+
     ;; Imenu.
     (setq-local treesit-simple-imenu-settings
-                `(("Function" "\\`function_command\\'" nil 
cmake-ts-mode--function-name)))
+                `(("Function" "^function_def$")
+                  ("Macro" "^macro_def$")))
     (setq-local which-func-functions nil)
 
     ;; Indent.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]