On 19-Feb-2010 Manuel König <[email protected]> wrote:
> Sorry, there was a bug in my previous patch that shouldn't have slipped
> my eyes, I forgot to add 'break;' in a switch structure... It's fixed
> now.

I have tested the patch: it works. The source code seems fine. There was
a slight mistake in the documentation (the option is referred to as L in
the example). I'm attaching a patch with the original source code and
updated documentation.

-- 
Cheers,
Lech

-- 
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
diff --git a/runtime/doc/indent.txt b/runtime/doc/indent.txt
index 4d00da2..2e31273 100644
--- a/runtime/doc/indent.txt
+++ b/runtime/doc/indent.txt
@@ -216,6 +216,21 @@ assume a 'shiftwidth' of 4.
 		      }			}		  }
 		  }		      }			  }
 <
+	JN    Controls placement of jump labels. If N equals -1, the label will
+	      be placed at column 1. If N is non-negative, the indent of the
+	      label will be that of a normal statement minus N. All other values
+	      for N are invalid and the default value will be used instead.
+	      (default -1).
+
+		cino=               cino=J2             cino=Js >
+		  func()              func()              func()
+		  {                   {                   {
+		      {                   {                   {
+		          stmt;               stmt;               stmt;
+		  LABEL:                    LABEL:            LABEL:
+		      }                   }                   }
+		  }                   }                   }
+<
 	:N    Place case labels N characters from the indent of the switch().
 	      (default 'shiftwidth').
 
@@ -446,13 +461,14 @@ assume a 'shiftwidth' of 4.
 
 
 The defaults, spelled out in full, are:
-	cinoptions=>s,e0,n0,f0,{0,}0,^0,:s,=s,l0,b0,gs,hs,ps,ts,is,+s,c3,C0,
+	cinoptions=>s,e0,n0,f0,{0,}0,^0,J-1,:s,=s,l0,b0,gs,hs,ps,ts,is,+s,c3,C0,
 		   /0,(2s,us,U0,w0,W0,m0,j0,)20,*30,#0
 
 Vim puts a line in column 1 if:
 - It starts with '#' (preprocessor directives), if 'cinkeys' contains '#'.
 - It starts with a label (a keyword followed by ':', other than "case" and
-  "default").
+  "default"), if 'cinoptions' does not contain JN for a non-negative value
+  of N.
 - Any combination of indentations causes the line to have less than 0
   indentation.
 
diff --git a/src/misc1.c b/src/misc1.c
index 6b6f339..418f7a8 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -6035,6 +6035,12 @@ get_c_indent()
     int ind_open_left_imag = 0;
 
     /*
+     * spaces jump labels should be shifted to the left if N is non-negative,
+     * otherwise the jump label will be put to column 1.
+     */
+    int ind_jump_label = -1;
+
+    /*
      * spaces from the switch() indent a "case xx" label should be located
      */
     int ind_case = curbuf->b_p_sw;
@@ -6245,6 +6251,7 @@ get_c_indent()
 	    case '{': ind_open_extra = n; break;
 	    case '}': ind_close_extra = n; break;
 	    case '^': ind_open_left_imag = n; break;
+	    case 'J': ind_jump_label = n; break;
 	    case ':': ind_case = n; break;
 	    case '=': ind_case_code = n; break;
 	    case 'b': ind_case_break = n; break;
@@ -6300,6 +6307,8 @@ get_c_indent()
 
     curwin->w_cursor.col = 0;
 
+    int original_line_islabel = cin_islabel(ind_maxcomment);
+
     /*
      * #defines and so on always go at the left when included in 'cinkeys'.
      */
@@ -6309,9 +6318,9 @@ get_c_indent()
     }
 
     /*
-     * Is it a non-case label?	Then that goes at the left margin too.
+     * put jump labels to the left if not configured otherwise.
      */
-    else if (cin_islabel(ind_maxcomment))	    /* XXX */
+    else if (ind_jump_label < 0 && original_line_islabel)	    /* XXX */
     {
 	amount = 0;
     }
@@ -7929,6 +7938,11 @@ term_again:
     }
 
 theend:
+    // QUESTION: Is this the right place to shift jump labels?
+    /* add extra left-shift for jump labels */
+    if (ind_jump_label > 0 && original_line_islabel)
+	amount -= ind_jump_label;
+
     /* put the cursor back where it belongs */
     curwin->w_cursor = cur_curpos;
 

Raspunde prin e-mail lui