unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Olivier Certner <ocert.dev@free.fr>
To: 63286@debbugs.gnu.org
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	[thread overview]
Message-ID: <2123423.7n0gGkaxiF@ravel> (raw)
In-Reply-To: <1769719.uSAL7GYomB@ravel>

[-- Attachment #1: Type: text/plain, Size: 37 bytes --]

Proposed change.

-- 
Olivier Certner

[-- Attachment #2: 0001-CC-Mode-New-c-for-clauses-as-arglist-style-variable.patch --]
[-- Type: text/x-patch, Size: 6248 bytes --]

From 3a84abb4cb06f9673c851aa44f2f1b27752560ef Mon Sep 17 00:00:00 2001
From: Olivier Certner <olce.emacs@certner.fr>
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 "\\<for\\>[^_]")))
+	 ;; 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 "\\<for\\>[^_]"))
 	  (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


  reply	other threads:[~2023-05-04 22:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-04 22:19 bug#63286: 30.0.50; CC Mode: New `c-for-clauses-as-arglist' style variable Olivier Certner
2023-05-04 22:22 ` Olivier Certner [this message]
2023-05-05  4:57   ` Eli Zaretskii
2023-05-06 21:49     ` Olivier Certner
2023-05-05 11:14   ` Alan Mackenzie
2023-05-06 21:41     ` Olivier Certner
2023-05-08 15:02       ` Alan Mackenzie
2023-05-09 10:08         ` Olivier Certner
2023-05-09 15:11           ` Alan Mackenzie
2023-05-10 13:20             ` Olivier Certner
2023-05-10 14:26               ` Eli Zaretskii
2023-09-11 18:14               ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2123423.7n0gGkaxiF@ravel \
    --to=ocert.dev@free.fr \
    --cc=63286@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).