voom icon indicating copy to clipboard operation
voom copied to clipboard

Add support for opt folder

Open bharatvaj opened this issue 7 months ago • 3 comments

opt folder support would be a great addition for voom, as it vastly improves the vim startup time.

Currently the $PLUGINS_DIR defaults to $VIM_DIR/pack/voom/start and all the plugins are being installed here.

To use the opt folder, there is no available workarounds, as

# voom
26 MANIFEST="$VIM_DIR/plugins"

is set without checking the environment. I believe this can be fixed by making the following change,

MANIFEST="${MANIFEST:-$VIM_DIR/plugins}"

But that would mean that the user have to invoke voom twice in a rather cumbersome way,

$ voom
$ MANIFEST="$VIM_DIR/plugins-opt" PLUGINS_DIR="$VIM_DIR/pack/voom/opt" voom

On top of that, one has to list the plugins in a timer function like shown below in their vimrc to lazy load the plugins

func! s:load_plugins(t) abort
  packadd vim-commentary
  packadd vim-surround
  packadd vim-fugitive
  packadd vim-unimpaired
  packadd vim-better-whitespace
  packadd vim-dispatch
  packadd ctrlp.vim
  packadd conflict-marker.vim
  packaedd notmuch-vim

  " lazy loaded plugin's configuration goes here
  let g:notmuch_use_fzf = 1
  let g:notmuch_open_command = 'fzf'
  let g:notmuch_fzf_command = 'fzf --reverse'
  let g:notmuch_use_conversation_view = 1
  let sendmail_path = systemlist('sed -n "s/^set sendmail=\(.*\)$/\1/p; $!d" ~/.mailrc')
  if len(sendmail_path) > 0
      let g:notmuch_sendmail=sendmail_path[]
  endif
endfunc

aug lazyload_plugins
  au! | au VimEnter * call timer_start(20, function('s:load_plugins'))
aug END

Proposal

I want to suggest a simple approach,

# plugins
tpope/commentary.vim

[opt]
tpope/fugitive.vim

Which should produce the following tree,

$VIM_DIR/pack/voom/
    start/
     |  commentary.vim/
     |  voom.vim/
        |  autoload/
           |  voom.vim      <-- voom.vim can contain lazy loading logic
    opt/
     |  fugitive.vim/

Generating the autocmd timer function must be trivial from the shell.

# voom

_paths=$(ls $VIM_DIR/start/voom/opt | xargs -I {} echo packadd {})
mkdir -p $VIM_DIR/voom/start/voom.vim
echo "
func! s:voom_load_plugins(t) abort
  $(_paths)
  " TODO only call if the function exists or better throw a Vim event
  call g:voom_plugins_loaded()
endfunc

aug voom_opt_plugins
  au! | au VimEnter * call timer_start(20, function('s:voom_load_plugins'))
aug END
" >> $VIM_DIR/voom/start/voom.vim/autoload/voom.vim

Now voom.vim will be loaded by vim on startup, and call g:voom_plugins_loaded() which will be provided by the user,

" .vimrc
func! g:voom_plugins_loaded() abort
  " lazy loaded plugin's configuration goes here
  let g:notmuch_use_fzf = 1
  let g:notmuch_open_command = 'fzf'
  let g:notmuch_fzf_command = 'fzf --reverse'
  let g:notmuch_use_conversation_view = 1
  let sendmail_path = systemlist('sed -n "s/^set sendmail=\(.*\)$/\1/p; $!d" ~/.mailrc')
  if len(sendmail_path) > 0
      let g:notmuch_sendmail=sendmail_path[]
  endif
endfunc

bharatvaj avatar Jul 24 '25 13:07 bharatvaj