From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: john muhl via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#66465: [PATCH] Improve imenu support in lua-ts-mode Date: Wed, 11 Oct 2023 12:15:08 -0500 Message-ID: <87fs2hoyox.fsf@pub.pink> Reply-To: john muhl 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="27519"; mail-complaints-to="usenet@ciao.gmane.io" To: 66465@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 11 19:30:13 2023 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 1qqd2D-0006tM-Aq for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 11 Oct 2023 19:30:13 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqd1s-00074m-H7; Wed, 11 Oct 2023 13:29:52 -0400 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 1qqd1q-00074G-P5 for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2023 13:29:50 -0400 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 1qqd1h-0000PE-D7 for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2023 13:29:50 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qqd22-0001Gb-Pz for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2023 13:30:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: john muhl Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 11 Oct 2023 17:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 66465 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.16970453884800 (code B ref -1); Wed, 11 Oct 2023 17:30:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Oct 2023 17:29:48 +0000 Original-Received: from localhost ([127.0.0.1]:39989 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qqd1n-0001FM-RB for submit@debbugs.gnu.org; Wed, 11 Oct 2023 13:29:48 -0400 Original-Received: from lists.gnu.org ([2001:470:142::17]:58622) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qqd1i-0001F3-Fm for submit@debbugs.gnu.org; Wed, 11 Oct 2023 13:29:46 -0400 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 1qqd1E-0006zu-PJ for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2023 13:29:13 -0400 Original-Received: from out-209.mta1.migadu.com ([95.215.58.209]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqd1C-0000Km-7G for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2023 13:29:12 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1697045346; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=CRiq2PiPApRdGdFNtX3wBxoUWDYLsY4aZ2fao/MsMH8=; b=S3PAh2QtQ9MTivncAe49ZpjS5VhStQVZZBuv+jMkCdjzVdNOrdeaxeaEmDZCqhvcTOUob+ yNBNcyCNvXFZKQWTpL8SuVsH8THob3JqxxxygMZPApTro7/z3JNqWFmmVJ0Jpi6ssxMvXZ Zf8ccZ01YNaMy3mHkAGAyDf5wWepVm0= X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=95.215.58.209; envelope-from=jm@pub.pink; helo=out-209.mta1.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:272260 Archived-At: --=-=-= Content-Type: text/plain Tags: patch This moves functions to the top level, adds a category for requires and gets rid of the "Anonymous" entries. --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Improve-imenu-support-in-lua-ts-mode.patch >From 4c67794a13b2f980b9436326512f0c9925195e28 Mon Sep 17 00:00:00 2001 From: john muhl Date: Tue, 10 Oct 2023 14:39:30 -0500 Subject: [PATCH] Improve imenu support in lua-ts-mode * lisp/progmodes/lua-ts-mode.el (lua-ts-mode): Include require statements and remove anonymous entries. (lua-ts--named-function-p): (lua-ts--require-name-function): (lua-ts--require-p): New functions. * lisp/speedbar.el (speedbar-supported-extension-expressions): Add Lua to the list of supported file types. --- lisp/progmodes/lua-ts-mode.el | 43 +++++++++++++++++++++++++++++------ lisp/speedbar.el | 2 +- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index 030a3585158..224199dff74 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el @@ -292,6 +292,33 @@ lua-ts--defun-name-function (and (treesit-search-subtree node "function_definition" nil nil 1) (treesit-node-text child t)))))) +(defun lua-ts--named-function-p (node) + "Matches if NODE is a named function." + (let ((type (treesit-node-type node))) + (or (equal "function_declaration" type) + (and (equal "field" type) + (equal "function_definition" + (treesit-node-type + (treesit-node-child-by-field-name + node "value"))) + (treesit-node-child-by-field-name node "name"))))) + +(defun lua-ts--require-name-function (node) + "Return name of NODE to use for requires in imenu." + (when-let* (((lua-ts--require-p node)) + (parent (treesit-node-parent node)) + (parent-type (treesit-node-type parent))) + (if (equal "expression_list" parent-type) + (let* ((g-parent (treesit-node-parent parent)) + (name (treesit-node-child-by-field-name g-parent "name"))) + (treesit-node-text name t)) + (treesit-node-text (treesit-search-subtree node "string_content") t)))) + +(defun lua-ts--require-p (node) + "Matches if NODE is a require statement." + (let ((name (treesit-node-child-by-field-name node "name"))) + (equal "require" (treesit-node-text name t)))) + (defvar-local lua-ts--flymake-process nil) (defun lua-ts-flymake-luacheck (report-fn &rest _args) @@ -422,13 +449,15 @@ lua-ts-mode ;; Imenu. (setq-local treesit-simple-imenu-settings - `(("Variable" ,(rx bos "variable_declaration" eos) nil nil) - ("Function" ,(rx bos - (or "function_declaration" - "function_definition" - "field") - eos) - nil nil))) + `(("Requires" + "\\`function_call\\'" + lua-ts--require-p + lua-ts--require-name-function) + ("Variables" "\\`variable_declaration\\'" nil nil) + (nil + "\\`\\(?:f\\(?:ield\\|unction_declaration\\)\\)\\'" + lua-ts--named-function-p + nil))) ;; Which-function. (setq-local which-func-functions (treesit-defun-at-point)) diff --git a/lisp/speedbar.el b/lisp/speedbar.el index 67d4e8c4df1..51c5962cb66 100644 --- a/lisp/speedbar.el +++ b/lisp/speedbar.el @@ -631,7 +631,7 @@ speedbar-supported-extension-expressions (append '(".[ch]\\(\\+\\+\\|pp\\|c\\|h\\|xx\\)?" ".tex\\(i\\(nfo\\)?\\)?" ".el" ".emacs" ".l" ".lsp" ".p" ".java" ".js" ".f\\(90\\|77\\|or\\)?") (if speedbar-use-imenu-flag - '(".ad[abs]" ".p[lm]" ".tcl" ".m" ".scm" ".pm" ".py" ".g" + '(".ad[abs]" ".p[lm]" ".tcl" ".m" ".scm" ".pm" ".py" ".g" ".lua" ;; html is not supported by default, but an imenu tags package ;; is available. Also, html files are nice to be able to see. ".s?html" -- 2.41.0 --=-=-=--