From f1a08584f579616031896049e5fa95ac64c9408c Mon Sep 17 00:00:00 2001 From: Dmitry Antonyuk <32649457+dantonyuk@users.noreply.github.com> Date: Wed, 3 Nov 2021 17:53:43 -0500 Subject: [PATCH] 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. --- README.md | 8 ++++++++ autoload/gist.vim | 28 ++++++++++++++++++++++++---- doc/gist-vim.txt | 6 ++++++ plugin/gist.vim | 5 +++-- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f2df1bb..06f049f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/autoload/gist.vim b/autoload/gist.vim index eea5584..67f2234 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -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' @@ -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 @@ -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 @@ -767,6 +769,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 @@ -794,6 +798,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' @@ -874,6 +886,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*$') @@ -910,7 +930,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 diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 88c46d1..2810b96 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -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". > @@ -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: > diff --git a/plugin/gist.vim b/plugin/gist.vim index 4d4efe6..46956a1 100644 --- a/plugin/gist.vim +++ b/plugin/gist.vim @@ -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(, "", , , ) " vim:set et: