Hi James and Bram,

2015-10-4 (Sun) 22:29:23 UTC+9 h_east:
> Hi James!
> 
> 2015-8-2 (Sun) 13:46:34 UTC+9 James McCoy:
> > Given the file foo.cc
> > 
> > -- >8 --
> > class a {
> >     public:
> >             a() : i(0)
> >             {
> >             }
> > 
> >             a()
> >                     : i(0)
> >             {
> >             }
> > 
> >             a() : i(0) {
> >             }
> > };
> > -- 8< --
> > 
> > Performing '=G' from line 1 results in
> > 
> > -- >8 --
> > class a {
> >     public:
> >             a() : i(0)
> >     {
> >     }
> > 
> >             a()
> >                     : i(0)
> >             {
> >             }
> > 
> >             a() : i(0) {
> >             }
> > };
> > -- 8< --
> > 
> > The block of the constructor on line 3 gets dedented when it shouldn't.
> > The backtracking to find the start of the constructor, so it can be used
> > as the basis for indenting the block, finds the scope declaration and
> > keys off of that instead.
> > 
> > The cindent code is pretty hairy.  I wasn't able to find an obvious fix.
> 
> I can reproduce it.
> And began to investigate.
> Perhaps I would fix this problem.
> 
> Please wait a week.

I got it!

Please confirm an attached patch. (Contains test)

--
Best regards,
Hirohito Higashi (a.k.a h_east)

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff -r 7271fdea3884 src/misc1.c
--- a/src/misc1.c	Tue Sep 29 18:15:04 2015 +0200
+++ b/src/misc1.c	Wed Oct 07 10:20:16 2015 +0900
@@ -5485,8 +5485,9 @@
 
 /* Find result cache for cpp_baseclass */
 typedef struct {
-    int	    found;
-    lpos_T  lpos;
+    int		found;
+    linenr_T	start_of_decl;
+    lpos_T	lpos;
 } cpp_baseclass_cache_T;
 
 /*
@@ -6494,6 +6495,8 @@
     int		class_or_struct, lookfor_ctor_init, cpp_base_class;
     linenr_T	lnum = curwin->w_cursor.lnum;
     char_u	*line = ml_get_curline();
+    linenr_T	start_of_decl;
+    pos_T	end_paren = { 0, 0 };
 
     if (pos->lnum <= lnum)
 	return cached->found;	/* Use the cached result */
@@ -6542,6 +6545,7 @@
 	--lnum;
     }
 
+    start_of_decl = lnum;
     pos->lnum = lnum;
     line = ml_get(lnum);
     s = cin_skipcomment(line);
@@ -6586,6 +6590,8 @@
 	{
 	    class_or_struct = TRUE;
 	    lookfor_ctor_init = FALSE;
+	    if (!cpp_base_class)
+		start_of_decl = lnum;
 
 	    if (*s == 'c')
 		s = cin_skipcomment(s + 5);
@@ -6604,6 +6610,12 @@
 		 * something like "):" */
 		class_or_struct = FALSE;
 		lookfor_ctor_init = TRUE;
+		if (!cpp_base_class)
+		{
+		    start_of_decl = 0;
+		    end_paren.lnum = lnum;
+		    end_paren.col = (colnr_T)(s - line);
+		}
 	    }
 	    else if (s[0] == '?')
 	    {
@@ -6636,7 +6648,28 @@
 
     cached->found = cpp_base_class;
     if (cpp_base_class)
+    {
 	pos->lnum = lnum;
+	if (start_of_decl > 0)
+	    cached->start_of_decl = start_of_decl;
+	else
+	{
+	    pos_T   *start_paren;
+	    pos_T   cursor_save = curwin->w_cursor;
+
+	    curwin->w_cursor = end_paren;
+	    start_paren = findmatchlimit(NULL, '(', FM_BACKWARD,
+							curbuf->b_ind_maxparen);
+	    curwin->w_cursor = cursor_save;
+	    if (start_paren == NULL)
+		cached->start_of_decl = end_paren.lnum;
+	    else
+		cached->start_of_decl = start_paren->lnum;
+	}
+    }
+    else
+	cached->start_of_decl = 0;
+
     return cpp_base_class;
 }
 
@@ -7186,7 +7219,7 @@
     int		original_line_islabel;
     int		added_to_amount = 0;
     int		js_cur_has_key = 0;
-    cpp_baseclass_cache_T cache_cpp_baseclass = { FALSE, { MAXLNUM, 0 } };
+    cpp_baseclass_cache_T cache_cpp_baseclass = { FALSE, 0, { MAXLNUM, 0 } };
 
     /* make a copy, value is changed below */
     int		ind_continuation = curbuf->b_ind_continuation;
@@ -8255,6 +8288,12 @@
 		    }
 		    else if (theline[0] == '{')
 		    {
+			curwin->w_cursor.lnum
+					    = cache_cpp_baseclass.start_of_decl;
+			if (curbuf->b_ind_js)
+			    amount = get_indent();
+			else
+			    amount = skip_label(curwin->w_cursor.lnum, &l);
 			/* Need to find start of the declaration. */
 			lookfor = LOOKFOR_UNTERM;
 			ind_continuation = 0;
diff -r 7271fdea3884 src/testdir/test3.in
--- a/src/testdir/test3.in	Tue Sep 29 18:15:04 2015 +0200
+++ b/src/testdir/test3.in	Wed Oct 07 10:20:16 2015 +0900
@@ -910,6 +910,29 @@
     )foo";
      }
 
+class a {
+	public:
+		a()
+			: i(0)
+		{
+		}
+
+		a() : i(0)
+		{
+		}
+
+		Constructor(
+				int a,
+				int b,
+				int c
+				) : base(0)
+		{
+		}
+
+		a() : i(0) {
+		}
+};
+
 /* end of AUTO */
 
 STARTTEST
diff -r 7271fdea3884 src/testdir/test3.ok
--- a/src/testdir/test3.ok	Tue Sep 29 18:15:04 2015 +0200
+++ b/src/testdir/test3.ok	Wed Oct 07 10:20:16 2015 +0900
@@ -898,6 +898,29 @@
     )foo";
 }
 
+class a {
+	public:
+		a()
+			: i(0)
+		{
+		}
+
+		a() : i(0)
+		{
+		}
+
+		Constructor(
+				int a,
+				int b,
+				int c
+				) : base(0)
+		{
+		}
+
+		a() : i(0) {
+		}
+};
+
 /* end of AUTO */
 
 

Reply via email to