From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov 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 19:01:32 +0200 Message-ID: <4eb476aa-bb60-42fe-95f9-98d3e88c4496@gutov.dev> References: <20240305220951.00005489@cvkm.cz> <86zfv7yf3t.fsf@gnu.org> <87zfv5riyr.fsf@thornhill.no> <86wmq25squ.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17920"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: carlos@cvkm.cz, casouri@gmail.com, 69571@debbugs.gnu.org To: Eli Zaretskii , Theodor Thornhill , Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Mar 16 18:02:53 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 1rlXQo-0004TM-Sd for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 16 Mar 2024 18:02:52 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rlXQR-0006FA-PW; Sat, 16 Mar 2024 13:02:28 -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 1rlXQQ-0006Em-7F for bug-gnu-emacs@gnu.org; Sat, 16 Mar 2024 13:02:26 -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 1rlXQP-0002JA-CT for bug-gnu-emacs@gnu.org; Sat, 16 Mar 2024 13:02:25 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rlXR0-0006ea-66 for bug-gnu-emacs@gnu.org; Sat, 16 Mar 2024 13:03:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 16 Mar 2024 17:03: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.171060854425499 (code B ref 69571); Sat, 16 Mar 2024 17:03:02 +0000 Original-Received: (at 69571) by debbugs.gnu.org; 16 Mar 2024 17:02:24 +0000 Original-Received: from localhost ([127.0.0.1]:56412 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rlXQN-0006dC-DK for submit@debbugs.gnu.org; Sat, 16 Mar 2024 13:02:23 -0400 Original-Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:54187) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rlXQL-0006cr-BN for 69571@debbugs.gnu.org; Sat, 16 Mar 2024 13:02:22 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 999DA3200302; Sat, 16 Mar 2024 13:01:37 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sat, 16 Mar 2024 13:01:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1710608497; x=1710694897; bh=CaaR7DG9FjqrydKXa+qOXz4SbnD8EQWvSE2QqN+qLbQ=; b= iEjrI8WYJBdprx9hAEL7cGxpzrT0d1BrgDxHOU8ARMcDiIgetqz6+K5aZB+kwpke tsux7sGwakGRJmPtmN3B2390Wlv9dcbZQYl3ulQl38z4J9ZdsGwNJzo8EXuf4cjw R69xjJ2wfQUz+foTQUaYSFk0fg4tVTInR2x3UKV9fTcXTcQrYIuBCz5A87/OgVSQ 4L1V6AI7LcUctLjhB476hqHLyUqxQabGJnLvzKLFfrsb+t7Vf13qUhqnayvXD6iH lR0JzTYaE6p1ybzj7CGGlWYt3hEVlt1ACT+SIrrSgA+medPlReU/OciK2blEqWtC r6St8eM137/LMTO8O09HAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1710608497; x= 1710694897; bh=CaaR7DG9FjqrydKXa+qOXz4SbnD8EQWvSE2QqN+qLbQ=; b=o xkCvvjQZUqSxwBgm0PaEU5pi7GGa9yFf1A3nKO2jtoSgrwt7WcwaqgL86gRD2Yom xUO9f8Tlf7ecAWftIQvYgVB7ZdJGYThQLJ4CCrhYOcS3yFIkphAlM5NfthIxXSgR HJa96dM/24hJ7nRmKKCYcgEuZUkUs5pBrS42gb8oxmvDLEF/csHOgx4ExdECPBQk G0lWhxwccnbmw7H0cNauqzO32FYBGNAPpUhnBI3j84ang4UW8QeBkHaEgUbTUg00 JdfuDKAUGVHuHPQGpqvYHTyHFf0wxrAUBc4eugbixaHdhnYzLg8lFjZqupgfkhz9 rN8IZnN4iteL8dXI+I3Yg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrkedvgdejvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfuvfevfhfhjggtgfesthejredttddvjeenucfhrhhomhepffhmihht rhihucfiuhhtohhvuceoughmihhtrhihsehguhhtohhvrdguvghvqeenucggtffrrghtth gvrhhnpeetudeljeegheetgfehgeejkeeuhedvveeikeeufedtvddtveefhfdvveegudej heenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegumh hithhrhiesghhuthhovhdruggvvh X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 16 Mar 2024 13:01:34 -0400 (EDT) Content-Language: en-US In-Reply-To: <86wmq25squ.fsf@gnu.org> 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:281728 Archived-At: On 16/03/2024 13:19, Eli Zaretskii wrote: > Ping! Yuan, could help Theo figure out what's best here? csharp-mode is based on CC Mode, not tree-sitter. So maybe Alan will want to comment. (csharp-ts-mode doesn't have this problem.) >> 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)) >> > > >