On Jan 12, 9:44 am, Ben Fritz <[email protected]> wrote:
> This is what I have for C files, but I did it long enough ago that I
> cannot for the life of me remember what it is for or how it works
> without studying it for a while. It may be helpful as a starting
> point, but no guarantees:
>
> ==============$HOME/vimfiles/after/indent/c.vim===================
> " special indenting (indent to the unmatched paren or bracket)
> " autoload only supported in version 7 and above
> if v:version>=701
>   let s:comment_text = '^\s*\*.*\|//.*\|/\*\%(\%(\*/\)\...@!.\)*'
>   let &l:indentexpr="max([".(&indentexpr ? &indentexpr : -1).",
> indent#OpenBracketAlign('".s:comment_text."')])"
>   unlet s:comment_text
> endif
>
> " cindent will use these values to do parenthesis-alignment.
> setlocal cinoptions+=(0
> setlocal cinoptions+=W2s
>
> ==============$HOME/vimfiles/autoload/indent.vim==================
> " align the indent just after the last unclosed paren in the line
> above,
> " unless that parenthesis is contained in a comment.
> "
> " pass in a pattern to match text to be treated as a comment
> function! indent#OpenParenAlign(comment_text)
>   let aboveLineNum=line('.')-1
>   if aboveLineNum < 1
>     return -1
>   else
>     " remove parentheses from comment text (keeping line the same
> length)
>     let aboveLine=getline(aboveLineNum)
>     let aboveLine=
>           \ substitute(aboveLine,
>           \            a:comment_text,
>           \            substitute(submatch(0), '[()]', 'x', 'g'),
>           \            'g')
>
>     " remove all matched parentheses from the line (keeping same line
> length)
>     let aboveLineOld=aboveLine
>     let aboveLine=substitute(aboveLineOld,'(\([^()]*\))','x\1x','g')
>     while aboveLine!=aboveLineOld
>       let aboveLineOld=aboveLine
>       let aboveLine=substitute(aboveLineOld,'(\([^()]*\))','x\1x','g')
>     endwhile
>
>     " find position of last opening paren in the line - indent will be
> just
>     " after this if it exists
>     let parenPos=match(aboveLine,'([^(]*$')
>     if parenPos==-1
>       if &cindent
>         return cindent('.')
>       else
>         return -1
>       endif
>     else
>       return parenPos+1
>     endif
>   endif
> endfunction
>
> " align the indent just after the last unclosed square bracket in the
> line above
> " unless that parenthesis is contained in a comment.
> "
> " pass in a pattern to match text to be treated as a comment
> function! indent#OpenBracketAlign(comment_text)
>   let aboveLineNum=line('.')-1
>   if aboveLineNum < 1
>     return -1
>   else
>     " remove brackets from comment text (keeping line the same length)
>     let aboveLine=getline(aboveLineNum)
>     let aboveLine=
>           \ substitute(aboveLine,
>           \            a:comment_text,
>           \            substitute(submatch(0), '[][])]', 'x', 'g'),
>           \            'g')
>
>     " remove all matched brackets from the line (keeping same line
> length)
>     let aboveLineOld=aboveLine
>     let aboveLine=substitute(aboveLineOld,'\[\([^[\]]*\)\]','x
> \1x','g')
>     while aboveLine!=aboveLineOld
>       let aboveLineOld=aboveLine
>       let aboveLine=substitute(aboveLineOld,'\[\([^[\]]*\)\]','x
> \1x','g')
>     endwhile
>
>     " find position of last opening bracket in the line - indent will
> be just
>     " after this if it exists
>     let bracketPos=match(aboveLine,'\[[^[]*$')
>     if bracketPos==-1
>       if &cindent
>         return cindent('.')
>       else
>         return -1
>       endif
>     else
>       return bracketPos+1
>     endif
>   endif
> endfunction

I should mention:

This will NOT be a drop-in solution for you, it is for a different
file type, and solves an entirely different problem (one that I don't
even remember having, it's been in my config for so long). I included
it as an example of the method that you may be able to expand on and
possibly borrow some technique. I vaguely remember crafting this when
I wanted similar indent for array indices like this:

    if (NULL != biglongarrayname[4 * (somevar + othervar) /
anotherbigvarname]
                                [(CONST_VAL << varshift) &
BIG_LONG_MASK_NAME_TAKING_UP_SPACE])
        dosomething();
-- 
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

Reply via email to