From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Olivier Certner Newsgroups: gmane.emacs.bugs Subject: bug#63286: 30.0.50; CC Mode: New `c-for-clauses-as-arglist' style variable Date: Fri, 05 May 2023 00:22:12 +0200 Message-ID: <2123423.7n0gGkaxiF@ravel> References: <1769719.uSAL7GYomB@ravel> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart4132696.SpxzoVVZVy" Content-Transfer-Encoding: 7Bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30728"; mail-complaints-to="usenet@ciao.gmane.io" To: 63286@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri May 05 00:23:23 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 1puhMA-0007jp-A6 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 05 May 2023 00:23:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puhLs-0005l6-3v; Thu, 04 May 2023 18:23:04 -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 1puhLq-0005kq-Je for bug-gnu-emacs@gnu.org; Thu, 04 May 2023 18:23:02 -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 1puhLq-0006yj-Ba for bug-gnu-emacs@gnu.org; Thu, 04 May 2023 18:23:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1puhLq-0003mo-6k for bug-gnu-emacs@gnu.org; Thu, 04 May 2023 18:23:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Olivier Certner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 04 May 2023 22:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63286 X-GNU-PR-Package: emacs Original-Received: via spool by 63286-submit@debbugs.gnu.org id=B63286.168323893514461 (code B ref 63286); Thu, 04 May 2023 22:23:02 +0000 Original-Received: (at 63286) by debbugs.gnu.org; 4 May 2023 22:22:15 +0000 Original-Received: from localhost ([127.0.0.1]:52280 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1puhL4-0003lA-Ki for submit@debbugs.gnu.org; Thu, 04 May 2023 18:22:15 -0400 Original-Received: from smtp2-g21.free.fr ([212.27.42.2]:17950) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1puhL3-0003l3-FT for 63286@debbugs.gnu.org; Thu, 04 May 2023 18:22:14 -0400 Original-Received: from ravel.localnet (unknown [90.118.140.172]) (Authenticated sender: ocert.dev@free.fr) by smtp2-g21.free.fr (Postfix) with ESMTPSA id E3ECE2003CA for <63286@debbugs.gnu.org>; Fri, 5 May 2023 00:22:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=free.fr; s=smtp-20201208; t=1683238932; bh=alNUdjNEI4X+c51LcCxbpZlpzqyJ7Q6ti936rfOR/Bc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=C0Zm5rG+JvzpzmCXMh4XsZg6kXPxQfH3Vuy0r9KBLheM91mWerOngO+7HUCBS0t3Z l10XCebn7+vDC2O4GXsyuqwnoF8c+yOOAs5a/gQvIT5MSoMvgqM28wvxjjpOOWHuzA Am7vMn66ccoa7X3++ZhsQOCTA7ZXK8NWcbv8WmZEicY4jp4m4DOt0rczoQ3Wkle2YU NF/uetDPT7idffpCQQINRgK1E6GxWJmAxmtJTSdpW+8SgthC82FjHQjgjfUA5NwJSR iYe2/RidGaNQS/4cN+yNejo78nDShImRYJWyVToUZcsNDmNYvBe+/yD763K9jye+lE PnVe55MxhQpaQ== In-Reply-To: <1769719.uSAL7GYomB@ravel> 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:261040 Archived-At: This is a multi-part message in MIME format. --nextPart4132696.SpxzoVVZVy Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" Proposed change. -- Olivier Certner --nextPart4132696.SpxzoVVZVy Content-Disposition: attachment; filename="0001-CC-Mode-New-c-for-clauses-as-arglist-style-variable.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="unicode-2-0-utf-8"; name="0001-CC-Mode-New-c-for-clauses-as-arglist-style-variable.patch" >From 3a84abb4cb06f9673c851aa44f2f1b27752560ef Mon Sep 17 00:00:00 2001 From: Olivier Certner Date: Wed, 3 May 2023 18:12:27 +0200 Subject: [PATCH] CC Mode: New `c-for-clauses-as-arglist' style variable This new style variable allows to disable special handling of "for" statements' clauses, which is that there are indented as statements, or continuations of such, when on separate lines instead of argument lists or continuations of such. * lisp/progmodes/cc-engine.el (c-guess-basic-syntax): Skip case 7D, which specifically handles the above-mentioned case. While here, rewrite the case's comment to be more explicit about what it does. * lisp/progmodes/cc-vars.el (c-for-clauses-as-arglist): The new style variable. (c-style-variables): Include the new style variable. (c-style-variables-are-local-p): Update documentation following addition of the variable. * doc/misc/cc-mode.texi (Style Variables): List the new variable. (Syntactic Symbols): Indicate precisely which syntactic symbol can appear in a syntactic element when analyzing `for' clauses depending on the style variable value. (Bug#63286) --- doc/misc/cc-mode.texi | 19 ++++++++++++++----- lisp/progmodes/cc-engine.el | 13 +++++++------ lisp/progmodes/cc-vars.el | 14 +++++++++++++- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi index 71bf3fcee4a..0e4ba4c6a91 100644 --- a/doc/misc/cc-mode.texi +++ b/doc/misc/cc-mode.texi @@ -2624,6 +2624,7 @@ Style Variables Commas});@* @code{c-cleanup-list} (@pxref{Clean-ups});@* @code{c-basic-offset} (@pxref{Customizing Indentation});@* +@code{c-for-clauses-as-arglist} (@pxref{Syntactic Symbols});@* @code{c-offsets-alist} (@pxref{c-offsets-alist});@* @code{c-comment-only-line-offset} (@pxref{Comment Line-Up});@* @code{c-special-indent-hook}, @code{c-label-minimum-indentation} @@ -4267,7 +4268,8 @@ Syntactic Symbols Subsequent lines in an enum or static array list where the line begins with an open brace. @ref{Brace List Symbols}. @item statement -A statement. @ref{Function Symbols}. +A statement, including `for' clauses except if +@code{c-for-clauses-as-arglist} is true. @ref{Function Symbols}. @item statement-cont A continuation of a statement. @ref{Function Symbols}. @item annotation-var-cont @@ -4309,15 +4311,22 @@ Syntactic Symbols @item comment-intro A line containing only a comment introduction. @ref{Literal Symbols}. @item arglist-intro -The first line in an argument list. @ref{Paren List Symbols}. +The first line in an argument list or a parenthesized expression. +Note that @code{for} clauses are rather considered statements (or +their continuation) except if @code{c-for-clauses-as-arglist} is true. +@ref{Paren List Symbols}. @item arglist-cont Subsequent argument list lines when no arguments follow on the same -line as the arglist opening paren. @ref{Paren List Symbols}. +line as the arglist opening paren. Same remark concerning @code{for} +clauses as for @code{arglist-intro} above. @ref{Paren List Symbols}. @item arglist-cont-nonempty Subsequent argument list lines when at least one argument follows on -the same line as the arglist opening paren. @ref{Paren List Symbols}. +the same line as the arglist opening paren. Same remark concerning +@code{for} clauses as for @code{arglist-intro} above. @ref{Paren List +Symbols}. @item arglist-close -The solo close paren of an argument list. @ref{Paren List Symbols}. +The solo close paren of an argument list or a @code{for} clause. +@ref{Paren List Symbols}. @item stream-op Lines continuing a stream operator (C++ only). @ref{Literal Symbols}. @c @emph{FIXME!!! Can this not be moved somewhere better?} diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 27740b4903c..409cbc59ab5 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -15246,12 +15246,13 @@ c-guess-basic-syntax (c-most-enclosing-brace paren-state (point)) paren-state)) - ;; CASE 7D: we are inside a conditional test clause. treat - ;; these things as statements - ((progn - (goto-char containing-sexp) - (and (c-safe (c-forward-sexp -1) t) - (looking-at "\\[^_]"))) + ;; CASE 7D: We are inside a for clause. Treat these clauses + ;; as statements unless `c-for-clauses-as-arglist' is + ;; non-nil. + ((and (not c-for-clauses-as-arglist) + (goto-char containing-sexp) + (c-safe (c-forward-sexp -1) t) + (looking-at "\\[^_]")) (goto-char (1+ containing-sexp)) (c-forward-syntactic-ws indent-point) (if (eq char-before-ip ?\;) diff --git a/lisp/progmodes/cc-vars.el b/lisp/progmodes/cc-vars.el index 72d4b93ee59..304ebca52fe 100644 --- a/lisp/progmodes/cc-vars.el +++ b/lisp/progmodes/cc-vars.el @@ -158,7 +158,8 @@ c-style-variables c-comment-prefix-regexp c-doc-comment-style c-cleanup-list c-hanging-braces-alist c-hanging-colons-alist c-hanging-semi&comma-criteria c-backslash-column c-backslash-max-column - c-special-indent-hook c-label-minimum-indentation c-offsets-alist) + c-special-indent-hook c-label-minimum-indentation + c-for-clauses-as-arglist c-offsets-alist) "List of the style variables.") (defvar c-fallback-style nil) @@ -960,6 +961,16 @@ c-label-minimum-indentation :type 'integer :group 'c) +(defcustom-c-stylevar c-for-clauses-as-arglist nil + "Whether to consider for clauses as part of an argument list. +The clauses of the for statement are normally considered by CC +mode as separate statements when at start of a line \(and +statement continuations when split). Setting this variable to +non-nil indicates that they should be treated as any other +argument lists." + :type 'boolean + :group 'c) + (defcustom c-progress-interval 5 "Interval used to update progress status during long re-indentation. If a number, percentage complete gets updated after each interval of @@ -1449,6 +1460,7 @@ c-style-variables-are-local-p `c-backslash-column' `c-backslash-max-column' `c-label-minimum-indentation' + `c-for-clauses-as-arglist' `c-offsets-alist' `c-special-indent-hook' `c-indentation-style'" -- 2.39.2 --nextPart4132696.SpxzoVVZVy--