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#61558: 29.0.60; Indentation with c-ts-mode doesn't work in code guarded by #ifdef..#endif Date: Fri, 17 Feb 2023 20:49:23 +0100 Message-ID: <877cwgoyws.fsf@thornhill.no> References: <835yc12v7a.fsf@gnu.org> <87cz68p03u.fsf@thornhill.no> <83zg9cytni.fsf@gnu.org> Reply-To: Theodor Thornhill Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28366"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 61558@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Feb 17 20:50:22 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 1pT6kP-0007Ad-Jj for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 17 Feb 2023 20:50:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pT6k7-0003yZ-DJ; Fri, 17 Feb 2023 14:50:03 -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 1pT6k6-0003y6-93 for bug-gnu-emacs@gnu.org; Fri, 17 Feb 2023 14:50:02 -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 1pT6k5-00086U-UX for bug-gnu-emacs@gnu.org; Fri, 17 Feb 2023 14:50:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pT6k5-0006PK-MV for bug-gnu-emacs@gnu.org; Fri, 17 Feb 2023 14:50:01 -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 19:50:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61558 X-GNU-PR-Package: emacs Original-Received: via spool by 61558-submit@debbugs.gnu.org id=B61558.167666337124586 (code B ref 61558); Fri, 17 Feb 2023 19:50:01 +0000 Original-Received: (at 61558) by debbugs.gnu.org; 17 Feb 2023 19:49:31 +0000 Original-Received: from localhost ([127.0.0.1]:41620 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pT6jb-0006OU-04 for submit@debbugs.gnu.org; Fri, 17 Feb 2023 14:49:31 -0500 Original-Received: from out0.migadu.com ([94.23.1.103]:29854) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pT6jY-0006OK-Lp for 61558@debbugs.gnu.org; Fri, 17 Feb 2023 14:49:29 -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=1676663367; 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=iyIOUH2NRox1F7gNFW4JL0fw4MW7DwJxOks1KsA7M5Y=; b=Y8Hp3TYJhEkfLT3Qh/pN/CPC23caiVpwq5S7rnMct5e28xwG5t2CXhOd1mo94mHB4Zui0P YiUl0yKjil1troa0ucsBnohV0ENLRWPGvE5yZZDxBhOcA1w4taU5vLpdpHi0MbZTYObB8w pwkZlEOiqJSM8+1gKYybGQol61wqaL2H8mSxo3fd2/XqnRK0nfJMWOE37CN+DUC5c+mS3W 1tIhT8AvFAGAKn0jceUX8HQQbxzWVYxHgsZ1oT2lDJKCfueBUx1TYX5k/xRh6+RpcWhpgD /Be3zhLKRH8YhkGO6jCW9Vda/lTYH8/+TGWxSmXa6ZY0opwip+2me5xxAmTcTA== In-Reply-To: <83zg9cytni.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:255903 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Theodor Thornhill >> Cc: 61558@debbugs.gnu.org >> Date: Fri, 17 Feb 2023 20:23:33 +0100 >> >> #if defined GLYPH_DEBUG && defined ENABLE_CHECKING >> /* Increment number of allocated matrices. This count is used >> to detect memory leaks. */ >> ++glyph_matrix_count; >> #endif >> >> >> Is it a correct assuption to think that whatever is inside one of these >> if-blocks should indent according to their grand-parents rule? > > Yes. Basically, a cpp macro definition is like a comment: it > disappears when cpp processes it. So, from the language POV, it > doesn't exist. > >> In this case: >> >> >> static struct glyph_matrix * >> new_glyph_matrix (struct glyph_pool *pool) >> { >> struct glyph_matrix *result = xzalloc (sizeof *result); >> >> #if defined GLYPH_DEBUG && defined ENABLE_CHECKING >> /* Increment number of allocated matrices. This count is used >> to detect memory leaks. */ >> ++glyph_matrix_count; >> #endif >> >> /* Set pool and return. */ >> result->pool = pool; >> return result; >> } >> >> ++glyph_matrix_count; >> >> is indented one step from the compound_statement node, right? > > Sorry: what is the compound_statement node in this case? > compound_statement is a {} block. >> > Strangely, in other places indentation does work: lines 1069, 3119. >> > >> >> Yeah, in these cases we have something other than the preproc directive >> itself to indent from. > > Preprocessor directives should have no effect whatsoever on code > indentation. Right, thanks. Can you test this patch? It seems to work for me, but I'm no C expert. Theo --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Cleanup-preproc-indent-for-c-ts-mode.patch >From 30387d0a115f78b2184632e4f3bca6ee3a32417f Mon Sep 17 00:00:00 2001 From: Theodor Thornhill Date: Fri, 17 Feb 2023 20:46:19 +0100 Subject: [PATCH] Cleanup preproc indent for c-ts-mode * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Make sure we indent to grand-parent if inside an #ifdef...#endif block. If grandparent is root node, then don't indent one step. --- lisp/progmodes/c-ts-mode.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index a60c464093..54b1482403 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -246,13 +246,13 @@ c-ts-mode--indent-styles ((match nil "do_statement" "body") parent-bol c-ts-mode-indent-offset) ((match nil "for_statement" "body") parent-bol c-ts-mode-indent-offset) - ((match "preproc_ifdef" "compound_statement") point-min 0) - ((match "#endif" "preproc_ifdef") point-min 0) - ((match "preproc_if" "compound_statement") point-min 0) - ((match "#endif" "preproc_if") point-min 0) - ((match "preproc_function_def" "compound_statement") point-min 0) + ((node-is "preproc") point-min 0) + ((node-is "#endif") point-min 0) ((match "preproc_call" "compound_statement") point-min 0) + ((n-p-gp nil "preproc" "translation_unit") point-min 0) + ((parent-is "preproc") grand-parent c-ts-mode-indent-offset) + ((parent-is "function_definition") parent-bol 0) ((parent-is "conditional_expression") first-sibling 0) ((parent-is "assignment_expression") parent-bol c-ts-mode-indent-offset) -- 2.34.1 --=-=-=--