unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Jörg Bornemann" <foss@jbornemann.de>
To: Randy Taylor <dev@rjt.dev>
Cc: 69186@debbugs.gnu.org
Subject: bug#69186: [PATCH] Recognize functions and macros as defuns in cmake-ts-mode
Date: Wed, 21 Feb 2024 21:05:59 +0100	[thread overview]
Message-ID: <6d1eabbc-36ee-4518-a0c4-eb6526590ed6@jbornemann.de> (raw)
In-Reply-To: <kSR9dx3jlfSK1fyS-98qB6SYtXwxRv55gPysIzNjhu2nn9w5TbQKlfVp_dC5cQLrvikGUz9itMcGoE-ElAmt8uhDZIab15QtCfggbWdsKb0=@rjt.dev>

[-- Attachment #1: Type: text/plain, Size: 261 bytes --]

On 2/21/24 04:34, Randy Taylor wrote:

> Thanks for working on this, it looks good to me.

Thanks for the review!

> I have a few small nits:
[...]

I've picked the nits and rebased the change.
And the paperwork is also done from all sides now.


Cheers,

Jörg

[-- Attachment #2: 0001-Recognize-functions-and-macros-as-defuns-in-cmake-ts.patch --]
[-- Type: text/x-patch, Size: 2602 bytes --]

From eb48288def06a30b7a12c1664897093e226cca21 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20Bornemann?= <foss@jbornemann.de>
Date: Sat, 17 Feb 2024 21:18:02 +0100
Subject: [PATCH] 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.

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 @@ cmake-ts-mode--font-lock-settings
    '((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 @@ cmake-ts-mode
     (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.
-- 
2.39.2


  reply	other threads:[~2024-02-21 20:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-17 20:26 bug#69186: [PATCH] Recognize functions and macros as defuns in cmake-ts-mode Jörg Bornemann
2024-02-20 16:07 ` Randy Taylor
2024-02-21  3:34 ` Randy Taylor
2024-02-21 20:05   ` Jörg Bornemann [this message]
2024-02-21 20:53     ` Randy Taylor
2024-02-22 13:03     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6d1eabbc-36ee-4518-a0c4-eb6526590ed6@jbornemann.de \
    --to=foss@jbornemann.de \
    --cc=69186@debbugs.gnu.org \
    --cc=dev@rjt.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).