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#61541: 30.0.50; Wrong indentarion in csharp-mode Date: Sat, 18 Feb 2023 00:38:20 +0100 Message-ID: <87edqn6exf.fsf@thornhill.no> References: <87k00i7hko.fsf.ref@aol.com> <87k00i7hko.fsf@aol.com> <87a61cozw8.fsf@thornhill.no> <305e7060-58cc-344a-ae1a-98c82510aa88@secure.kjonigsen.net> <20230217214346.dr6d54yxk2rr6ucj@Ergus> Reply-To: Theodor Thornhill 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="3923"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 61541@debbugs.gnu.org To: Ergus , jostein@kjonigsen.net Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Feb 18 00:39:14 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 1pTAJs-0000sR-VN for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 18 Feb 2023 00:39:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pTAJk-00011q-V1; Fri, 17 Feb 2023 18:39:04 -0500 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 1pTAJj-00011R-5O for bug-gnu-emacs@gnu.org; Fri, 17 Feb 2023 18:39:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pTAJi-0005v4-T2 for bug-gnu-emacs@gnu.org; Fri, 17 Feb 2023 18:39:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pTAJi-0006JQ-He for bug-gnu-emacs@gnu.org; Fri, 17 Feb 2023 18:39:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 17 Feb 2023 23:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61541 X-GNU-PR-Package: emacs Original-Received: via spool by 61541-submit@debbugs.gnu.org id=B61541.167667710524210 (code B ref 61541); Fri, 17 Feb 2023 23:39:02 +0000 Original-Received: (at 61541) by debbugs.gnu.org; 17 Feb 2023 23:38:25 +0000 Original-Received: from localhost ([127.0.0.1]:41877 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pTAJ6-0006IQ-RE for submit@debbugs.gnu.org; Fri, 17 Feb 2023 18:38:25 -0500 Original-Received: from out0.migadu.com ([94.23.1.103]:23273) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pTAJ4-0006IH-Ml for 61541@debbugs.gnu.org; Fri, 17 Feb 2023 18:38:23 -0500 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=1676677101; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AobEtuJBI9jfCtWWRccsYtcWLQ4bA6KyBRHgJhiAVdI=; b=JhJaR2Cc2COa0P/13GI65aOEupyALH4YxBich+bnR4xCc6/MKe+Gevli/1UaXfoHJubcIe 1DqucOLVfdO0UKXh6ko/jzxe+I37oBlIYaq2upbUTrUBn8UY3gpfkJ1gHG3BYH+tOH+NcU AstUDvAvy0tCF9XwOx6wwAwZUMLTJBfWGtTruBB3z5/q90iAGFdMO+/A9tPWRRcRccY7J3 5HNqzWZGlZC/CpcN/1EjK/vr3txSjwKnb/2lK6ynJr2+HMfRLWQ8rmc7aUrqniC9ZnZEKS ToAMNdsXEZ1H5tMqRBNVF533gAhm0HyevxMC4QRAbA8WNY60U5R+GhWcXEY+0w== In-Reply-To: <20230217214346.dr6d54yxk2rr6ucj@Ergus> 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:255912 Archived-At: Ergus writes: > On Fri, Feb 17, 2023 at 10:06:50PM +0100, Jostein Kj=C3=AF=C2=BF=C2=BDnig= sen wrote: >>2/17/23 20:28, Theodor Thornhill wrote: >>>Ergus writes: >>> >>>>Hi: >>>> >>>>I just found that this indentations are wrong in csharp mode: >>>> >>>>// wrong >>>>new myNamespace.myClass >>>>{ >>>> Name1 =3D x.Value, // defun-block-intro >>>> var2 =3D 2 // statement-cont >>>> } // statement-cont >>>> >>>> >>>>The problem seems to be related with the dot (.) in the new, because >>>>this variant indents correctly: >>>> >>>>// right >>>>new myClass >>>>{ >>>> Name1 =3D x.Value, // brace-list-intro >>>> var2 =3D 2 // brace-list-entry >>>>} // brace-list-close >>>> >>>> >>>>csharp-ts-mode is doing it right BTW. >>>> >>>Hi! >>> >>>Yeah, this is one of the harder issues iirc, and one of the ones that >>>made us move to tree-sitter in csharp-mode in the first place. >>> >>>What do you think Jostein? >>> >>>Patches welcome! >>> >>>Theo >>> >>First of all: Thanks for a detailed bug-report. >> >>Then for the bad news: I may be missing something here. I'm on the=20 >>latest revision of the emacs-29 branch, and I really can't reproduce=20 >>at all. >> >>I've tried typing out the concrete code-samples above, and I've tried=20 >>copy-pasting them. >> >>No matter what I do, I cannot reproduce the behaviour outlined above. >> >>Ergus: Could you come up with a even more complete example? >> >>I mean... If I can't reproduce, I definitely won't be able to come up=20 >>with a patch. >> >>-- >>Jostein >> > > Hi Jostein: > > I just do: > > emacs -Q /tmp/main.cs > > Then pasted (or write) the code snippet shown in the example, and > re-indent the buffer: > > I get this: > > new myNamespace.myClass > { > Name1 =3D 1, > Name2 =3D2 > } > > Exactly like in the example C-c C-o shows the same than in the > example. Even the fontification is wrong. > > If I remove the dot like this myNamespacemyClass the fontification and > indentation is fixed immediately. > > I am using the master branch (emacs-version =3D 30.0.50) tomorrow I can > try to reproduce the issue on emacs-29 branch, but I have to build it. > > Best, > Ergus Try this, Ergus and Jostein. What do you think? diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el index b6b842d7fd..293a910081 100644 --- a/lisp/progmodes/csharp-mode.el +++ b/lisp/progmodes/csharp-mode.el @@ -474,28 +474,37 @@ csharp-guess-basic-syntax (and (eq (char-before) ?\]) (not (eq (char-after) ?\;)))))) `((annotation-top-cont ,(c-point 'iopl)))) - ((and ;; Heuristics to find object initializers (save-excursion ;; Next non-whitespace character should be '{' (goto-char (c-point 'boi)) - (eq (char-after) ?{)) - (save-excursion - ;; 'new' should be part of the line - (goto-char (c-point 'iopl)) - (looking-at ".*new.*")) + (unless (eq (char-after) ?{) + (backward-up-list 1 t t)) + (save-excursion + ;; 'new' should be part of the line + (goto-char (c-point 'iopl)) + (looking-at ".*new.*"))) ;; Line should not already be terminated (save-excursion (goto-char (c-point 'eopl)) (or (not (eq (char-before) ?\;)) (not (eq (char-before) ?\{))))) - (if (save-excursion - ;; if we have a hanging brace on line before - (goto-char (c-point 'eopl)) - (eq (char-before) ?\{)) - `((brace-list-intro ,(c-point 'iopl))) - `((block-open) (statement ,(c-point 'iopl))))) + (cond + ((save-excursion + ;; if we have a hanging brace on line before + (goto-char (c-point 'eopl)) + (eq (char-before) ?\{)) + `((brace-list-intro ,(c-point 'iopl)))) + ((save-excursion + ;; if we have a hanging brace on line before + (goto-char (c-point 'boi)) + (and (eq (char-after) ?\}) + `((brace-list-close ,(save-excursion + (backward-up-list 1 t t) + (point))))))) + (t + `((block-open) (statement ,(c-point 'iopl)))))) (t (apply orig-fun args)))) =20