Last active
February 6, 2019 18:12
-
-
Save ignamv/bc38c591b505085d14fe4b2fbee52629 to your computer and use it in GitHub Desktop.
Spectre line folding for Vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setlocal keywordprg=manspectre | |
setlocal foldmethod=expr | |
setlocal foldexpr=GetSpectreFold(v:lnum) | |
function! NextNonCommentLine(lnum) | |
let numlines = line('$') | |
let current = a:lnum + 1 | |
while current <= numlines | |
if getline(current) !~? '\v^\s*//' | |
return current | |
endif | |
let current += 1 | |
endwhile | |
return -1 | |
endfunction | |
function! LineContinues(lnum) | |
if getline(a:lnum) =~? '\v\\$' | |
return 1 | |
endif | |
let nextline = NextNonCommentLine(a:lnum) | |
if nextline != -1 | |
return getline(nextline) =~? '\v^\+' | |
endif | |
return 0 | |
endfunction | |
function! GetSpectreFold(lnum) | |
if getline(a:lnum) =~? '\v^\s*$' | |
return '=' | |
endif | |
if getline(a:lnum) =~? '\v^\s*(inline )?subckt' | |
return 'a1' | |
endif | |
if getline(a:lnum) =~? '\v^\s*ends' | |
return 's1' | |
endif | |
if getline(a:lnum) =~? '\v\s*\}.*\{\s*$' | |
return '=' | |
endif | |
if getline(a:lnum) =~? '\v\{\s*$' | |
return 'a1' | |
endif | |
if getline(a:lnum) =~? '\v^\s*\}' | |
return 's1' | |
endif | |
if LineContinues(a:lnum) && ! LineContinues(a:lnum-1) | |
return 'a1' | |
endif | |
if LineContinues(a:lnum-1) && ! LineContinues(a:lnum) | |
return 's1' | |
endif | |
return '=' | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment