From: "Jörg Bornemann" <foss@jbornemann.de>
To: 69186@debbugs.gnu.org
Subject: bug#69186: [PATCH] Recognize functions and macros as defuns in cmake-ts-mode
Date: Sat, 17 Feb 2024 21:26:58 +0100 [thread overview]
Message-ID: <8734tq4z1p.fsf@jbornemann.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 834 bytes --]
Tags: patch
This might exceed the lines of code for the Copyright-paperwork-exempt
marker. From my side, FSF paperwork is done and my "assignment awaits a
countersignature from the deputy directory" since a while. In the
meantime, let's have this change reviewed.
In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.38, cairo version 1.16.0) of 2024-02-16 built on barf
Repository revision: 4b89fb08bdd7d0249698bc0ed578555d6755724d
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12201009
System Description: Debian GNU/Linux 12 (bookworm)
Configured using:
'configure --with-x --with-x-toolkit=gtk3 --with-native-compilation
--with-imagemagick --with-json --with-sound=alsa --with-mailutils
--with-file-notification=yes --prefix /home/jobor/dev/emacs-master'
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Recognize-functions-and-macros-as-defuns-in-cmake-ts.patch --]
[-- Type: text/patch, Size: 2654 bytes --]
From 474c7872ca1950761ed4b377e5e8477bb775965e 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 | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/lisp/progmodes/cmake-ts-mode.el b/lisp/progmodes/cmake-ts-mode.el
index 29c9e957d3c..850133ac935 100644
--- a/lisp/progmodes/cmake-ts-mode.el
+++ b/lisp/progmodes/cmake-ts-mode.el
@@ -193,13 +193,14 @@ 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. We
+consider CMake functions and macros as defuns."
(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 +217,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
next reply other threads:[~2024-02-17 20:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-17 20:26 Jörg Bornemann [this message]
2024-02-20 16:07 ` bug#69186: [PATCH] Recognize functions and macros as defuns in cmake-ts-mode Randy Taylor
2024-02-21 3:34 ` Randy Taylor
2024-02-21 20:05 ` Jörg Bornemann
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=8734tq4z1p.fsf@jbornemann.de \
--to=foss@jbornemann.de \
--cc=69186@debbugs.gnu.org \
/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).