Subject: Re: [Uncrustify-developer] reindenting with uncrustify, maybe...

From: Jim Meyering <[email-masked]>
Date: Thu, 03 Jun 2010 09:19:11 +0200

Jim Meyering wrote:
> I'm considering whether to format coreutils' sources using uncrustify.
...
> Here is a summary of some nits contributing to the induced 14K-line
> diff.  If any of you can adjust the uncrustify config file I'm using
> to make that difference smaller, I'd appreciate patches.
>
>   - I do *not* want it to expand TABs used for comment and backslash
>     alignment, but haven't yet found how to do that, or if it's even
>     possible, in combination with the spaces-only-indentation mode.
>
>     For example, I don't want this sort of change:
>
>       -    case FTS_DC:		/* directory that causes cycles */
>       +    case FTS_DC:                /* directory that causes cycles */

I've fixed it for backslashes, but not yet for comments.
Here's a patch to make uncrustify honor its align_on_tabstop option
when aligning backslashes:

[Note: I let a personal preference sneak into this patch.
 I don't want to align-to-tabstop when there is only one continued line:

    #define foo \
      bar.................

 If others prefer to enable align-to-tabstop even for those
 situations, uncrustify could add an option.
]

>From 94929cba20a7a589151eebf0dded38167bb195ba Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email-masked]>
Date: Wed, 2 Jun 2010 13:14:28 +0200
Subject: [PATCH] Honor align_on_tabstop also when aligning backslashes.

* src/align.cpp (align_nl_cont): Honor align_on_tabstop also
when aligning backslashes.
---
 src/align.cpp |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/src/align.cpp b/src/align.cpp
index ff4f404..c79e5fc 100644
--- a/src/align.cpp
+++ b/src/align.cpp
@@ -1187,6 +1187,7 @@ static chunk_t *align_var_def_brace(chunk_t *start, int span, int *p_nl_count)
 chunk_t *align_nl_cont(chunk_t *start)
 {
    int        max_col = 0;
+   unsigned int n_continued = 0;
    chunk_t    *pc     = start;
    chunk_t    *tmp;
    ChunkStack cs;
@@ -1202,10 +1203,27 @@ chunk_t *align_nl_cont(chunk_t *start)
       if (pc->type == CT_NL_CONT)
       {
          align_add(cs, pc, max_col, 1, true);
+         n_continued++;
       }
       pc = chunk_get_next(pc);
    }

+   // Honor align_on_tabstop only when there are two or more continued lines.
+   if (cpd.settings[UO_align_on_tabstop].b && n_continued > 1)
+   {
+     int rem = (max_col - 1) % cpd.settings[UO_output_tab_size].n;
+     if (rem != 0)
+     {
+       // FIXME: cpd.settings[UO_output_tab_size].n is 0 here. that seems wrong.
+       int code_width = cpd.settings[UO_code_width].n;
+       code_width = code_width ? code_width : 80;
+
+       int t = max_col + cpd.settings[UO_output_tab_size].n - rem;
+       if (t < code_width)
+	 max_col = t;
+     }
+   }
+
    /* NL_CONT is always the last thing on a line */
    while ((tmp = cs.Pop()) != NULL)
    {
--
1.7.1.359.g19d56