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#65673: [PATCH emacs 1/1 v2] Add lua-ts-mode Date: Sat, 9 Sep 2023 10:17:20 -0500 Message-ID: <20230909151834.3613907-1-jm@pub.pink> References: <169352253839.28940.16024479871485106701-0@git.sr.ht> Reply-To: john muhl Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="423"; mail-complaints-to="usenet@ciao.gmane.io" Cc: philipk@posteo.net, arstoffel@gmail.com, maurooaranda@gmail.com, ~emacs/emacs-devel@lists.sr.ht To: 65673@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 09 17:19:14 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 1qezju-000AVg-Cs for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 09 Sep 2023 17:19:14 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qezji-0006sV-9o; Sat, 09 Sep 2023 11:19:02 -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 1qezjh-0006rm-56 for bug-gnu-emacs@gnu.org; Sat, 09 Sep 2023 11:19:01 -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 1qezjg-0004qj-Df for bug-gnu-emacs@gnu.org; Sat, 09 Sep 2023 11:19:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qezji-00058Z-DK for bug-gnu-emacs@gnu.org; Sat, 09 Sep 2023 11:19: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: Sat, 09 Sep 2023 15:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65673 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 65673-submit@debbugs.gnu.org id=B65673.169427274019731 (code B ref 65673); Sat, 09 Sep 2023 15:19:02 +0000 Original-Received: (at 65673) by debbugs.gnu.org; 9 Sep 2023 15:19:00 +0000 Original-Received: from localhost ([127.0.0.1]:48274 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qezjf-000586-V6 for submit@debbugs.gnu.org; Sat, 09 Sep 2023 11:19:00 -0400 Original-Received: from out-228.mta0.migadu.com ([91.218.175.228]:23281) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qezja-00057j-58 for 65673@debbugs.gnu.org; Sat, 09 Sep 2023 11:18:57 -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=1694272729; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1SmKOGKJEnUUT3DYyKZy8aE1W1Ttgpycrgz2QQbxNdw=; b=M6rUSCsYfbND1+9nD7QeyUK//TNFM0dmkmbzj9N2uk+JMR4ZJjr1T+Q6+A97AaSU0j0gWI s2XWhwNTwd2Nq4y63j+1i4cDEUg02k0SpHJQs/iSktOQMlcYivTaHvDp9rzBFUDdiw5RSo 39dmKMTAcuTxhVbh2YOkpRlL0GEXptY= In-Reply-To: <169352253839.28940.16024479871485106701-0@git.sr.ht> X-Migadu-Flow: FLOW_OUT 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: , X-ACL-Warn: , john muhl 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:269873 Archived-At: Mauro Aranda writes: > I just have some comments/questions about the defcustoms: Fixed. Philip Kaludercic writes: > ~johnmuhl writes: > >> +(defcustom lua-ts-lua-manual >> + (if (file-readable-p "/usr/share/doc/lua/manual.html") >> + "file:///usr/share/doc/lua/manual.html" "") >> + "Location of the Lua `manual.html' file." >> + :type 'string >> + :safe 'stringp >> + :group 'lua >> + :version "30.1") > > Could this fall back to some online manual? I went with Augusto’s suggestion and removed the documentation command. >> +(defcustom inferior-lua-interpreter "lua" >> + "Program to run in the inferior Lua process." >> + :type 'string >> + :safe 'stringp >> + :group 'lua >> + :version "30.1") > > Are you sure that any string is safe? That would include "rm -rf ~". Fixed here and for the startfile and command line options. >> +;;;###autoload >> +(define-derived-mode lua-ts-mode prog-mode "Lua" >> + "Major mode for editing Lua files, powered by tree-sitter." >> + :group 'lua > > The :group is redundant here, it will automatically use the last > defgroup defined in the file. Fixed. Augusto Stoffel writes: > On Thu, 31 Aug 2023 at 16:32, ~johnmuhl wrote: > >> +(defcustom inferior-lua-switches "-i" >> + "Command line options for the inferior Lua process." >> + :type 'string >> + :safe 'stringp >> + :group 'lua >> + :version "30.1") > > This should be given as a list of strings rather a string that you later > need to call split-string-shell-command on. Fixed. > Also, I think it's probably best to use the same lua-ts- prefix Changed to lua-ts-inferior-* >> +(defun lua-ts-documentation-at-point () >> + "Show documentation of function at point in Lua manual." >> + (interactive) >> + (unless (string-blank-p lua-ts-lua-manual) >> + (let ((character-before (char-to-string (char-before))) >> + id) >> + (save-excursion >> + ;; When point is mid-word `treesit-thing-at-point' >> + ;; may return the parent node of the thing at point. >> + (unless (or (bolp) >> + (not (string-match-p "[[:alnum:]]" character-before))) >> + (backward-word)) >> + (let ((node (treesit-thing-at-point 'builtin nil))) >> + (setq id (pcase (treesit-node-type node) >> + ("dot_index_expression" (treesit-node-text node t)) >> + ("function_call" >> + (let* ((child (treesit-node-child-by-field-name node "name")) >> + (name (treesit-node-text child t))) >> + (if (string-match-p ":" name) >> + (replace-regexp-in-string "^.*:" "file:" name) >> + name))))))) >> + (when id (browse-url (concat lua-ts-lua-manual "#pdf-" id)))))) > > I wouldn't add this command. It's not polished enough and too ad-hoc in > the sense that this functionality is (or should be) covered by other > mechanisms: Info, Eldoc, etc. Removed. >> + ;; Outline. >> + (setq-local outline-regexp >> + (rx (or "--[[" "do" "for" "if" "repeat" "while" >> + (seq (** 0 1 "local ") "function")))) > > What is the idea behind "--[["? I like the way o-m-m folds the header sections of elisp files and since my lua files often start with a multi-line comment containing similar information I added it to get that effect in lua too. > Should one allow whitespace in front of these strings (also inferring > the outline level from that)? Done. > Also, one should allow arbitrary whitespace after "local" (I'd say > "local\\s-+") and enclose the keywords with "\\_<...\\_>". Fixed.