Skip to content

Commit f1a0858

Browse files
dantonyukallex
authored andcommitted
Manage per-page limit while listing
Control how many gists we're going to get during list commands. Two ways introduced: 1. Global variable `g:gist_per_page_limit` which is 30 by default. Set it to the value that will be used as a default number of gists per page in list commands. 2. Specify the number of gists for any list command explicitly `-n` or `--per-page` option: ``` :Gist -l -n 100 :Gist --list --per-page 100 ``` Note that the page limit could not exceed 100 and should be a positive number.
1 parent 04dbb9a commit f1a0858

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ For the latest version please see https://github.com/mattn/vim-gist.
8787

8888
:Gist -l mattn
8989

90+
- Specify the number of gists listed:
91+
92+
:Gist -l -n 100
93+
9094
- List everyone's gists.
9195

9296
:Gist -la
@@ -188,6 +192,10 @@ You need to either set global git config:
188192

189193
$ git config --global github.user Username
190194

195+
If you want to list more than 30 gists per page (maximum is 100):
196+
197+
let g:gist_per_page_limit = 100
198+
191199
## License:
192200

193201
Copyright 2010 by Yasuhiro Matsumoto

autoload/gist.vim

+24-4
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ endfunction
171171

172172
" Note: A colon in the file name has side effects on Windows due to NTFS Alternate Data Streams; avoid it.
173173
let s:bufprefix = 'gist' . (has('unix') ? ':' : '_')
174-
function! s:GistList(gistls, page) abort
174+
function! s:GistList(gistls, page, pagelimit) abort
175175
if a:gistls ==# '-all'
176176
let url = g:gist_api_url.'gists/public'
177177
elseif get(g:, 'gist_show_privates', 0) && a:gistls ==# 'starred'
@@ -196,9 +196,11 @@ function! s:GistList(gistls, page) abort
196196
exec 'silent noautocmd split' s:bufprefix.a:gistls
197197
endif
198198
endif
199+
200+
let url = url . '?per_page=' . a:pagelimit
199201
if a:page > 1
200202
let oldlines = getline(0, line('$'))
201-
let url = url . '?page=' . a:page
203+
let url = url . '&page=' . a:page
202204
endif
203205

204206
setlocal modifiable
@@ -527,7 +529,7 @@ function! s:GistListAction(mode) abort
527529
return
528530
endif
529531
if line =~# '^more\.\.\.$'
530-
call s:GistList(b:gistls, b:page+1)
532+
call s:GistList(b:gistls, b:page+1, g:gist_per_page_limit)
531533
return
532534
endif
533535
endfunction
@@ -767,6 +769,8 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
767769
let editpost = 0
768770
let anonymous = get(g:, 'gist_post_anonymous', 0)
769771
let openbrowser = 0
772+
let setpagelimit = 0
773+
let pagelimit = g:gist_per_page_limit
770774
let listmx = '^\%(-l\|--list\)\s*\([^\s]\+\)\?$'
771775
let bufnamemx = '^' . s:bufprefix .'\(\zs[0-9a-f]\+\ze\|\zs[0-9a-f]\+\ze[/\\].*\)$'
772776
if strlen(g:github_user) == 0 && anonymous == 0
@@ -794,6 +798,14 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
794798
elseif arg =~# '^\(-G\|--gitclone\)$\C' && gistidbuf !=# '' && g:gist_api_url ==# 'https://api.github.com/' && has_key(b:, 'gist') && has_key(b:gist, 'id')
795799
exe '!' printf('git clone [email protected]:%s', b:gist['id'])
796800
return
801+
elseif setpagelimit == 1
802+
let setpagelimit = 0
803+
let pagelimit = str2nr(arg)
804+
if pagelimit < 1 || pagelimit > 100
805+
echohl ErrorMsg | echomsg 'Page limit should be between 1 and 100: '.arg | echohl None
806+
unlet args
807+
return 0
808+
endif
797809
elseif arg =~# '^\(-la\|--listall\)$\C'
798810
let gistls = '-all'
799811
elseif arg =~# '^\(-ls\|--liststar\)$\C'
@@ -874,6 +886,14 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
874886
endif
875887
elseif arg =~# '^\(-b\|--browser\)$\C'
876888
let openbrowser = 1
889+
elseif arg =~# '^\(-n\|--per-page\)$\C'
890+
if len(gistls) > 0
891+
let setpagelimit = 1
892+
else
893+
echohl ErrorMsg | echomsg 'Page limit can be set only for list commands'.arg | echohl None
894+
unlet args
895+
return 0
896+
endif
877897
elseif arg !~# '^-' && len(gistnm) == 0
878898
if gistdesc !=# ' '
879899
let gistdesc = matchstr(arg, '^\s*\zs.*\ze\s*$')
@@ -910,7 +930,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
910930
endif
911931

912932
if len(gistls) > 0
913-
call s:GistList(gistls, 1)
933+
call s:GistList(gistls, 1, pagelimit)
914934
elseif len(gistid) > 0 && editpost == 0 && deletepost == 0
915935
call s:GistGet(gistid, clipboard)
916936
else

doc/gist-vim.txt

+6
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ USAGE *:Gist* *vim-gist-usage*
102102
103103
:Gist -l
104104
:Gist --list
105+
:Gist -l -n 100
106+
:Gist --list --per-page 100
105107
<
106108
- List gists from user "mattn". >
107109
@@ -201,6 +203,10 @@ If you want to open gist list/buffer as vertical split: >
201203
202204
let g:gist_list_vsplit = 1
203205
206+
If you want to list more than 30 gists per page (maximum is 100):
207+
208+
let g:gist_per_page_limit = 100
209+
204210
If you want to modify filetype for the file on github, or add mapping of
205211
filetype/file-extension: >
206212

plugin/gist.vim

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ endif
1212
let g:loaded_gist_vim = 1
1313

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

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

2324
" vim:set et:

0 commit comments

Comments
 (0)