From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrey Listopadov Newsgroups: gmane.emacs.bugs Subject: bug#66159: 30.0.50; lua-ts-mode semantic indentation problems Date: Sat, 30 Sep 2023 12:59:28 +0300 Message-ID: <87wmw83qg2.fsf@gmail.com> References: <87fs36vvxl.fsf@gmail.com> <87v8bz3905.fsf@pub.pink> <878r8vwm9v.fsf@gmail.com> <87il7z5g3g.fsf@pub.pink> <87lecs4ttm.fsf@gmail.com> <87fs302oz3.fsf@pub.pink> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27338"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.8.11; emacs 30.0.50 Cc: 66159@debbugs.gnu.org, Philip Kaludercic , Eli Zaretskii To: john muhl Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 30 12:30:07 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 1qmXEd-0006oX-4i for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 30 Sep 2023 12:30:07 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmXEL-00070h-B4; Sat, 30 Sep 2023 06:29:49 -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 1qmXEK-000700-AV for bug-gnu-emacs@gnu.org; Sat, 30 Sep 2023 06:29:48 -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 1qmXEK-0000Xs-1D for bug-gnu-emacs@gnu.org; Sat, 30 Sep 2023 06:29:48 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qmXEY-0003EF-Od for bug-gnu-emacs@gnu.org; Sat, 30 Sep 2023 06:30:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andrey Listopadov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 30 Sep 2023 10:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66159 X-GNU-PR-Package: emacs Original-Received: via spool by 66159-submit@debbugs.gnu.org id=B66159.169606975512318 (code B ref 66159); Sat, 30 Sep 2023 10:30:02 +0000 Original-Received: (at 66159) by debbugs.gnu.org; 30 Sep 2023 10:29:15 +0000 Original-Received: from localhost ([127.0.0.1]:57777 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qmXDm-0003Cc-9s for submit@debbugs.gnu.org; Sat, 30 Sep 2023 06:29:14 -0400 Original-Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:54273) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qmXDh-0003CC-0y for 66159@debbugs.gnu.org; Sat, 30 Sep 2023 06:29:12 -0400 Original-Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-406589e5765so18240955e9.0 for <66159@debbugs.gnu.org>; Sat, 30 Sep 2023 03:28:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696069727; x=1696674527; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:message-id:in-reply-to:date :subject:cc:to:from:user-agent:references:from:to:cc:subject:date :message-id:reply-to; bh=gCurS4zaXyxvEZ1hi6Huoux7KN1SeLzg6Cs+9FkxK34=; b=H7QWROJAdy0yTCG5lftDLBC2rvWYxroHKTxyz6Re5UzWi20tAPiuKRUSUyR1wGkv3d +LMEdpLjQOc6zYgosKyvrndedTXmJKWoXFnqPqTfPg9oG0GfVhW+i6qEx/iQ1hl0IytU PXSzoErlWrzD4FQ8iYeyr7QhSkresJy32qmYNlj01H+f94CXSP4wPFRPc2Yi7UJLKbbu 737J3fNlsMLt/oJn/isMyLtPwbSt5e4bW4pnRoeUxmuwgrUSxSz8lgvoKi0gq79rbssl oss9Fg7IogM4iu9bqot19PixBZLjON2MOEBHr0KFHjr/cMDX/PwYDMMb09ihPziaF8oB 7e2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696069727; x=1696674527; h=content-transfer-encoding:mime-version:message-id:in-reply-to:date :subject:cc:to:from:user-agent:references:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=gCurS4zaXyxvEZ1hi6Huoux7KN1SeLzg6Cs+9FkxK34=; b=EdZNHzN1UQgY4OZ92Tsx+xVBnbELb6sxCAKL6JN6zkf13Qvt7UmU8B5NC1Nj0BE7fX 47nc+7O8wVgHQJKt0frUGrwTplcu0dvF0h0kjY2ywLjDr+7+LR6rbL8Uy59XkLm5aRWK ZC0Pl3ITjpez9OLGsx6qsWhEU3yjmA+7n+GwthNRYQhSLFMrpxdKWClTIQR2SW5MB4j+ Hrm/rAkeuuEqY4OsnxOwbzwo9Fxq19KSkTwzLEGeJsG882nUOWBMDyNrvrzjRta86my2 3AgnbYFffdqBAbIJx0lcPjJLvdl9Vk1zYTQ2PWoWdOWuk7NhCgu7HfgaNe1fhSgP+BqU LSLw== X-Gm-Message-State: AOJu0Yw1w5BgLndpt8mMRGaHm0Ky1vMSpP/Ce5OEn3NtJXId7cH/s65I hkLpYyOOfgwvgQHGSyuaGkY= X-Google-Smtp-Source: AGHT+IHoYmL3IyAf+e0s+g+RzpJHV2GNklYYGIx7txcWXttVu83S+bPp8BGuouwHu32WyhKTd9V13Q== X-Received: by 2002:adf:f38c:0:b0:31f:f91c:d872 with SMTP id m12-20020adff38c000000b0031ff91cd872mr6190689wro.19.1696069727051; Sat, 30 Sep 2023 03:28:47 -0700 (PDT) Original-Received: from toolbox.smtp.gmail.com (kotobank.ch. [195.154.83.132]) by smtp.gmail.com with ESMTPSA id 11-20020a056000156b00b0032485046055sm5533949wrz.5.2023.09.30.03.28.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 03:28:46 -0700 (PDT) In-reply-to: <87fs302oz3.fsf@pub.pink> 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:271537 Archived-At: john muhl writes: > I agree there=E2=80=99s no immediate need. > > Could you explain what the lua-indent-* options do in lua-mode? I tried > toggling them but didn=E2=80=99t see any difference between on/off. I don't really know it myself, sorry. There seem to be some specifics regarding how the content inside parenthesis is indented, but I'm not using these either. >> There are also some weirdness in semantic navigation, but it's more >> likely that I'm just not used to new ts-backed navigation yet. > > I=E2=80=99m sure there is room for improvement here too. Suggestions welc= ome. Here are a few examples. the =E2=96=88 represents the point: =E2=96=88(function (x) return x + 1 end)(41) Pressing C-M-f (forward-sexp) puts the point here: (function (x)=E2=96=88return x + 1 end)(41) I would expect it to go over the whole parenthesized expression: (function (x) return x + 1 end)=E2=96=88(41) Another weird thing here: function foo (x) if false then print "foo" elseif true then print "bar" end end=E2=96=88 Pressing C-M-b (backward-sexp) puts the point here: function foo (x) =E2=96=88if false then print "foo" elseif true then print "bar" end end I would expect it to go before the `function' instead: =E2=96=88function foo (x) if false then print "foo" elseif true then print "bar" end end >> If you're willing to dig into some (pretty crazy) involved examples, I >> can send here some really convoluted nested anonymous functions that >> currently are indented in a weird way in both modes. Neither does it >> exactly right in my opiion, but I also don't know if there is the right >> way to indent this. I can send these examples later this week once I >> finish an article I'm working on rightnow. > > Sure. Whenever you have the time. I've tried a couple of Lua formatters available, and as far as I can see, most of them indent my code in a weird way too, so perhaps it's not really a problem, although I'm not sure. For example, here's a piece of code that implements an iterator wrapper with anonymous functions only: 1 function partitioning (n, collect) 2 return function (iterator) 3 return function (...) 4 return ( 5 function (next1, ...) 6 local count, arr, last =3D 0, {} 7 return (function (f, ...) 8 return (function (i, ...) return i(i, ...) end)( 9 function (i, ...) 10 return f(function (x, ...) 11 return i(i, ...)(x, ...) 12 end, ...) 13 end) 14 end)(function (step) 15 return function(iterable, ...) 16 return (function (recur, iterable, ...) 17 if nil ~=3D ... then 18 if n-1 =3D=3D count then 19 local arr1, count1 =3D arr, count 20 arr, count =3D {}, 0 21 return (function (...) 22 last =3D ... 23 return ... 24 end)(collect(arr1, count1+1, ...= )) 25 else 26 count =3D count + 1 27 return recur(iterable, 28 (function (...) 29 last =3D ... 30 return ... 31 end)(collect(arr, c= ount, ...))) 32 end 33 elseif count ~=3D 0 then 34 count =3D 0 35 return last, arr 36 end 37 end)(step, iterable, next1(iterable, ...)) 38 end 39 end), ... 40 end)(iterator(...)) 41 end 42 end 43 end Here are the lines I find strange. First, the Immediately Invoked Function Expression (IIFE) indentation is all over the place: 8 return (function (i, ...) return i(i, ...) end)( 9 function (i, ...) 10 return f(function (x, ...) 11 return i(i, ...)(x, ...) 12 end, ...) 13 end) The I would expect the inner IIFE to be indented like this: 8 return (function (i, ...) return i(i, ...) end)( 9 function (i, ...) 10 return f(function (x, ...) 11 return i(i, ...)(x, ...) 12 end, ...) 13 end) Another strange snippet: 21 return (function (...) 22 last =3D ... 23 return ... 24 end)(collect(arr1, count1+1, ...= )) The `last' and `return' statements are not properly indented to the function's scope. I expected it to be indented like this: 21 return (function (...) 22 last =3D ... 23 return ... 24 end)(collect(arr1, count= 1+1, ...)) And, weirdly, enough, a bit further in the code there's a similar expression, but it is indented correctly: 27 return recur(iterable, 28 (function (...) 29 last =3D ... 30 return ... 31 end)(collect(arr, c= ount, ...))) I know, that this code is convoluted, and probably no one writes like this, it was done on purpose for an article about the power of anonymous functions, so perhaps it isn't really a problem for most Lua programmers. But it makes reading code a bit harder in rare cases like this. I have more examples in the article, feel free to grab them if you need code snippets for testing: https://andreyor.st/posts/2023-09-26-iterator-based-transducers-in-lua/ Other than that, and the navigation issues I've mentioned above, the mode works solidly. I've also noticed that some of the `lua-mode' default shortcuts are missing, like `C-c C-f' (lua-search-documentation) and `C-c C-l' (lua-send-buffer), but these may be out of the scope of this module, so let me know if I should just define these myself. Thanks! -- Andrey Listopadov