Le mardi 6 juin 2017 21:48:12 UTC+2, Ni Va a écrit :
> Hi,
>
> With this kind of syntax:
>
>
> FUNCTION
>
> NETWORK
> foobar
> barfo
> foo
> bar
> NETWORK
> foobar
> barfo
> foo
> bar
>
> NETWORK
> foobar
> barfo
> foo
> bar
> END_FUNCTION
>
>
>
>
> I don't happen to foldlevel 1 FUNC END_FUNC and foldlevel 2 NETWORK section.
>
>
> I just happen to fold all in foldlevel one with this script :
>
> " folding
> setlocal foldmethod=expr
> setlocal foldexpr=GetFold(v:lnum)
>
> function! GetFold(lnum)
> let currentLine = getline(a:lnum)
> let nextLine = getline(a:lnum+1)
> if (currentLine =~? '\v^NETWORK') || (currentLine =~? '\v^FUNC')
> return '>1'
> endif
> if (nextLine =~? '\v^NETWORK') || (nextLine =~? '\v^END_FUNC')
> return '<1'
> endif
> return '1'
> endfunction
Ok it's done
" folding
setlocal foldmethod=expr
setlocal foldexpr=GetFold(v:lnum)
function! GetFold(lnum)
let currentLine = getline(a:lnum)
let nextLine = getline(a:lnum+1)
if (currentLine =~ '\v^FUNC')
\ || (currentLine =~ '\v^DATA')
\ || (currentLine =~ '\v^TYPE')
\ || (currentLine =~ '\v^ORGA')
return '>1'
elseif (currentLine =~ '\v^END_FUNC')
\ || (currentLine =~ '\v^END_DATA')
\ || (currentLine =~ '\v^END_TYPE')
\ || (currentLine =~ '\v^END_ORGA')
return '<1'
else
if (currentLine =~ '\v^NETWORK')
return '>2'
elseif (nextLine =~ '\v^NETWORK')
return '<2'
else
return '='
endif
return '='
endif
endfunction
Is it polssible to accelerate with another vimscript code strix or other alternative?
Thank you
--
--
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
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment