Hi all,

this is my first post here and my first patch for vim (and any other
open source project in general), and I'm new to these diff/patch tools,
so please tell me if there's something wrong or room for improvement. I
created the patch by doing

$cd vim7
$diff -c src/misc1.c my/vim7/src/misc1.c > misc.diff
$diff -c runtime/doc/indent.txt my/vim7/runtime/doc/indent.txt >
indent.diff
$cat indent.diff misc.diff > cino_jump_labels.diff

and successfully applied it by doing

$cd vim7
$patch -c -p0 <cino_jump_labels.diff

Copied from the description I added to cinoption-values:

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=L2             cino=Ls >
          func()              func()              func()
          {                   {                   {
              {                   {                   {
                  stmt;               stmt;               stmt;
          LABEL:                    LABEL:            LABEL:
              }                   }                   }
          }                   }                   }

I declared values of N < -1 as invalid because that allows adding new
options in the future, like N=-2 to lign up jump labels with the
current innermost function (some languages allow nested functions,
therefore "innermost").

Advantages:
* Use cino+=J0 to not break up with foldmethod=indent
* Still possible to visually distinguish labels by using
  something like cino+=Js or cino+=J0.5s. This also doesn't
  break up with foldmethod=indent so severely as if the label
  were at column 1.
* When working with highly indendet code, it can be hard to
  track for the eye to which line of code a label belongs to
  if it's located at column 1

Disadvantages:
* Adds one more entry to cinoptions the user may have to read
  before he finds what he wants to have. But still better than
  reading through all options just to find out in the second last
  point that placement of jump labels is not supported, as it was
  the case for me ;)

I still have some questions that need to be resolved before folding
this patch into vim:

(Q1) All code examples in :help cinoptions-values have a mixed use of
normal spaces and tabs, so that the examples break up if I set tabstop
to something different than 8. In my code example I used tabs to indent
the beginning of the code, and then only used spaces. Is that a
documentation bug or is it expected that tabstop==8 for helpfiles?

(Q2) The text in cinoptions-values uses both column 0 and column 1 for
the "first" column. It should be agreed up on a consistent naming, I
prefer column 1 because there really is no such thing as column 0, only
a char array that's indexed starting at 0.

(Q3) In the file src/misc1.c I'm not sure if I placed the code that
actually performs the label shifting at the right place. You can find
that code by doing 'grep QUESTION' on the patched misc1.c. I admit that
I haven't read all the code above that's responsible for indenting
and would appreciate any help of someone who is knowledgeable with that
portion of code.

I'm not sure if the following is expected to be correct behaviour:

:set tabstop=8
:set cindent
:set cino=J4

/*
 * The next label is still indented at column 8, but it
 * should be at column 4. Admittedly such code doesn't
 * make much sense, but it still smells like a bug.
 *
 * But that also doesn't work in the current version of
 * vim if I don't apply my patch (ie. this label won't be
 * put to column 1), so it's probably OK. The reason is
 * that such labels won't even be recognized as labels
 * by cin_islabel(ind_maxcomment).
 */
if (blah)
        LABEL:
if (asdf)
        stmt;

Thank's for your time :)

-- 
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
*** runtime/doc/indent.txt	2010-02-15 16:09:45.980505930 +0100
--- ../../vim7/runtime/doc/indent.txt	2010-02-15 14:57:34.001429987 +0100
***************
*** 216,221 ****
--- 216,236 ----
  		      }			}		  }
  		  }		      }			  }
  <
+ 	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=L2             cino=Ls >
+ 		  func()              func()              func()
+ 		  {                   {                   {
+ 		      {                   {                   {
+ 		          stmt;               stmt;               stmt;
+ 		  LABEL:                    LABEL:            LABEL:
+ 		      }                   }                   }
+ 		  }                   }                   }
+ <
  	:N    Place case labels N characters from the indent of the switch().
  	      (default 'shiftwidth').
  
***************
*** 446,458 ****
  
  
  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,
  		   /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").
  - Any combination of indentations causes the line to have less than 0
    indentation.
  
--- 461,474 ----
  
  
  The defaults, spelled out in full, are:
! 	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"), 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.
  
*** src/misc1.c	2010-02-15 16:10:12.127169873 +0100
--- ../../vim7/src/misc1.c	2010-02-15 16:17:59.963790082 +0100
***************
*** 6035,6040 ****
--- 6035,6046 ----
      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,6250 ****
--- 6251,6257 ----
  	    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;
  	    case ':': ind_case = n; break;
  	    case '=': ind_case_code = n; break;
  	    case 'b': ind_case_break = n; break;
***************
*** 6300,6305 ****
--- 6307,6314 ----
  
      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,6317 ****
      }
  
      /*
!      * Is it a non-case label?	Then that goes at the left margin too.
       */
!     else if (cin_islabel(ind_maxcomment))	    /* XXX */
      {
  	amount = 0;
      }
--- 6318,6326 ----
      }
  
      /*
!      * put jump labels to the left if not configured otherwise.
       */
!     else if (ind_jump_label < 0 && original_line_islabel)	    /* XXX */
      {
  	amount = 0;
      }
***************
*** 7929,7934 ****
--- 7938,7948 ----
      }
  
  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