pseewald / vim-anyfold

Language agnostic vim plugin for folding and motion based on indentation.
MIT License
268 stars 11 forks source link

[feature] add augroup #40

Closed Freed-Wu closed 3 years ago

Freed-Wu commented 3 years ago
" deprecated initialization using anyfold_activate variable
" still works but echoes a warning
au BufNewFile,BufRead * call anyfold#init(0)

First, this autocmd don't be included in an augroup, which make user cannot use autocmd! augroup_name to disable it.

Second, this autocmd make vim call this function when read or create a buffer, which means vim will source autoload/anyfold.vim. If we change it to (just move some lines from autoload function to plugin/anyfold.vim)

au BufNewFile,BufRead * call s:init()
function! s:init() abort
    if exists("g:anyfold_activate")
        let b:anyfold_activate = g:anyfold_activate
    endif

    if !exists("b:anyfold_activate")
        return
    elseif !b:anyfold_activate
        return
    endif
    call anyfold#init(1)
endfunction

Now, if g: or b:anyfold_activate don't exist, the autoload function anyfold#init will not be called, so autoload/anyfold.vim will not be sourced, it can save time of sourcing a script.

I think it will be better.

Thanks!

Freed-Wu commented 3 years ago

Sorry for repetition.