hecal3 / vim-leader-guide

294 stars 21 forks source link

Bug/Regression with autocommand #39

Open ctjhoa opened 7 years ago

ctjhoa commented 7 years ago

Hi,

A few months ago, I notice a bug with vim-leader-guide (https://github.com/ctjhoa/spacevim/issues/32) and I didn't take the time to look at it until now.

Here is what I've found. With the current version of vim-leader-guide calling register_prefix_description from an autocommand will lead to a bug where the name of your entry does not show. If I rollback to the commit bade1b9dfc5e56aaf322791fff11e350fd8681ae it works as intended.

I did a .vimrc which show the issue:

call plug#begin('~/.vim/plugged')

Plug 'hecal3/vim-leader-guide'

call plug#end()

let mapleader = ' '
let g:leaderGuide_vertical = 1

" THIS WORKS
" ==========
" call leaderGuide#register_prefix_descriptions("<Space>", "g:lmap")
" nnoremap <silent> <leader> :<c-u>LeaderGuide '<Space>'<CR>
" vnoremap <silent> <leader> :<c-u>LeaderGuideVisual '<Space>'<CR>
" ==========

" THIS DON'T
" ==========
function! s:vim_enter()
        call leaderGuide#register_prefix_descriptions("<Space>", "g:lmap")
        nnoremap <silent> <leader> :<c-u>LeaderGuide '<Space>'<CR>
        vnoremap <silent> <leader> :<c-u>LeaderGuideVisual '<Space>'<CR>
endfunction

augroup delayed
  autocmd!
  autocmd VimEnter * call s:vim_enter()
augroup END
" ==========

let g:lmap = get(g:, 'lmap', {})
let g:lmap.a = { 'name': '+applications' }

Thanks

hecal3 commented 5 years ago

This is probably a bit late for you, but for completion's sake:

If the plugin is unable to find a configuration dictionary on startup it will initialise an empty one:

if !leaderGuide#has_configuration()
    let g:leaderGuide_map = {}
    call leaderGuide#register_prefix_descriptions('', 'g:leaderGuide_map')
endif

The autocmd is apparently executed after this little snippet.

It's possible to hook the g:lmap dictionary into the top-level one like this:

function! s:vim_enter()
        let g:leaderGuide_map[' '] = g:lmap
        " registering is no longer necessary
        "call leaderGuide#register_prefix_descriptions("<Space>", "g:lmap")
        nnoremap <silent> <leader> :<c-u>LeaderGuide '<Space>'<CR>
        vnoremap <silent> <leader> :<c-u>LeaderGuideVisual '<Space>'<CR>
endfunction

augroup delayed
  autocmd!
  autocmd VimEnter * call s:vim_enter()
augroup END