Skip to content

Manage per-page limit while listing #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ For the latest version please see https://github.com/mattn/vim-gist.

:Gist -l mattn

- Specify the number of gists listed:

:Gist -l -n 100

- List everyone's gists.

:Gist -la
Expand Down Expand Up @@ -188,6 +192,10 @@ You need to either set global git config:

$ git config --global github.user Username

If you want to list more than 30 gists per page (maximum is 100):

let g:gist_per_page_limit = 100

## License:

Copyright 2010 by Yasuhiro Matsumoto
Expand Down
28 changes: 24 additions & 4 deletions autoload/gist.vim
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ endfunction

" Note: A colon in the file name has side effects on Windows due to NTFS Alternate Data Streams; avoid it.
let s:bufprefix = 'gist' . (has('unix') ? ':' : '_')
function! s:GistList(gistls, page) abort
function! s:GistList(gistls, page, pagelimit) abort
if a:gistls ==# '-all'
let url = g:gist_api_url.'gists/public'
elseif get(g:, 'gist_show_privates', 0) && a:gistls ==# 'starred'
Expand All @@ -196,9 +196,11 @@ function! s:GistList(gistls, page) abort
exec 'silent noautocmd split' s:bufprefix.a:gistls
endif
endif

let url = url . '?per_page=' . a:pagelimit
if a:page > 1
let oldlines = getline(0, line('$'))
let url = url . '?page=' . a:page
let url = url . '&page=' . a:page
endif

setlocal modifiable
Expand Down Expand Up @@ -527,7 +529,7 @@ function! s:GistListAction(mode) abort
return
endif
if line =~# '^more\.\.\.$'
call s:GistList(b:gistls, b:page+1)
call s:GistList(b:gistls, b:page+1, g:gist_per_page_limit)
return
endif
endfunction
Expand Down Expand Up @@ -761,6 +763,8 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
let editpost = 0
let anonymous = get(g:, 'gist_post_anonymous', 0)
let openbrowser = 0
let setpagelimit = 0
let pagelimit = g:gist_per_page_limit
let listmx = '^\%(-l\|--list\)\s*\([^\s]\+\)\?$'
let bufnamemx = '^' . s:bufprefix .'\(\zs[0-9a-f]\+\ze\|\zs[0-9a-f]\+\ze[/\\].*\)$'
if strlen(g:github_user) == 0 && anonymous == 0
Expand Down Expand Up @@ -788,6 +792,14 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
elseif arg =~# '^\(-G\|--gitclone\)$\C' && gistidbuf !=# '' && g:gist_api_url ==# 'https://api.github.com/' && has_key(b:, 'gist') && has_key(b:gist, 'id')
exe '!' printf('git clone git@github.com:%s', b:gist['id'])
return
elseif setpagelimit == 1
let setpagelimit = 0
let pagelimit = str2nr(arg)
if pagelimit < 1 || pagelimit > 100
echohl ErrorMsg | echomsg 'Page limit should be between 1 and 100: '.arg | echohl None
unlet args
return 0
endif
elseif arg =~# '^\(-la\|--listall\)$\C'
let gistls = '-all'
elseif arg =~# '^\(-ls\|--liststar\)$\C'
Expand Down Expand Up @@ -868,6 +880,14 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
endif
elseif arg =~# '^\(-b\|--browser\)$\C'
let openbrowser = 1
elseif arg =~# '^\(-n\|--per-page\)$\C'
if len(gistls) > 0
let setpagelimit = 1
else
echohl ErrorMsg | echomsg 'Page limit can be set only for list commands'.arg | echohl None
unlet args
return 0
endif
elseif arg !~# '^-' && len(gistnm) == 0
if gistdesc !=# ' '
let gistdesc = matchstr(arg, '^\s*\zs.*\ze\s*$')
Expand Down Expand Up @@ -904,7 +924,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
endif

if len(gistls) > 0
call s:GistList(gistls, 1)
call s:GistList(gistls, 1, pagelimit)
elseif len(gistid) > 0 && editpost == 0 && deletepost == 0
call s:GistGet(gistid, clipboard)
else
Expand Down
6 changes: 6 additions & 0 deletions doc/gist-vim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ USAGE *:Gist* *vim-gist-usage*

:Gist -l
:Gist --list
:Gist -l -n 100
:Gist --list --per-page 100
<
- List gists from user "mattn". >

Expand Down Expand Up @@ -201,6 +203,10 @@ If you want to open gist list/buffer as vertical split: >

let g:gist_list_vsplit = 1

If you want to list more than 30 gists per page (maximum is 100):

let g:gist_per_page_limit = 100

If you want to modify filetype for the file on github, or add mapping of
filetype/file-extension: >

Expand Down
5 changes: 3 additions & 2 deletions plugin/gist.vim
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ endif
let g:loaded_gist_vim = 1

function! s:CompleteArgs(arg_lead,cmdline,cursor_pos)
return filter(copy(["-p", "-P", "-a", "-m", "-e", "-s", "-d", "+1", "-1", "-f", "-c", "-l", "-la", "-ls", "-b",
return filter(copy(["-p", "-P", "-a", "-m", "-e", "-s", "-d", "+1", "-1", "-f", "-c", "-l", "-la", "-ls", "-b", "-n",
\ "--listall", "--liststar", "--list", "--multibuffer", "--private", "--public", "--anonymous", "--description", "--clipboard",
\ "--rawurl", "--delete", "--edit", "--star", "--unstar", "--fork", "--browser"
\ "--rawurl", "--delete", "--edit", "--star", "--unstar", "--fork", "--browser", "--per-page"
\ ]), 'stridx(v:val, a:arg_lead)==0')
endfunction

let g:gist_per_page_limit = get(g:, 'gist_per_page_limit', 30)
command! -nargs=? -range=% -bang -complete=customlist,s:CompleteArgs Gist :call gist#Gist(<count>, "<bang>", <line1>, <line2>, <f-args>)

" vim:set et: