1- " NeoVim integration for sphinxnotes-snippet
2- " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1+ " Vim integration for sphinxnotes-snippet
2+ " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33"
44" :Author: Shengyu Zhang
55" :Date: 2021-04-01
6- " :Version: 20210413
6+ " :Version: 20210814
77"
88" NOTE: junegunn/fzf.vim is required
99
@@ -13,9 +13,9 @@ function! s:SplitID(row)
1313 return split (a: row , ' ' )[0 ]
1414endfunction
1515
16- function ! g: SphinxNotesSnippetList (callback, kinds )
16+ function ! g: SphinxNotesSnippetList (callback, tags )
1717 let cmd = [s: snippet , ' list' ,
18- \ ' --kinds ' , a: kinds ,
18+ \ ' --tags ' , a: tags ,
1919 \ ' --width' , &columns - 2 ,
2020 \ ]
2121 call fzf#run ({
@@ -25,72 +25,4 @@ function! g:SphinxNotesSnippetList(callback, kinds)
2525 \ })
2626endfunction
2727
28- function ! g: SphinxNotesSnippetListAndView ()
29- function ! s: CallView (selection )
30- call g: SphinxNotesSnippetView (s: SplitID (a: selection ))
31- endfunction
32- call g: SphinxNotesSnippetList (function (' s:CallView' ), ' ds' )
33- endfunction
34-
35- " https://github.com/anhmv/vim-float-window/blob/master/plugin/float-window.vim
36- function ! g: SphinxNotesSnippetView (id)
37- let height = float2nr ((&lines - 2 ) / 1.5 )
38- let row = float2nr ((&lines - height) / 2 )
39- let width = float2nr (&columns / 1.5 )
40- let col = float2nr ((&columns - width) / 2 )
41-
42- " Main Window
43- let opts = {
44- \ ' relative' : ' editor' ,
45- \ ' style' : ' minimal' ,
46- \ ' width' : width,
47- \ ' height' : height,
48- \ ' col' : col ,
49- \ ' row' : row,
50- \ }
51-
52- let buf = nvim_create_buf (v: false , v: true )
53- " Global for :call
54- let g: sphinx_notes_snippet_win = nvim_open_win (buf , v: true , opts)
55-
56- " The content is always reStructuredText for now
57- set filetype = rst
58- " Press enter to return
59- nmap <buffer> <CR> :call nvim_win_close(g:sphinx_notes_snippet_win, v:true)<CR>
60-
61- let cmd = [s: snippet , ' get' , ' --text' , a: id ]
62- execute ' $read !' . join (cmd, ' ' )
63- execute ' $read !' . ' ..'
64- call append (line (' $' ), [
65- \ ' .. Inserted By sphinxnotes-snippet:' ,
66- \ ' ' ,
67- \ ' Press <ENTER> to return' ])
68- endfunction
69-
70- function ! g: SphinxNotesSnippetEdit (id)
71- let cmd = [s: snippet , ' get' , ' --file' , a: id ]
72- execute ' $tabedit ' . system (join (cmd, ' ' ))
73- endfunction
74-
75- function ! g: SphinxNotesSnippetListAndEdit ()
76- function ! s: CallEdit (selection )
77- call g: SphinxNotesSnippetEdit (s: SplitID (a: selection ))
78- endfunction
79- call g: SphinxNotesSnippetList (function (' s:CallEdit' ), ' ds' )
80- endfunction
81-
82- function ! g: SphinxNotesSnippetUrl (id)
83- let cmd = [s: snippet , ' get' , ' --url' , a: id ]
84- for url in systemlist (join (cmd, ' ' ))
85- echo system (' xdg-open ' . shellescape (url))
86- endfor
87- endfunction
88-
89- function ! g: SphinxNotesSnippetListAndUrl ()
90- function ! s: CallUrl (selection )
91- call g: SphinxNotesSnippetUrl (s: SplitID (a: selection ))
92- endfunction
93- call g: SphinxNotesSnippetList (function (' s:CallUrl' ), ' ds' )
94- endfunction
95-
9628" vim: set shiftwidth = 2 :
0 commit comments