|
| 1 | +" NeoVim key binding for sphinxnotes-snippet |
| 2 | +" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3 | +" |
| 4 | +" :Author: Shengyu Zhang |
| 5 | +" :Date: 2021-11-14 |
| 6 | +" :Version: 20211114 |
| 7 | +" |
| 8 | +" TODO: Support vim? |
| 9 | + |
| 10 | +function! g:SphinxNotesSnippetListAndView() |
| 11 | + function! s:CallView(selection) |
| 12 | + call g:SphinxNotesSnippetView(s:SplitID(a:selection)) |
| 13 | + endfunction |
| 14 | + call g:SphinxNotesSnippetList(function('s:CallView'), 'ds') |
| 15 | +endfunction |
| 16 | + |
| 17 | +" https://github.com/anhmv/vim-float-window/blob/master/plugin/float-window.vim |
| 18 | +function! g:SphinxNotesSnippetView(id) |
| 19 | + let height = float2nr((&lines - 2) / 1.5) |
| 20 | + let row = float2nr((&lines - height) / 2) |
| 21 | + let width = float2nr(&columns / 1.5) |
| 22 | + let col = float2nr((&columns - width) / 2) |
| 23 | + |
| 24 | + " Main Window |
| 25 | + let opts = { |
| 26 | + \ 'relative': 'editor', |
| 27 | + \ 'style': 'minimal', |
| 28 | + \ 'width': width, |
| 29 | + \ 'height': height, |
| 30 | + \ 'col': col, |
| 31 | + \ 'row': row, |
| 32 | + \ } |
| 33 | + |
| 34 | + let buf = nvim_create_buf(v:false, v:true) |
| 35 | + " Global for :call |
| 36 | + let g:sphinx_notes_snippet_win = nvim_open_win(buf, v:true, opts) |
| 37 | + |
| 38 | + " The content is always reStructuredText for now |
| 39 | + set filetype=rst |
| 40 | + " Press enter to return |
| 41 | + nmap <buffer> <CR> :call nvim_win_close(g:sphinx_notes_snippet_win, v:true)<CR> |
| 42 | +
|
| 43 | + let cmd = [s:snippet, 'get', '--text', a:id] |
| 44 | + call append(line('$'), ['.. hint:: Press <ENTER> to return']) |
| 45 | + execute '$read !' . '..' |
| 46 | + execute '$read !' . join(cmd, ' ') |
| 47 | + execute '$read !' . '..' |
| 48 | + call append(line('$'), ['.. hint:: Press <ENTER> to return']) |
| 49 | +endfunction |
| 50 | + |
| 51 | +nmap <C-k>v :call g:SphinxNotesSnippetListAndView()<CR> |
| 52 | +
|
| 53 | +" vim: set shiftwidth=2: |
| 54 | +" vim: set ft=vim: |
0 commit comments