Skip to content

Commit

Permalink
feat(integration): Use <C-k>d to input docname in vim (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverRainZ authored Oct 13, 2024
1 parent 278f624 commit 264be70
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/sphinxnotes/snippet/integration/binding.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function! g:SphinxNotesSnippetEdit(id)
let file = system(join([s:snippet, 'get', '--file', a:id, '2>/dev/null'], ' '))
let line = system(join([s:snippet, 'get', '--line-start', a:id, '2>/dev/null'], ' '))
if &modified
execute 'tabedit ' . file
execute 'vsplit ' . file
else
execute 'edit ' . file
endif
Expand Down Expand Up @@ -38,7 +38,27 @@ function! g:SphinxNotesSnippetListAndUrl()
call g:SphinxNotesSnippetList(function('s:CallUrl'), 'ds')
endfunction

function! g:SphinxNotesSnippetInput(id, item)
let content = system(join([s:snippet, 'get', '--' . a:item, a:id, '2>/dev/null'], ' '))
let content = substitute(content, '\n\+$', '', '') " skip trailing \n
if a:item == 'docname'
" Create doc reference.
let content = ':doc:`/' . content . '`'
endif
execute 'normal! i' . content
endfunction

function! g:SphinxNotesSnippetListAndInputDocname()
function! s:InputDocname(selection)
call g:SphinxNotesSnippetInput(s:SplitID(a:selection), 'docname')
endfunction
call g:SphinxNotesSnippetList(function('s:InputDocname'), 'd')
endfunction

nmap <C-k>e :call g:SphinxNotesSnippetListAndEdit()<CR>
nmap <C-k>u :call g:SphinxNotesSnippetListAndUrl()<CR>
nmap <C-k>d :call g:SphinxNotesSnippetListAndInputDocname()<CR>
" FIXME: can't return to insert mode even use a/startinsert!/C-o
imap <C-k>d <C-o>:call g:SphinxNotesSnippetListAndInputDocname()<CR>
" vim: set shiftwidth=2:

0 comments on commit 264be70

Please sign in to comment.