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:49 +0000 Message-ID: <87il0xek76.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="32179"; 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:07:21 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 1rsGFs-00089i-D6 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 04 Apr 2024 08:07:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rsGFX-0004tj-QN; Thu, 04 Apr 2024 02:06: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 1rsGFV-0004tP-E1 for bug-gnu-emacs@gnu.org; Thu, 04 Apr 2024 02:06:57 -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 1rsGFV-0008S8-5A for bug-gnu-emacs@gnu.org; Thu, 04 Apr 2024 02:06:57 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rsGFZ-0000pL-TA for bug-gnu-emacs@gnu.org; Thu, 04 Apr 2024 02:07:01 -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:07:01 +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.17122107673106 (code B ref 70167); Thu, 04 Apr 2024 06:07:01 +0000 Original-Received: (at 70167) by debbugs.gnu.org; 4 Apr 2024 06:06:07 +0000 Original-Received: from localhost ([127.0.0.1]:60254 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rsGEg-0000o2-JS for submit@debbugs.gnu.org; Thu, 04 Apr 2024 02:06:07 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:52289) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rsGEb-0000nC-Fe for 70167@debbugs.gnu.org; Thu, 04 Apr 2024 02:06:05 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id C1C14240027 for <70167@debbugs.gnu.org>; Thu, 4 Apr 2024 08:05:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1712210750; bh=lbOCT8V7gmwhkIxCkictZFkATA9rK2cxP3diCHnUbYE=; h=From:To:Cc:Subject:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=YTayhjn4AfHitmXku1b8fZ0k0glBcYqsnFNbCjV/GouomCvRRwW31etKFLzFApvEv DqOrmpkK/AMWsujPWgNHhzku/7n1qsdynBRxLkTSaYVQnCx71rAfoiAs0hPXBFz8HJ aFlgeTlWs3Zj9LIngAVMnhGUzS4o306V3jb+wm4oabM3GPJlOWrhqhDaXORN0c0/xC 3p57UmGhY2Inkc1x6xLmmIoaI5AujYrdhSgMi2hZKQp8SWaJwPg1jXJJThbWmSY9sf xh7GvCvHwcKBJRq5sUv+17MYhstIeFdIGM/0E04sxjN7+LXj2E15HQB5wLhtnyclF5 VvN96GWdBqMiQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4V9B1p29DLz6tx2; Thu, 4 Apr 2024 08:05:50 +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:282621 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