From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#69571: 29.2; csharp-mode indentation: Misaligned closing brace in blocks starting below "new" Date: Sat, 16 Mar 2024 13:19:21 +0200 Message-ID: <86wmq25squ.fsf@gnu.org> References: <20240305220951.00005489@cvkm.cz> <86zfv7yf3t.fsf@gnu.org> <87zfv5riyr.fsf@thornhill.no> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14426"; mail-complaints-to="usenet@ciao.gmane.io" Cc: carlos@cvkm.cz, casouri@gmail.com, 69571@debbugs.gnu.org To: Theodor Thornhill Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Mar 16 12:20:38 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 1rlS5e-0003Yk-IZ for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 16 Mar 2024 12:20:38 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rlS5S-0005mj-Tv; Sat, 16 Mar 2024 07:20:26 -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 1rlS5R-0005mQ-TS for bug-gnu-emacs@gnu.org; Sat, 16 Mar 2024 07:20:25 -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 1rlS5R-00025D-Lc for bug-gnu-emacs@gnu.org; Sat, 16 Mar 2024 07:20:25 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rlS62-00023r-Fy for bug-gnu-emacs@gnu.org; Sat, 16 Mar 2024 07:21:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 16 Mar 2024 11:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69571 X-GNU-PR-Package: emacs Original-Received: via spool by 69571-submit@debbugs.gnu.org id=B69571.17105880117828 (code B ref 69571); Sat, 16 Mar 2024 11:21:02 +0000 Original-Received: (at 69571) by debbugs.gnu.org; 16 Mar 2024 11:20:11 +0000 Original-Received: from localhost ([127.0.0.1]:55012 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rlS5C-00022B-Pc for submit@debbugs.gnu.org; Sat, 16 Mar 2024 07:20:11 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:46222) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rlS59-00021t-Bn for 69571@debbugs.gnu.org; Sat, 16 Mar 2024 07:20:08 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rlS4S-0001iR-Dg; Sat, 16 Mar 2024 07:19:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=fkRMYskNPVqByE+ckVmAg0Rnx3RJrkeEHvaiFMNXF4I=; b=h3TVnv8ubxmH eX3eVHhjHEgEqPt/t4z2untrnSJdzVDNqst2+T6mYm6vk4hwCD9dfWMgvXlhniAeAq7trmMCu/3kC cJZDKUnwNveKpTi7Xavev1kxfSPnFb/ZoILhWJ6vkBysxA7pH8dxFxUswIlcFQRwosqyt/1F5UWCs FtTF1xr5Y05jpdEQamw/zHqcglTQx20SlM8ttJB0Zyz5CmGVZyRJ6ijnf3nv8SBf0hiTsqJYbkWbk xaoQ9RzLk7sslP3VAleqiGz11NRdtnBzlw+UciR8/QEJCSb3/Quy4kV3sgRS9U26/xk/pmYztcxgi xmsR1PhOlWOnSsBhRZS9/g==; In-Reply-To: <87zfv5riyr.fsf@thornhill.no> (message from Theodor Thornhill on Sun, 10 Mar 2024 20:21:32 +0100) 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:281722 Archived-At: Ping! Yuan, could help Theo figure out what's best here? > From: Theodor Thornhill > Cc: 69571@debbugs.gnu.org > Date: Sun, 10 Mar 2024 20:21:32 +0100 > > Eli Zaretskii writes: > > >> Date: Tue, 5 Mar 2024 22:09:51 +0100 > >> From: Carlos > >> > >> Any block starting on the line immediately below a line having the > >> string "new" will have its closing brace aligned with the opening one. > >> > >> See the following code: > >> > >> public class Foo { > >> void Bar () { > >> var x = new X(); // [1] > >> for (;;) { > >> x(); > >> } // [2] > >> } > >> } > >> > >> Line [1] says "new". The closing brace in line [2] is aligned to the > >> opening brace. > >> > >> If you comment out the "new" (or the whole line) the problem persists. > >> > >> If you remove the "new" the problem goes away and [2] is correctly > >> aligned. > >> > >> If you insert a line between line [1] and the one having the opening > >> brace the problem goes away. > > > > Theo and Yuan, could you please look into this? > > I have a working patch for this, but I'd like to expand it to cover an > edge case for which I'm unable to find a good solution. Can you suggest > a way around this edge case? > > Consider the provided code: > ``` > public class Foo { > void Bar () { > var x = new X(); // [1] > for (;;) { > x(); > } // [2] > } > } > ``` > > Like this, the below patch doesn't work. If you remove the first > comment, the patch works. > > ``` > public class Foo { > void Bar () { > var x = new X(); > for (;;) { > x(); > } // [2] > } > } > ``` > > The reason is simple, of course. What I'm struggling with here is how to > best handle the case where there is a comment ending the line, possibly > containing a ';' itself. I've tried some variations with save-excursion > along with syntax-ppss to detect whether or not we're in a comment, but > it gets verbose and ugly. Is there some simple way to do this check in > Emacs, or should I just resort to making some best effort judgement call > here? > > Thanks, > Theo > > diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el > index 7bf57bcbe21..00278e18e51 100644 > --- a/lisp/progmodes/csharp-mode.el > +++ b/lisp/progmodes/csharp-mode.el > @@ -495,9 +495,10 @@ csharp-guess-basic-syntax > (unless (eq (char-after) ?{) > (ignore-errors (backward-up-list 1 t t))) > (save-excursion > - ;; 'new' should be part of the line > + ;; 'new' should be part of the line, but should not trigger if > + ;; statement has already ended, like for 'var x = new X();'. > (goto-char (c-point 'iopl)) > - (looking-at ".*new.*"))) > + (looking-at ".*new.*[^;]$"))) > ;; Line should not already be terminated > (save-excursion > (goto-char (c-point 'eopl)) >