~gpanders/dotfiles

b7152c83b47e3338b22f4068c518da48bba6791f — Gregory Anders 18 days ago f7edcc7
vim: replace zet plugin with wk

The wk Vim runtime files are part of the source repo, so include it as a
plugin in minpac. However, in order to get minpac to work with
subdirectories, the devel branch has to be used until [1] is merged.

[1]: https://github.com/k-takata/minpac/pull/99
3 files changed, 7 insertions(+), 93 deletions(-)

D .vim/autoload/zet.vim
M .vim/plugin/minpac.vim
D .vim/plugin/zet.vim
D .vim/autoload/zet.vim => .vim/autoload/zet.vim +0 -75
@@ 1,75 0,0 @@
function! zet#complete(findstart, base) abort
    let line = getline('.')
    if line =~# '^tags:'
        return s:compltag(line, a:findstart, a:base)
    else
        return s:compllink(line, a:findstart, a:base)
    endif
endfunction

function! s:zettels(base) abort
    let zettels = glob($ZETTEL_DIR . '/*.md', 0, 1)
    call map(zettels, 'fnamemodify(v:val, '':t'')')
    call filter(zettels, 'v:val =~# ''^\d\{14}'' && v:val =~? a:base')
    return zettels
endfunction

function! s:compltag(line, findstart, base) abort
    if a:findstart
        let start = col('.') - 1
        while start > 0 && a:line[start - 1] !~# '[, ]'
            let start -= 1
        endwhile
        if start == 0
            return -2
        endif
        return start
    else
        let zettels = s:zettels('')
        let alltags = []
        for zet in zettels
            let contents = readfile($ZETTEL_DIR . '/' . zet, 0, 5)
            let tags = split(matchstr(contents, '^tags:\s\+.\+$'), '^tags:\s\+')
            if empty(tags)
                continue
            endif

            call extend(alltags, split(tags[0], ', \?'))
        endfor

        call uniq(sort(alltags))

        let matches = []
        for tag in alltags
            if tag =~# a:base
                call add(matches, tag)
            endif
        endfor
        return matches
    endif
endfunction

function! s:compllink(line, findstart, base) abort
    if a:findstart
        let start = col('.') - 1
        while start > 0 && a:line[start - 2:start - 1] !=# '[['
            let start -= 1
        endwhile
        if start == 0
            return -2
        endif
        return start
    else
        let zettels = s:zettels(a:base)
        let matches = []
        for zet in zettels
            let contents = readfile($ZETTEL_DIR . '/' . zet, 0, 5)
            let title = split(matchstr(contents, '^title:\s\+.\+$'), '^title:\s\+')
            if !empty(title)
                let word = matchstr(zet, '^\d\+')
                call add(matches, {'word': word, 'menu': title[0]})
            endif
        endfor
        return matches
    endif
endfunction

M .vim/plugin/minpac.vim => .vim/plugin/minpac.vim +7 -1
@@ 12,7 12,10 @@ function! s:PackInit() abort
    endif

    call minpac#init()
    call minpac#add('k-takata/minpac', {'type': 'opt'})

    " Use devel branch until https://github.com/k-takata/minpac/pull/99 is
    " merged
    call minpac#add('k-takata/minpac', {'type': 'opt', 'branch': 'devel'})

    " Colorscheme
    call minpac#add('gpanders/base16-vim', {'type': 'opt'})


@@ 26,6 29,9 @@ function! s:PackInit() abort
    " Evaluate code blocks in Markdown buffers
    call minpac#add('gpanders/vim-medieval')

    " wk plugin
    call minpac#add('https://git.sr.ht/~gpanders/wk', {'subdir': 'contrib/vim'})

    " Git wrapper in vim
    call minpac#add('tpope/vim-fugitive')


D .vim/plugin/zet.vim => .vim/plugin/zet.vim +0 -17
@@ 1,17 0,0 @@
if exists('g:loaded_zet')
    finish
endif
let g:loaded_zet = 1

if empty($ZETTEL_DIR)
    if !empty($XDG_DATA_HOME)
        let $ZETTEL_DIR = $XDG_DATA_HOME . '/zet'
    else
        let $ZETTEL_DIR = $HOME . '/.local/share/zet'
    endif
endif

augroup plugin_zet
    autocmd!
    autocmd BufReadPost $ZETTEL_DIR/* setlocal include=\\[\\[\\zs\\d\\+\\ze]] includeexpr=glob($ZETTEL_DIR.'/'.v:fname.'*') omnifunc=zet#complete
augroup END