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

foldtext indentation: problem with mix of spaces and tabs

Expand Messages
  • fkater@googlemail.com
    I try to keep the foldtext (the visible line if something is folded) indented the same like the unfolded first line. So I keep the overall indentation
    Message 1 of 2 , Mar 6, 2012
    • 0 Attachment
      I try to keep the foldtext (the visible line if something is folded)
      indented the same like the unfolded first line. So I keep the overall
      indentation regardless if parts get interrupted by 'foldtext'.

      For tabsize of 4 I do it like this:

      foldtext=repeat(' ',indent(v:foldstart)-indent(v:foldstart)/
      4).getline(v:foldstart)


      However, sometimes the indentation is done by *spaces* instead of
      tabs. So I can't use the above formula.

      So I would have to count spaces and tabs separately etc...I haven't
      got a clue how to find out dynamically how many spaces to insert...
      Anyone?

      Felix

      --
      You received this message from the "vim_use" 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
    • Ben Fritz
      On Mar 6, 7:04 am, fka...@googlemail.com ... It looks like you re subtracting off the indent already in the line (returned by
      Message 2 of 2 , Mar 6, 2012
      • 0 Attachment
        On Mar 6, 7:04 am, "fka...@..." <fka...@...>
        wrote:
        > I try to keep the foldtext (the visible line if something is folded)
        > indented the same like the unfolded first line. So I keep the overall
        > indentation regardless if parts get interrupted by 'foldtext'.
        >
        > For tabsize of 4 I do it like this:
        >
        > foldtext=repeat(' ',indent(v:foldstart)-indent(v:foldstart)/
        > 4).getline(v:foldstart)
        >
        > However, sometimes the indentation is done by *spaces* instead of
        > tabs. So I can't use the above formula.
        >
        > So I would have to count spaces and tabs separately etc...I haven't
        > got a clue how to find out dynamically how many spaces to insert...
        > Anyone?
        >

        It looks like you're subtracting off the indent already in the line
        (returned by getline()) by assuming they are tabs of width 4, which
        then get replaced with a single space by Vim when executing your
        foldtext expression.

        Since indent() already gives you the proper indent of the line, why
        not just replace the leading whitespace, and forget about subtracting
        off its width?

        You could probably do it easiest with indent():

        substitute(getline(v:foldstart), '^\s\+', repeat("
        ",indent(v:foldstart)), '')

        I ended up doing it in my own foldtext with
        strdisplaywidth(submatch(0)) in a similar substitute call.

        --
        You received this message from the "vim_use" 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
      Your message has been successfully submitted and would be delivered to recipients shortly.