From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#69571: 29.2; csharp-mode indentation: Misaligned closing brace in blocks starting below "new" Date: Sun, 10 Mar 2024 20:21:32 +0100 Message-ID: <87zfv5riyr.fsf@thornhill.no> References: <20240305220951.00005489@cvkm.cz> <86zfv7yf3t.fsf@gnu.org> Reply-To: Theodor Thornhill Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8593"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 69571@debbugs.gnu.org To: Eli Zaretskii , Carlos , Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Mar 10 20:23:01 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 1rjOl9-0001yA-T1 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 10 Mar 2024 20:23:00 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rjOkh-00089s-Pm; Sun, 10 Mar 2024 15:22:31 -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 1rjOkf-000897-PT for bug-gnu-emacs@gnu.org; Sun, 10 Mar 2024 15:22:29 -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 1rjOkf-0002HP-HH for bug-gnu-emacs@gnu.org; Sun, 10 Mar 2024 15:22:29 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rjOlC-0002NS-PE for bug-gnu-emacs@gnu.org; Sun, 10 Mar 2024 15:23:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 10 Mar 2024 19:23: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.17100985679109 (code B ref 69571); Sun, 10 Mar 2024 19:23:02 +0000 Original-Received: (at 69571) by debbugs.gnu.org; 10 Mar 2024 19:22:47 +0000 Original-Received: from localhost ([127.0.0.1]:37895 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rjOkx-0002Mo-AS for submit@debbugs.gnu.org; Sun, 10 Mar 2024 15:22:47 -0400 Original-Received: from out-178.mta0.migadu.com ([91.218.175.178]:41221) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rjOku-0002MN-TU for 69571@debbugs.gnu.org; Sun, 10 Mar 2024 15:22:45 -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=thornhill.no; s=key1; t=1710098495; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Ytfd2fgxiTFqeySfjKIOIRv2xpiB2emKeKfSFQyFF6s=; b=Sfxh8HUL6SJWDSktN/6SDEUp+dOYkIZEVfV06SNug7Kwi2QvxNAqYYsQgzkdRMBvSaEATH R6BGC08HY0dJ99CpvhYuaBjMvTlCsnc07gnArj1FgE5mpbbleYfs0RNgxaMVq+chVuENHH MAMAkoOQ/e4txmDU2XDHIMWbTqppktnYDPCr1nyF9WzFmVpb9MM63w7jP4w+mq1alGjyPO Q646q5lAgcNjFMWRLqupVS3BUuHiXJ7RfSK24YGq4ab1oDovix8huARTCjRpAl7eYHgFaQ 9f8/cb/D8Erm2DdB6Z/GiIUXSmkCVJ2XZtT3Vehk6kmzteWBRVYsJA4y5Y5obw== In-Reply-To: <86zfv7yf3t.fsf@gnu.org> 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: , 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:281429 Archived-At: 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))