emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 9c346270f9: CC Mode: New alignment function c-lineup-argcont-+


From: Alan Mackenzie
Subject: master 9c346270f9: CC Mode: New alignment function c-lineup-argcont-+
Date: Sat, 23 Apr 2022 16:04:57 -0400 (EDT)

branch: master
commit 9c346270f9848c5abf3c40def48ad1f65758763a
Author: Alan Mackenzie <acm@muc.de>
Commit: Alan Mackenzie <acm@muc.de>

    CC Mode: New alignment function c-lineup-argcont-+
    
    This fixes bug #21409.
    
    * lisp/progmodes/cc-align.el (c-lineup-argcont-1): New function, mainly
    extracted from c-lineup-argcont.
    (c-lineup-argcont): Refactored to use the new function above.
    (c-lineup-argcont-+): New function.
    
    * doc/misc/cc-mode.texi (Operator Line-Up): Add a new piece for
    c-lineup-argcont-+.
---
 doc/misc/cc-mode.texi      |  26 ++++++++++
 lisp/progmodes/cc-align.el | 120 +++++++++++++++++++++++++++------------------
 2 files changed, 99 insertions(+), 47 deletions(-)

diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi
index 8b36d1afd7..1f12c30b1f 100644
--- a/doc/misc/cc-mode.texi
+++ b/doc/misc/cc-mode.texi
@@ -6278,6 +6278,32 @@ expressions for the operands.
 
 @comment ------------------------------------------------------------
 
+@defun c-lineup-argcont-+
+@findex lineup-argcont-+ (c-)
+Indent a continued argument @code{c-basic-offset} spaces from the
+start of the first argument at the current level of nesting on a
+previous line.
+
+@example
+@group
+foo (xyz, uvw, aaa + bbb + ccc
+         + ddd + eee + fff);    <- c-lineup-argcont-+
+     <-->                          c-basic-offset
+@end group
+@end example
+
+Only continuation lines like this are touched, @code{nil} being
+returned on lines which are the start of an argument.
+
+Within a gcc @code{asm} block, @code{:} is recognized as an argument
+separator, but of course only between operand specifications, not in the
+expressions for the operands.
+
+@workswith @code{arglist-cont}, @code{arglist-cont-nonempty}.
+@end defun
+
+@comment ------------------------------------------------------------
+
 @defun c-lineup-arglist-operators
 @findex lineup-arglist-operators @r{(c-)}
 Line up lines starting with an infix operator under the open paren.
diff --git a/lisp/progmodes/cc-align.el b/lisp/progmodes/cc-align.el
index 8298d5fef0..e14f5b9058 100644
--- a/lisp/progmodes/cc-align.el
+++ b/lisp/progmodes/cc-align.el
@@ -202,6 +202,58 @@ Works with: arglist-cont-nonempty, arglist-close."
            (skip-chars-forward " \t"))
          (vector (current-column)))))))
 
+(defun c-lineup-argcont-1 (elem)
+  ;; Move to the start of the current arg and return non-nil, otherwise
+  ;; return nil.
+  (beginning-of-line)
+
+  (when (eq (car elem) 'arglist-cont-nonempty)
+    ;; Our argument list might not be the innermost one.  If it
+    ;; isn't, go back to the first position in it.  We do this by
+    ;; stepping back over open parens until we get to the open paren
+    ;; of our argument list.
+    (let ((open-paren (c-langelem-2nd-pos c-syntactic-element))
+         (paren-state (c-parse-state)))
+      (while (not (eq (car paren-state) open-paren))
+       (unless (consp (car paren-state)) ;; ignore matched braces
+         (goto-char (car paren-state)))
+       (setq paren-state (cdr paren-state)))))
+
+  (let ((start (point)) c)
+
+    (when (bolp)
+      ;; Previous line ending in a comma means we're the start of an
+      ;; argument.  This should quickly catch most cases not for us.
+      ;; This case is only applicable if we're the innermost arglist.
+      (c-backward-syntactic-ws)
+      (setq c (char-before)))
+
+    (unless (eq c ?,)
+      ;; In a gcc asm, ":" on the previous line means the start of an
+      ;; argument.  And lines starting with ":" are not for us, don't
+      ;; want them to indent to the preceding operand.
+      (let ((gcc-asm (save-excursion
+                      (goto-char start)
+                      (c-in-gcc-asm-p))))
+       (unless (and gcc-asm
+                    (or (eq c ?:)
+                        (save-excursion
+                          (goto-char start)
+                          (looking-at "[ \t]*:"))))
+
+         (c-lineup-argcont-scan (if gcc-asm ?:))
+         t)))))
+
+(defun c-lineup-argcont-scan (&optional other-match)
+  ;; Find the start of an argument, for `c-lineup-argcont'.
+  (when (zerop (c-backward-token-2 1 t))
+    (let ((c (char-after)))
+      (if (or (eq c ?,) (eq c other-match))
+         (progn
+           (forward-char)
+           (c-forward-syntactic-ws))
+       (c-lineup-argcont-scan other-match)))))
+
 ;; Contributed by Kevin Ryde <user42@zip.com.au>.
 (defun c-lineup-argcont (elem)
   "Line up a continued argument.
@@ -217,56 +269,30 @@ but of course only between operand specifications, not in 
the expressions
 for the operands.
 
 Works with: arglist-cont, arglist-cont-nonempty."
-
   (save-excursion
-    (beginning-of-line)
+    (when (c-lineup-argcont-1 elem)
+      (vector (current-column)))))
 
-    (when (eq (car elem) 'arglist-cont-nonempty)
-      ;; Our argument list might not be the innermost one.  If it
-      ;; isn't, go back to the last position in it.  We do this by
-      ;; stepping back over open parens until we get to the open paren
-      ;; of our argument list.
-      (let ((open-paren (c-langelem-2nd-pos c-syntactic-element))
-           (paren-state (c-parse-state)))
-       (while (not (eq (car paren-state) open-paren))
-         (unless (consp (car paren-state)) ;; ignore matched braces
-           (goto-char (car paren-state)))
-         (setq paren-state (cdr paren-state)))))
-
-    (let ((start (point)) c)
-
-      (when (bolp)
-       ;; Previous line ending in a comma means we're the start of an
-       ;; argument.  This should quickly catch most cases not for us.
-       ;; This case is only applicable if we're the innermost arglist.
-       (c-backward-syntactic-ws)
-       (setq c (char-before)))
-
-      (unless (eq c ?,)
-       ;; In a gcc asm, ":" on the previous line means the start of an
-       ;; argument.  And lines starting with ":" are not for us, don't
-       ;; want them to indent to the preceding operand.
-       (let ((gcc-asm (save-excursion
-                        (goto-char start)
-                        (c-in-gcc-asm-p))))
-         (unless (and gcc-asm
-                      (or (eq c ?:)
-                          (save-excursion
-                            (goto-char start)
-                            (looking-at "[ \t]*:"))))
-
-           (c-lineup-argcont-scan (if gcc-asm ?:))
-           (vector (current-column))))))))
+(defun c-lineup-argcont-+ (langelem)
+  "Indent an argument continuation `c-basic-offset' in from the first argument.
 
-(defun c-lineup-argcont-scan (&optional other-match)
-  ;; Find the start of an argument, for `c-lineup-argcont'.
-  (when (zerop (c-backward-token-2 1 t))
-    (let ((c (char-after)))
-      (if (or (eq c ?,) (eq c other-match))
-         (progn
-           (forward-char)
-           (c-forward-syntactic-ws))
-       (c-lineup-argcont-scan other-match)))))
+This first argument is that on a previous line at the same level of nesting.
+
+foo (xyz, uvw, aaa + bbb + ccc
+         + ddd + eee + fff);    <- c-lineup-argcont-+
+     <-->                          c-basic-offset
+
+Only continuation lines like this are touched, nil being returned
+on lines which are the start of an argument.
+
+Works with: arglist-cont, arglist-cont-nonempty."
+  (save-excursion
+    (when (c-lineup-argcont-1 langelem)        ; Check we've got a continued 
argument...
+      ;; ... but ignore the position found.
+      (goto-char (c-langelem-2nd-pos c-syntactic-element))
+      (forward-char)
+      (c-forward-syntactic-ws)
+      (vector (+ (current-column) c-basic-offset)))))
 
 (defun c-lineup-arglist-intro-after-paren (_langelem)
   "Line up a line to just after the open paren of the surrounding paren



reply via email to

[Prev in Thread] Current Thread [Next in Thread]