@@ -132,12 +132,23 @@ function! s:format_gist(gist) abort
132
132
else
133
133
let code = ' '
134
134
endif
135
- let desc = type (a: gist .description)== 0 || a: gist .description == # ' ' ? ' ' : ' ( ' . a: gist .description. ' ) '
135
+ let desc = type (a: gist .description)== 0 || a: gist .description == # ' ' ? ' ' : a: gist .description
136
136
let name = substitute (name, ' [\r\n\t]' , ' ' , ' g' )
137
137
let name = substitute (name, ' ' , ' ' , ' g' )
138
138
let desc = substitute (desc, ' [\r\n\t]' , ' ' , ' g' )
139
139
let desc = substitute (desc, ' ' , ' ' , ' g' )
140
- return printf (' gist: %s %s %s%s' , a: gist .id, name, desc, code)
140
+ " return printf('gist: %-32s %s %s%s', a:gist.id, name, desc, code)
141
+ " Display a nice formatted (and truncated if needed) table of gists on screen
142
+ " Calculate field lengths for gist-listing formatting on screen
143
+ redir = >a |exe " sil sign place buffer=" .bufnr (' ' )|redir end
144
+ let signlist = split (a , ' \n' )
145
+ let width = winwidth (0 ) - ((&number || &relativenumber ) ? &numberwidth : 0 ) - &foldcolumn - (len (signlist) > 2 ? 2 : 0 )
146
+ let s: gistlen = 33
147
+ if ! exists (" g:gist_namelength" )
148
+ let g: gist_namelength= 30
149
+ endif
150
+ let s: desclen = width- (s: gistlen+ g: gist_namelength+ 10 )
151
+ return printf (' gist: %-*s %-*s %-*s' , s: gistlen , a: gist .id, g: gist_namelength+ 1 , strpart (name, 0 , g: gist_namelength ), s: desclen+ 1 , strpart (desc, 0 , s: desclen ))
141
152
endfunction
142
153
143
154
" Note: A colon in the file name has side effects on Windows due to NTFS Alternate Data Streams; avoid it.
@@ -206,17 +217,38 @@ function! s:GistList(gistls, page) abort
206
217
let lines = map (filter (content, ' !empty(v:val.files)' ), ' s:format_gist(v:val)' )
207
218
call setline (1 , split (join (lines , " \n " ), " \n " ))
208
219
209
- $put = ' more...'
220
+ let numlines = line (' $' )
221
+ if numlines > 1
222
+ let plural= ' s'
223
+ else
224
+ let plural= ' '
225
+ endif
226
+ " $put='more...'.line('$').' gist'.plural.' shown.'
227
+ call append (0 , ' ' .a: gistls .' : ' .numlines.' gist' .plural)
228
+
229
+ if numlines+ 1 > 11
230
+ let listheight = 11
231
+ else
232
+ let listheight = numlines+ 1
233
+ endif
234
+ execute ' resize ' . listheight
210
235
211
236
let b: gistls = a: gistls
212
237
let b: page = a: page
213
238
setlocal buftype = nofile bufhidden = hide noswapfile
239
+ setlocal cursorline
214
240
setlocal nomodified
215
241
setlocal nomodifiable
216
- syntax match SpecialKey / ^gist:/ he =e - 1
242
+ syntax match SpecialKey / ^gist:/ he =e
217
243
syntax match Title / ^gist: \S\+ / hs =s + 5 contains =ALL
218
244
nnoremap <silent> <buffer> <cr> :call <SID> GistListAction(0)<cr>
219
- nnoremap <silent> <buffer> <s-cr> :call <SID> GistListAction(1)<cr>
245
+ nnoremap <silent> <buffer> o :call <SID> GistListAction(0)<cr>
246
+ nnoremap <silent> <buffer> b :call <SID> GistListAction(1)<cr>
247
+ nnoremap <silent> <buffer> y :call <SID> GistListAction(2)<cr>
248
+ nnoremap <silent> <buffer> p :call <SID> GistListAction(3)<cr>
249
+ nnoremap <silent> <buffer> <esc> :bw<cr>
250
+ " Next line (in original code) only works on GUI VIM
251
+ nnoremap <silent> <buffer> <s-cr> :call <SID> GistListAction(1)<cr>
220
252
221
253
cal cursor (1 + len (oldlines),1 )
222
254
nohlsearch
@@ -401,6 +433,7 @@ function! s:GistGet(gistid, clipboard) abort
401
433
endif
402
434
else
403
435
silent only !
436
+ " exec 'silent noautocmd edit'
404
437
if get (g: , ' gist_list_vsplit' , 0 )
405
438
exec ' silent noautocmd rightbelow vnew'
406
439
else
@@ -437,7 +470,8 @@ function! s:GistGet(gistid, clipboard) abort
437
470
return
438
471
endtry
439
472
let &undolevels = old_undolevels
440
- setlocal buftype = acwrite bufhidden = delete noswapfile
473
+ " setlocal buftype=acwrite bufhidden=delete noswapfile
474
+ setlocal buftype = acwrite bufhidden = hide noswapfile
441
475
setlocal nomodified
442
476
doau StdinReadPost ,BufRead ,BufReadPost
443
477
let gist_detect_filetype = get (g: , ' gist_detect_filetype' , 0 )
@@ -471,10 +505,22 @@ function! s:GistListAction(shift) abort
471
505
let mx = ' ^gist:\s*\zs\(\w\+\)\ze.*'
472
506
if line = ~# mx
473
507
let gistid = matchstr (line , mx)
474
- if a: shift
508
+ if a: shift == 1
475
509
call s: open_browser (' https://gist.github.com/' . gistid)
476
- else
510
+ elseif a: shift == 0
477
511
call s: GistGet (gistid, 0 )
512
+ wincmd w
513
+ " bdelete
514
+ bw
515
+ elseif a: shift == 2
516
+ call s: GistGet (gistid, 1 )
517
+ bdelete
518
+ bdelete
519
+ elseif a: shift == 3
520
+ call s: GistGet (gistid, 1 )
521
+ bdelete
522
+ bdelete
523
+ normal ! " +p
478
524
endif
479
525
return
480
526
endif
0 commit comments