From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#70167: [PATCH] Mark Flymake regions more accurately in lua-ts-mode Date: Thu, 04 Apr 2024 06:05:03 +0000 Message-ID: <87jzldek8g.fsf@posteo.net> References: <87sf02baay.fsf@pub.pink> <878r1ub9q1.fsf@pub.pink> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25987"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 70167@debbugs.gnu.org To: john muhl Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Apr 04 08:06:15 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 1rsGEo-0006WP-U2 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 04 Apr 2024 08:06:15 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rsGEZ-0004jM-In; Thu, 04 Apr 2024 02:05:59 -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 1rsGEX-0004j8-Uc for bug-gnu-emacs@gnu.org; Thu, 04 Apr 2024 02:05:58 -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 1rsGEX-00088n-Mb for bug-gnu-emacs@gnu.org; Thu, 04 Apr 2024 02:05:57 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rsGEc-0000nb-Dh for bug-gnu-emacs@gnu.org; Thu, 04 Apr 2024 02:06:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 04 Apr 2024 06:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70167 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 70167-submit@debbugs.gnu.org id=B70167.17122107473039 (code B ref 70167); Thu, 04 Apr 2024 06:06:02 +0000 Original-Received: (at 70167) by debbugs.gnu.org; 4 Apr 2024 06:05:47 +0000 Original-Received: from localhost ([127.0.0.1]:60249 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rsGEM-0000mu-G1 for submit@debbugs.gnu.org; Thu, 04 Apr 2024 02:05:47 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:37005) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rsGEJ-0000lw-AI for 70167@debbugs.gnu.org; Thu, 04 Apr 2024 02:05:45 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 7DEE5240101 for <70167@debbugs.gnu.org>; Thu, 4 Apr 2024 08:05:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1712210732; bh=lbOCT8V7gmwhkIxCkictZFkATA9rK2cxP3diCHnUbYE=; h=From:To:Cc:Subject:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=JQrk3fQvnR6WS+kqgGdwnMIAKqsgQ8sNiqCnQI69bVc465QB5tn5p9q5m+ETSlyql DNoWNzHeknaH/e6db/czRWhP+udtOdlrJYl8TWeBWFCs7iguWqHo5GZhavg71Z2ey4 xbcTuy6cnZCeNMO1hkyK/ofItwee+NorF/FQfD2xHnA3t0eaRM6Rk3gvVjccu+YnTK z2SivGYM/nYMHTsHcFB2OH+cm1TbmBnXa02O8nOrHcubQapdDJjPOVksdNbaU/MNNx GrlMacX3/lFZMCd0yFRKwDe4KzFv/Jh944eKkP/UdvAkKV3lVZ0YobpRh7ww4Sr4nu RAw5g5j1LRvKQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4V9B1F0ryDz6tyS; Thu, 4 Apr 2024 08:05:20 +0200 (CEST) In-Reply-To: <878r1ub9q1.fsf@pub.pink> (john muhl's message of "Wed, 03 Apr 2024 12:59:24 -0500") OpenPGP: id=7126E1DE2F0CE35C770BED01F2C3CC513DB89F66; url="https://keys.openpgp.org/vks/v1/by-fingerprint/7126E1DE2F0CE35C770BED01F2C3CC513DB89F66"; preference=signencrypt 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:282620 Archived-At: john muhl writes: >>>From a0c1f9c84a7072a807141f7b304a3c98c8e92173 Mon Sep 17 00:00:00 2001 > From: john muhl > Date: Wed, 13 Mar 2024 08:35:08 -0500 > Subject: [PATCH] Mark Flymake regions more accurately in lua-ts-mode > > * lisp/progmodes/lua-ts-mode.el (lua-ts-flymake-luacheck): Use > the end position provided by Luacheck rather than relying on > 'thing-at-point' to guess where the end should be. (bug#70167) > --- > lisp/progmodes/lua-ts-mode.el | 55 ++++++++++++++++++----------------- > 1 file changed, 28 insertions(+), 27 deletions(-) > > diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el > index 407ef230c32..a39cfa9e814 100644 > --- a/lisp/progmodes/lua-ts-mode.el > +++ b/lisp/progmodes/lua-ts-mode.el > @@ -35,7 +35,6 @@ > (require 'treesit) > > (eval-when-compile > - (require 'cl-lib) > (require 'rx)) > > (declare-function treesit-induce-sparse-tree "treesit.c") > @@ -544,32 +543,34 @@ lua-ts-flymake-luacheck > (eq proc lua-ts--flymake-process)) > (with-current-buffer (process-buffer proc) > (goto-char (point-min)) > - (cl-loop > - while (search-forward-regexp > - (rx (seq bol > - (0+ alnum) ":" > - (group (1+ digit)) ":" > - (group (1+ digit)) "-" > - (group (1+ digit)) ": " > - (group (0+ nonl)) > - eol)) > - nil t) > - for (beg . end) = (flymake-diag-region > - source > - (string-to-number (match-string 1)) > - (string-to-number (match-string 2))) > - for msg = (match-string 4) > - for type = (if (string-match "^(W" msg) > - :warning > - :error) > - when (and beg end) > - collect (flymake-make-diagnostic source > - beg > - end > - type > - msg) > - into diags > - finally (funcall report-fn diags))) > + (let (beg end msg type diags) > + (while Why do you declare these variables outside of the loop? Should the values persist between iterations? If not, you could avoid the setq soup below, by declaring and binding the variables at once. > + (search-forward-regexp > + (rx (: bol (0+ alnum) ":" ^ this is not necessary, since the rx body has an implicit ":". > + (group (1+ digit)) ":" > + (group (1+ digit)) "-" > + (group (1+ digit)) ": " > + (group (0+ nonl)) eol)) > + nil t) > + (setq beg > + (car (flymake-diag-region > + source > + (string-to-number (match-string 1)) > + (string-to-number (match-string 2))))) > + (setq end > + (cdr (flymake-diag-region > + source > + (string-to-number (match-string 1)) > + (string-to-number (match-string 3))))) > + (setq msg (match-string 4)) > + (setq type (if (string-match "^(W" msg) :warning ^ You can avoid a regular expression here using `string-prefix-p'. > + :error)) > + (when (and beg end) > + (setq diags > + (nconc diags > + (list (flymake-make-diagnostic > + source beg end type msg)))))) > + (funcall report-fn diags))) If I see this correctly, then you are appending each element to the end of the list? If so, it would be more efficient to just construct the list in reverse using `push' and then `nreverse'ing it before passing it to REPORT-FN. > (flymake-log :warning "Canceling obsolete check %s" proc)) > (kill-buffer (process-buffer proc))))))) > (process-send-region lua-ts--flymake-process (point-min) (point-max)) -- Philip Kaludercic on peregrine