* bug#69186: [PATCH] Recognize functions and macros as defuns in cmake-ts-mode
@ 2024-02-17 20:26 Jörg Bornemann
2024-02-20 16:07 ` Randy Taylor
2024-02-21 3:34 ` Randy Taylor
0 siblings, 2 replies; 6+ messages in thread
From: Jörg Bornemann @ 2024-02-17 20:26 UTC (permalink / raw)
To: 69186
[-- 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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* bug#69186: [PATCH] Recognize functions and macros as defuns in cmake-ts-mode
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
1 sibling, 0 replies; 6+ messages in thread
From: Randy Taylor @ 2024-02-20 16:07 UTC (permalink / raw)
To: Jörg Bornemann; +Cc: 69186
On Saturday, February 17th, 2024 at 15:26, Jörg Bornemann <foss@jbornemann.de> wrote:
>
>
> 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.
Thanks, I'll try to take a look later tonight.
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#69186: [PATCH] Recognize functions and macros as defuns in cmake-ts-mode
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
1 sibling, 1 reply; 6+ messages in thread
From: Randy Taylor @ 2024-02-21 3:34 UTC (permalink / raw)
To: Jörg Bornemann; +Cc: 69186
On Saturday, February 17th, 2024 at 15:26, Jörg Bornemann <foss@jbornemann.de> wrote:
>
>
> 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.
Thanks for working on this, it looks good to me.
I have a few small nits:
+(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."
I would drop the last sentence.
In the commit message:
(cmake-ts-mode): Set up treesit-defun-type-regexp and
treesit-defun-name-function. Change the imenu setup to recognize macros
One more space needed before "Change".
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#69186: [PATCH] Recognize functions and macros as defuns in cmake-ts-mode
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
0 siblings, 2 replies; 6+ messages in thread
From: Jörg Bornemann @ 2024-02-21 20:05 UTC (permalink / raw)
To: Randy Taylor; +Cc: 69186
[-- 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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* bug#69186: [PATCH] Recognize functions and macros as defuns in cmake-ts-mode
2024-02-21 20:05 ` Jörg Bornemann
@ 2024-02-21 20:53 ` Randy Taylor
2024-02-22 13:03 ` Eli Zaretskii
1 sibling, 0 replies; 6+ messages in thread
From: Randy Taylor @ 2024-02-21 20:53 UTC (permalink / raw)
To: Jörg Bornemann; +Cc: 69186
On Wednesday, February 21st, 2024 at 15:05, Jörg Bornemann <foss@jbornemann.de> wrote:
>
>
> 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
Great, thanks!
Can someone install this on master? Thanks in advance.
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#69186: [PATCH] Recognize functions and macros as defuns in cmake-ts-mode
2024-02-21 20:05 ` Jörg Bornemann
2024-02-21 20:53 ` Randy Taylor
@ 2024-02-22 13:03 ` Eli Zaretskii
1 sibling, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2024-02-22 13:03 UTC (permalink / raw)
To: Jörg Bornemann; +Cc: dev, 69186-done
> Cc: 69186@debbugs.gnu.org
> Date: Wed, 21 Feb 2024 21:05:59 +0100
> From: Jörg Bornemann <foss@jbornemann.de>
>
> 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.
Thanks, installed on master, and closing the bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-02-22 13:03 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2024-02-21 20:53 ` Randy Taylor
2024-02-22 13:03 ` Eli Zaretskii
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.