@@ -132,12 +132,23 @@ function! s:format_gist(gist) abort
132132 else 
133133 let  code =  ' ' 
134134 endif 
135-  let  desc =  type (a: gist== 0  ||  a: gist== # ' ' ' ' ' ( ' . a: gist. ' ) ' 
135+  let  desc =  type (a: gist== 0  ||  a: gist== # ' ' ' ' a: gist
136136 let  name =  substitute (name, ' [\r\n\t]' '  ' ' g' 
137137 let  name =  substitute (name, '  ' '  ' ' g' 
138138 let  desc =  substitute (desc, ' [\r\n\t]' '  ' ' g' 
139139 let  desc =  substitute (desc, '  ' '  ' ' g' 
140-  return  printf (' gist: %s %s %s%s' a: gist
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: gistlena: gistg: gist_namelength+ 1 , strpart (name, 0 , g: gist_namelengths: desclen+ 1 , strpart (desc, 0 , s: desclen
141152endfunction 
142153
143154"  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
206217 let  lines  =  map (filter (content, ' !empty(v:val.files)' ' s:format_gist(v:val)' 
207218 call  setline (1 , split (join (lines , " \n " " \n " 
208219
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' : ' '  gist' 
228+ 229+  if  numlines+ 1  >  11 
230+  let  listheight =  11 
231+  else 
232+  let  listheight =  numlines+ 1 
233+  endif 
234+  execute  ' resize ' 
210235
211236 let  b: gistls=  a: gistls
212237 let  b: page=  a: page
213238 setlocal  buftype = nofile bufhidden = hide  noswapfile 
239+  setlocal  cursorline 
214240 setlocal  nomodified 
215241 setlocal  nomodifiable 
216-  syntax  match  SpecialKey  / ^gist:/ he =e - 1 
242+  syntax  match  SpecialKey  / ^gist:/ he =e 
217243 syntax  match  Title  / ^gist: \S\+ / hs =s + 5  contains =ALL 
218244 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>  
220252
221253 cal  cursor (1 + len (oldlines),1 )
222254 nohlsearch 
@@ -401,6 +433,7 @@ function! s:GistGet(gistid, clipboard) abort
401433 endif 
402434 else 
403435 silent  only ! 
436+  "  exec 'silent noautocmd edit' 
404437 if  get (g: ' gist_list_vsplit' 0 )
405438 exec  ' silent noautocmd rightbelow vnew' 
406439 else 
@@ -437,7 +470,8 @@ function! s:GistGet(gistid, clipboard) abort
437470 return 
438471 endtry 
439472 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 
441475 setlocal  nomodified 
442476 doau  StdinReadPost ,BufRead ,BufReadPost 
443477 let  gist_detect_filetype =  get (g: ' gist_detect_filetype' 0 )
@@ -471,10 +505,22 @@ function! s:GistListAction(shift) abort
471505 let  mx =  ' ^gist:\s*\zs\(\w\+\)\ze.*' 
472506 if  line  = ~# mx
473507 let  gistid =  matchstr (line , mx)
474-  if  a: shift
508+  if  a: shift== 1 
475509 call  s: open_browser' https://gist.github.com/' 
476-  else 
510+  elseif a: shift == 0 
477511 call  s: GistGet0 )
512+  wincmd  w 
513+  "  bdelete 
514+  bw 
515+  elseif  a: shift==  2  
516+  call  s: GistGet1 )
517+  bdelete 
518+  bdelete 
519+  elseif  a: shift==  3 
520+  call  s: GistGet1 )
521+  bdelete 
522+  bdelete 
523+  normal !  " +p 
478524 endif 
479525 return 
480526 endif 
0 commit comments