From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jeff Norden Newsgroups: gmane.emacs.bugs Subject: bug#64133: CC Mode 5.35.2 (C/*l); incorrect indentation for an arrays of structs. Date: Sat, 17 Jun 2023 10:03:24 -0500 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27505"; mail-complaints-to="usenet@ciao.gmane.io" To: 64133@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 17 17:05:24 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 1qAXUR-0006wT-HR for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 17 Jun 2023 17:05:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qAXUB-0001dy-Bk; Sat, 17 Jun 2023 11:05:07 -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 1qAXU7-0001df-By for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2023 11:05:03 -0400 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 1qAXU6-0004gw-49 for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2023 11:05:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qAXU5-0008SB-TT for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2023 11:05:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jeff Norden Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 17 Jun 2023 15:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 64133 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.168701425732422 (code B ref -1); Sat, 17 Jun 2023 15:05:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 17 Jun 2023 15:04:17 +0000 Original-Received: from localhost ([127.0.0.1]:52271 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAXTN-0008Qp-Du for submit@debbugs.gnu.org; Sat, 17 Jun 2023 11:04:17 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:45556) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAXTJ-0008Qf-HC for submit@debbugs.gnu.org; Sat, 17 Jun 2023 11:04:15 -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 1qAXTI-0001aC-K1 for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2023 11:04:12 -0400 Original-Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qAXTE-0004Ql-MW for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2023 11:04:12 -0400 Original-Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-666e6ecb52dso636539b3a.2 for ; Sat, 17 Jun 2023 08:03:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687014230; x=1689606230; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=HJsH+vKBbEP06bXCFs+lwhVzcxSyFGVNU09UzBBIgJw=; b=qMH6ZJJrcXa3PjgB+gF6smJhLTMD4V2OIoPp5TttnNF3fjeYzn1m+lAxkOl2BqwkWn 5JXNyGUAS/4ojyUica6D7WHKNvP1pI+YEhHnDIVtjEkpTHZooTxWZ3Is9g/ajgJUt/fz 32QJ5CaM4ZYAbZ76P0S98/gHi2yfbLl4gL2osgRJsejvIppYXBDTPPgZHA/VuC4ncwMZ MD2KQj3cW9o9pTqYsiGUj1wj0jC9lAxAqKi4v/9ADFwttpDzEV8PjVsNv9jqZ6hJH2vR igFpejqIdFk4sPwMKZKAeqgKnZufKofeKMXFWSyKyEIQb0iRqM1cx5x1G3IYgSG8/+0G Jgjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687014230; x=1689606230; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=HJsH+vKBbEP06bXCFs+lwhVzcxSyFGVNU09UzBBIgJw=; b=A0iKbysnS2Jbh589SHOOZt39qwIOKRdyPpMiT7eWf8B81L5NfQ9s+WS5hakUY26U5Z Q5WrcStalZyNknX2soLwOuCix1sfai1H2WugjhPqIdd+0adfLlfi1aCGSHWcdxGKXJt1 Ln84HZDdiQDscudzee/BOo+SLK1buvmwdgtT2fD65eQCr5YNpR1KFcjCJIUxrpijGb+b YbFIQWsqWm2F3KY3IipdV1w+gu2AHLptRm+NCmd/x3CSRrhRle8e3dE/hdqG2e+L8wpe jKmHuHWJ5Mv5yYXKSTVHWwEij1QGhrByvkBpJa7Zh7d44q7hICxD8/2SK+6dpldGOAQr NnrQ== X-Gm-Message-State: AC+VfDyCKH0RblcH4cxXaI1rsZG6iAM2rfuSw26uvd+0OvkdygMHRK15 z6eELYmBF3CZ4vL0D1kSvuqv2vzIAuHiTZ3DNXbPSGoe8kM= X-Google-Smtp-Source: ACHHUZ5OEaFC7qAedYj+JxgQafAXzcDKW1HSm3yRmlxWIOftqrqFziGITFKGHnQSuBqU6GqhqD7ptWWkhHhoVM620Rk= X-Received: by 2002:a17:90a:fe8d:b0:255:b1d9:a206 with SMTP id co13-20020a17090afe8d00b00255b1d9a206mr2927991pjb.22.1687014230069; Sat, 17 Jun 2023 08:03:50 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=norden.jeff@gmail.com; helo=mail-pf1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:263546 Archived-At: I've verified the following behavior with c-version 5.35.2 (emacs-29, and emacs-30 from git) and with 5.35.1 (emacs 28.2). Place the following text into a file with a ".c" extension, and load it with "emacs -Q". ========================================== #include struct three_ints { int a, b, c; }; int main () { struct three_ints numbers[]= { {0,1,2}, {3,4,5}, {6,7,8} }; for (int i=0; i to indent the line. It will be incorrectly indented 2 spaces more than the previous line. Move to the next line, press , and you'll see: struct three_ints numbers[]= { {0,1,2}, {3,4,5}, {6,7,8} }; Just using to re-indent the lines will not change anything. But, if you add or delete white-space before {0,1,2} or {3,4,5} and press , it *may* fix things. It seems to depend on just what you delete and where the cursor is. The pattern isn't clear to me. Once fixed, you get: struct three_ints numbers[]= { {0,1,2}, {3,4,5}, {6,7,8} }; At this point it is stable, and will work correctly. If you restart c-mode with "M-x c-mode", the problem re-occurs. This bug only seems to occur when a loop or similar construct occurs after the array declaration/initialization. It doesn't need to immediately follow, though. When incorrectly indenting, "C-c C-s" shows 'defun-block-intro' syntax for the {0,1,2} line, and 'substatement-open' for {3,4,5} and {4,5,6}. Once it gets fixed, this changes to 'brace-list-intro' and 'brace-entry-open'. ========================================== For a more "real world" example, start with the example program at the end of the getopt_long(3) man page: https://linux.die.net/man/3/getopt_long and move the declaration of long_options[] from inside the while loop to before it. (This makes long_options a global variable, instead of local to the loop). ========================================== I'm afraid I can't offer a patch or suggestion for a fix. My own attempts at "parsing" the lisp in cc-engine.el come to an abrupt halt when my brain receives an urgent "Warning! Meltdown imminent!" message from my subconscious -- just kidding :-). However, I did stumble upon the following in the comments for the `c-inside-bracelist-p' function: ;; CONTAINING-SEXP is the buffer pos of the innermost containing ;; paren. NO IT ISN'T!!! [This function is badly designed, and ;; probably needs reformulating without its first argument, ... Thanks, -Jeff ---------------------------- If believing that "function is more important than form" and that "people are more important than technology" makes me a Luddite, then so be it!