From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?J=C3=B6rg?= Bornemann Newsgroups: gmane.emacs.bugs Subject: bug#69186: [PATCH] Recognize functions and macros as defuns in cmake-ts-mode Date: Sat, 17 Feb 2024 21:26:58 +0100 Message-ID: <8734tq4z1p.fsf@jbornemann.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39002"; mail-complaints-to="usenet@ciao.gmane.io" To: 69186@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 18 19:16:08 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rblhv-0009tM-5o for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Feb 2024 19:16:07 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rblhZ-0005tO-Fd; Sun, 18 Feb 2024 13:15:45 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rblhX-0005t7-Kd for bug-gnu-emacs@gnu.org; Sun, 18 Feb 2024 13:15:43 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rblhX-0001KX-Cf for bug-gnu-emacs@gnu.org; Sun, 18 Feb 2024 13:15:43 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rblhr-0002S3-IV for bug-gnu-emacs@gnu.org; Sun, 18 Feb 2024 13:16:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?J=C3=B6rg?= Bornemann Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 18 Feb 2024 18:16:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 69186 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.17082801539385 (code B ref -1); Sun, 18 Feb 2024 18:16:03 +0000 Original-Received: (at submit) by debbugs.gnu.org; 18 Feb 2024 18:15:53 +0000 Original-Received: from localhost ([127.0.0.1]:36899 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rblhe-0002RC-Ot for submit@debbugs.gnu.org; Sun, 18 Feb 2024 13:15:53 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:53956) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rblQT-0001mW-Jx for submit@debbugs.gnu.org; Sun, 18 Feb 2024 12:58:06 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rbRHm-0004RW-Mt for bug-gnu-emacs@gnu.org; Sat, 17 Feb 2024 15:27:46 -0500 Original-Received: from ms-10.1blu.de ([178.254.4.101]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rbRHk-0006PS-5n for bug-gnu-emacs@gnu.org; Sat, 17 Feb 2024 15:27:46 -0500 Original-Received: from [93.228.120.14] (helo=barf.jbornemann.de) by ms-10.1blu.de with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rbRHg-005gs9-2Y for bug-gnu-emacs@gnu.org; Sat, 17 Feb 2024 21:27:40 +0100 X-Con-Id: 36794 X-Con-U: 0-foss X-Originating-IP: 93.228.120.14 Received-SPF: pass client-ip=178.254.4.101; envelope-from=foss@jbornemann.de; helo=ms-10.1blu.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 18 Feb 2024 13:15:48 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:280171 Archived-At: --=-=-= Content-Type: text/plain 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' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Recognize-functions-and-macros-as-defuns-in-cmake-ts.patch >From 474c7872ca1950761ed4b377e5e8477bb775965e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Bornemann?= 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 --=-=-=--