Loading ...
Sorry, an error occurred while loading the content.

[PATCH] New option: leftindent

Expand Messages
  • Michael Gold
    The attached patch for Vim 6.3 adds a new option called leftindent (short form li ). It is similar to preserveindent, but adds and removes indentation at
    Message 1 of 1 , Oct 1, 2005
    • 0 Attachment
      The attached patch for Vim 6.3 adds a new option called 'leftindent'
      (short form 'li'). It is similar to preserveindent, but adds and removes
      indentation at the far left end of the line rather than immediately
      before the first non-whitespace character. You can enter the following
      code in Vim to see my problem with preserveindent (use ":set noet pi
      ts=4 sw=4 sts=0"):

      function(a,
      b); // 9 spaces before b, aligning it with a

      If you use >> to indent all 3 lines, you'll get this (">--" is a tab):

      >---function(a,
      >-- b); // 9 spaces, a tab, and 1 space before b

      If you change the tab width (ts=3 for example) the letters no longer
      line up. I'd expect my code to display properly regardless of the tab
      width. With leftindent it does; this is the result:

      >---function(a,
      >--- b); // 1 tab and 9 spaces before b

      [ if you take this code and use << with the above :set line, you'll see
      a similar problem with unindenting - again, a and b won't line up when
      you change the tab width ]

      I always use shiftwidth == tabstop, but I've tried to make the code work
      when this isn't true (for example, with Vim's code which uses ts=8 sts=4
      sw=4). A possible issue is that >> would always insert some spaces, and
      these would build up with repeated indentation (and if sw < ts you'd
      never get a tab). leftindent will leave the spaces alone if you set
      preserveindent; otherwise it will convert between spaces and tabs,
      trying to maintain roughly the same number of spaces as before the
      indentation. preserveindent will have no other effects when leftindent
      is set.


      The patch creates a new function called left_indent in misc1.c, and
      modifies set_indent to call it when the leftindent option is set. It
      should be easy to see that no behaviour changes when this option is
      disabled.

      I developed and tested this patch with Vim 6.3, but it also applies to
      Vim 7 and seems to work fine.

      - Michael
    Your message has been successfully submitted and would be delivered to recipients shortly.