Skip to content

Commit

Permalink
Fix #27
Browse files Browse the repository at this point in the history
  • Loading branch information
subnut committed Jan 8, 2021
1 parent ccee999 commit 5ac775c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
9 changes: 3 additions & 6 deletions autoload/coiledsnake.vim
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,10 @@ function! coiledsnake#LoadSettings() abort "{{{1
endfunction

function! coiledsnake#EnableFoldText() abort "{{{1
let w:coiled_snake_saved_foldtext = &foldtext
let &foldtext = 'coiledsnake#FoldText()'
endfunction

function! coiledsnake#EnableFoldExpr() abort "{{{1
let w:coiled_snake_saved_foldexpr = &foldexpr
let w:coiled_snake_saved_foldmethod = &foldmethod
let &foldexpr = 'coiledsnake#FoldExpr(v:lnum)'
let &foldmethod = 'expr'
augroup CoiledSnake
Expand All @@ -185,12 +182,12 @@ function! coiledsnake#EnableFoldExpr() abort "{{{1
endfunction

function! coiledsnake#ResetFoldText() abort "{{{1
let &foldtext = get(w:, 'coiled_snake_saved_foldtext', &foldtext)
let &foldtext = &g:foldtext
endfunction

function! coiledsnake#ResetFoldExpr() abort "{{{1
let &foldexpr = get(w:, 'coiled_snake_saved_foldexpr', &foldexpr)
let &foldmethod = get(w:, 'coiled_snake_saved_foldmethod', &foldmethod)
let &foldexpr = &g:foldexpr
let &foldmethod = &g:foldmethod
augroup CoiledSnake
autocmd! TextChanged,InsertLeave <buffer>
augroup END
Expand Down
6 changes: 6 additions & 0 deletions ftplugin/python/coiledsnake.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if exists('b:coiled_snake_should_fold')
finish
endif
let b:coiled_snake_should_fold = 1

" vim: ts=4 sts=4 sw=4 fdm=marker et sr
20 changes: 10 additions & 10 deletions plugin/coiledsnake.vim
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
function! s:OnFileType() " {{{1
if ! get(b:, 'coiled_snake_bufenter', 0)
" Don't do anything before the buffer has been loaded.
function! s:OnBufEnter() " {{{1
if ! (exists('b:coiled_snake_should_fold') && b:coiled_snake_should_fold)
" not python
return
elseif &filetype != 'python' || &diff
" Don't do anything if this isn't a python file.
endif
if ! (&foldmethod ==# &g:foldmethod
\&& &foldexpr ==# &g:foldexpr
\&& &foldmethod ==# &g:foldmethod)
" something is not at default value. not safe to fold.
return
endif

Expand All @@ -17,20 +20,17 @@ function! s:OnFileType() " {{{1
endif
endfunction

function! s:OnBufEnter() " {{{1
let b:coiled_snake_bufenter = 1
call s:OnFileType()
endfunction

function! s:OnBufLeave() " {{{1
call coiledsnake#ResetFoldText()
call coiledsnake#ResetFoldExpr()
endfunction

augroup CoiledSnake " {{{1
autocmd!
autocmd FileType * call s:OnFileType()
autocmd BufEnter * call s:OnBufEnter()
autocmd BufLeave * call s:OnBufLeave()
augroup END
" }}}1

" vim: ts=4 sts=4 sw=4 fdm=marker et sr

0 comments on commit 5ac775c

Please sign in to comment.