1
0
Fork 0
mirror of synced 2024-12-25 00:03:20 -05:00

Update vim-gist.

This commit is contained in:
Kurtis Moxley 2022-05-19 22:00:33 +08:00
parent 7747765240
commit f219991e20
10 changed files with 303 additions and 547 deletions

View file

@ -1,11 +0,0 @@
all : gist-vim.zip
remove-zip:
-rm -f doc/tags
-rm -f gist-vim.zip
gist-vim.zip: remove-zip
zip -r gist-vim.zip autoload plugin doc README.mkd
release: gist-vim.zip
vimup update-script gist.vim

View file

@ -2,7 +2,7 @@
This is a vimscript for creating gists (http://gist.github.com). This is a vimscript for creating gists (http://gist.github.com).
For the latest version please see https://github.com/mattn/gist-vim. For the latest version please see https://github.com/mattn/vim-gist.
## Usage: ## Usage:
@ -87,6 +87,10 @@ For the latest version please see https://github.com/mattn/gist-vim.
:Gist -l mattn :Gist -l mattn
- Specify the number of gists listed:
:Gist -l -n 100
- List everyone's gists. - List everyone's gists.
:Gist -la :Gist -la
@ -103,14 +107,14 @@ For the latest version please see https://github.com/mattn/gist-vim.
- Useful mappings on the gist-listing buffer: - Useful mappings on the gist-listing buffer:
- Both `o` or `Enter` open the gist file in a new buffer, and close the - Both `o` or `Enter` open the gist file in a new buffer, and close the
gist-vim listing one. vim-gist listing one.
- `b` opens the gist file in a browser; this is necessary because - `b` opens the gist file in a browser; this is necessary because
`Shift-Enter` (as was originally) only works for GUI vim. `Shift-Enter` (as was originally) only works for GUI vim.
- `y` copies the contents of the selected gist to the clipboard, and - `y` copies the contents of the selected gist to the clipboard, and
closes the gist-vim buffer. closes the vim-gist buffer.
- `p` pastes the contents of the selected gist to the buffer from where - `p` pastes the contents of the selected gist to the buffer from where
gist-vim was called, and closes the gist-vim buffer. vim-gist was called, and closes the vim-gist buffer.
- Hitting `Escape` or `Tab` at the gist-vim buffer closes it. - Hitting `Escape` or `Tab` at the vim-gist buffer closes it.
- Gist listing has fixed-length columns now, more amenable to eye inspection. - Gist listing has fixed-length columns now, more amenable to eye inspection.
Every line on the gist-listing buffer contains the gist id, name and Every line on the gist-listing buffer contains the gist id, name and
@ -188,6 +192,10 @@ You need to either set global git config:
$ git config --global github.user Username $ 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: ## License:
Copyright 2010 by Yasuhiro Matsumoto Copyright 2010 by Yasuhiro Matsumoto
@ -237,7 +245,7 @@ If you want to use latest one:
Add the following lines to your `.vimrc`. Add the following lines to your `.vimrc`.
Bundle 'mattn/webapi-vim' Bundle 'mattn/webapi-vim'
Bundle 'mattn/gist-vim' Bundle 'mattn/vim-gist'
Now restart Vim and run `:BundleInstall`. Now restart Vim and run `:BundleInstall`.
@ -245,7 +253,7 @@ Now restart Vim and run `:BundleInstall`.
Add the following line to your `.vimrc`. Add the following line to your `.vimrc`.
NeoBundle 'mattn/gist-vim', {'depends': 'mattn/webapi-vim'} NeoBundle 'mattn/vim-gist', {'depends': 'mattn/webapi-vim'}
## Requirements: ## Requirements:
@ -262,15 +270,15 @@ First, you need to set your GitHub username in git's global configuration:
$ git config --global github.user <username> $ git config --global github.user <username>
Then gist-vim will ask for your password in order to create an access Then vim-gist will ask for your password in order to create an access
token. If you have two-factor authentication enabled, gist-vim will also token. If you have two-factor authentication enabled, vim-gist will also
prompt you to enter the two-factor key you receive. prompt you to enter the two-factor key you receive.
NOTE: NOTE:
If you want you can set it directly to `g:github_user` and `g:gist_token`. If you want you can set it directly to `g:github_user` and `g:gist_token`.
Whichever type of authentication you use, your GitHub password will not be Whichever type of authentication you use, your GitHub password will not be
stored, only a OAuth access token produced specifically for gist-vim. The stored, only a OAuth access token produced specifically for vim-gist. The
token is stored in `~/.gist-vim`. If you stop using the plugin, you can token is stored in `~/.gist-vim`. If you stop using the plugin, you can
easily remove this file. To revoke the associated GitHub token, go to the easily remove this file. To revoke the associated GitHub token, go to the
list of ["Authorized applications" on GitHub's "Account Settings" list of ["Authorized applications" on GitHub's "Account Settings"

View file

@ -3,7 +3,7 @@
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com> " Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
" Last Change: 10-Oct-2016. " Last Change: 10-Oct-2016.
" Version: 7.3 " Version: 7.3
" WebPage: http://github.com/mattn/gist-vim " WebPage: http://github.com/mattn/vim-gist
" License: BSD " License: BSD
let s:save_cpo = &cpoptions let s:save_cpo = &cpoptions
@ -134,7 +134,7 @@ function! s:truncate(str, num)
let str = substitute(str, mx_first, '\2', '') let str = substitute(str, mx_first, '\2', '')
endwhile endwhile
while width + 1 <= a:num while width + 1 <= a:num
let ret .= " " let ret .= ' '
let width = width + 1 let width = width + 1
endwhile endwhile
return ret return ret
@ -160,7 +160,7 @@ function! s:format_gist(gist) abort
let desc = substitute(desc, ' ', ' ', 'g') let desc = substitute(desc, ' ', ' ', 'g')
" Display a nice formatted (and truncated if needed) table of gists on screen " Display a nice formatted (and truncated if needed) table of gists on screen
" Calculate field lengths for gist-listing formatting on screen " Calculate field lengths for gist-listing formatting on screen
redir =>a |exe "sil sign place buffer=".bufnr('')|redir end redir =>a |exe 'sil sign place buffer='.bufnr('')|redir end
let signlist = split(a, '\n') let signlist = split(a, '\n')
let width = winwidth(0) - ((&number||&relativenumber) ? &numberwidth : 0) - &foldcolumn - (len(signlist) > 2 ? 2 : 0) let width = winwidth(0) - ((&number||&relativenumber) ? &numberwidth : 0) - &foldcolumn - (len(signlist) > 2 ? 2 : 0)
let idlen = 33 let idlen = 33
@ -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. " 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') ? ':' : '_') let s:bufprefix = 'gist' . (has('unix') ? ':' : '_')
function! s:GistList(gistls, page) abort function! s:GistList(gistls, page, pagelimit) abort
if a:gistls ==# '-all' if a:gistls ==# '-all'
let url = g:gist_api_url.'gists/public' let url = g:gist_api_url.'gists/public'
elseif get(g:, 'gist_show_privates', 0) && a:gistls ==# 'starred' 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 exec 'silent noautocmd split' s:bufprefix.a:gistls
endif endif
endif endif
let url = url . '?per_page=' . a:pagelimit
if a:page > 1 if a:page > 1
let oldlines = getline(0, line('$')) let oldlines = getline(0, line('$'))
let url = url . '?page=' . a:page let url = url . '&page=' . a:page
endif endif
setlocal modifiable setlocal modifiable
@ -214,7 +216,7 @@ function! s:GistList(gistls, page) abort
echohl ErrorMsg | echomsg v:errmsg | echohl None echohl ErrorMsg | echomsg v:errmsg | echohl None
return return
endif endif
let res = webapi#http#get(url, '', { "Authorization": auth }) let res = webapi#http#get(url, '', { 'Authorization': auth })
if v:shell_error != 0 if v:shell_error != 0
bw! bw!
redraw redraw
@ -330,7 +332,7 @@ function! gist#list(user, ...) abort
if len(auth) == 0 if len(auth) == 0
return [] return []
endif endif
let res = webapi#http#get(url, '', { "Authorization": auth }) let res = webapi#http#get(url, '', { 'Authorization': auth })
return webapi#json#decode(res.content) return webapi#json#decode(res.content)
endfunction endfunction
@ -339,7 +341,7 @@ function! s:GistGetFileName(gistid) abort
if len(auth) == 0 if len(auth) == 0
return '' return ''
endif endif
let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { "Authorization": auth }) let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { 'Authorization': auth })
let gist = webapi#json#decode(res.content) let gist = webapi#json#decode(res.content)
if has_key(gist, 'files') if has_key(gist, 'files')
return sort(keys(gist.files))[0] return sort(keys(gist.files))[0]
@ -352,7 +354,7 @@ function! s:GistDetectFiletype(gistid) abort
if len(auth) == 0 if len(auth) == 0
return '' return ''
endif endif
let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { "Authorization": auth }) let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { 'Authorization': auth })
let gist = webapi#json#decode(res.content) let gist = webapi#json#decode(res.content)
let filename = sort(keys(gist.files))[0] let filename = sort(keys(gist.files))[0]
let ext = fnamemodify(filename, ':e') let ext = fnamemodify(filename, ':e')
@ -380,7 +382,7 @@ endfunction
function! s:GistGet(gistid, clipboard) abort function! s:GistGet(gistid, clipboard) abort
redraw | echon 'Getting gist... ' redraw | echon 'Getting gist... '
let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { "Authorization": s:GistGetAuthHeader() }) let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { 'Authorization': s:GistGetAuthHeader() })
if res.status =~# '^2' if res.status =~# '^2'
try try
let gist = webapi#json#decode(res.content) let gist = webapi#json#decode(res.content)
@ -459,10 +461,10 @@ function! s:GistGet(gistid, clipboard) abort
let content = gist.files[filename].content let content = gist.files[filename].content
call setline(1, split(content, "\n")) call setline(1, split(content, "\n"))
let b:gist = { let b:gist = {
\ "filename": filename, \ 'filename': filename,
\ "id": gist.id, \ 'id': gist.id,
\ "description": gist.description, \ 'description': gist.description,
\ "private": gist.public =~ 'true', \ 'private': gist.public =~# 'true',
\} \}
catch catch
let &undolevels = old_undolevels let &undolevels = old_undolevels
@ -527,16 +529,16 @@ function! s:GistListAction(mode) abort
return return
endif endif
if line =~# '^more\.\.\.$' 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 return
endif endif
endfunction endfunction
function! s:GistUpdate(content, gistid, gistnm, desc) abort function! s:GistUpdate(content, gistid, gistnm, desc) abort
let gist = { "id": a:gistid, "files" : {}, "description": "","public": function('webapi#json#true') } let gist = { 'id': a:gistid, 'files' : {}, 'description': '','public': function('webapi#json#true') }
if exists('b:gist') if exists('b:gist')
if has_key(b:gist, 'filename') && len(a:gistnm) > 0 if has_key(b:gist, 'filename') && len(a:gistnm) > 0
let gist.files[b:gist.filename] = { "content": '', "filename": b:gist.filename } let gist.files[b:gist.filename] = { 'content': '', 'filename': b:gist.filename }
let b:gist.filename = a:gistnm let b:gist.filename = a:gistnm
endif endif
if has_key(b:gist, 'private') && b:gist.private | let gist['public'] = function('webapi#json#false') | endif if has_key(b:gist, 'private') && b:gist.private | let gist['public'] = function('webapi#json#false') | endif
@ -560,25 +562,25 @@ function! s:GistUpdate(content, gistid, gistnm, desc) abort
if a:desc !=# ' ' if a:desc !=# ' '
let gist['description'] = a:desc let gist['description'] = a:desc
else else
let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { "Authorization": auth }) let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { 'Authorization': auth })
if res.status =~# '^2' if res.status =~# '^2'
let old_gist = webapi#json#decode(res.content) let old_gist = webapi#json#decode(res.content)
let gist['description'] = old_gist.description let gist['description'] = old_gist.description
endif endif
endif endif
let gist.files[filename] = { "content": a:content, "filename": filename } let gist.files[filename] = { 'content': a:content, 'filename': filename }
redraw | echon 'Updating gist... ' redraw | echon 'Updating gist... '
let res = webapi#http#post(g:gist_api_url.'gists/' . a:gistid, let res = webapi#http#post(g:gist_api_url.'gists/' . a:gistid,
\ webapi#json#encode(gist), { \ webapi#json#encode(gist), {
\ "Authorization": auth, \ 'Authorization': auth,
\ "Content-Type": "application/json", \ 'Content-Type': 'application/json',
\}) \})
if res.status =~# '^2' if res.status =~# '^2'
let obj = webapi#json#decode(res.content) let obj = webapi#json#decode(res.content)
let loc = obj['html_url'] let loc = obj['html_url']
let b:gist = {"id": a:gistid, "filename": filename} let b:gist = {'id': a:gistid, 'filename': filename}
setlocal nomodified setlocal nomodified
redraw | echomsg 'Done: '.loc redraw | echomsg 'Done: '.loc
else else
@ -598,8 +600,8 @@ function! s:GistDelete(gistid) abort
redraw | echon 'Deleting gist... ' redraw | echon 'Deleting gist... '
let res = webapi#http#post(g:gist_api_url.'gists/'.a:gistid, '', { let res = webapi#http#post(g:gist_api_url.'gists/'.a:gistid, '', {
\ "Authorization": auth, \ 'Authorization': auth,
\ "Content-Type": "application/json", \ 'Content-Type': 'application/json',
\}, 'DELETE') \}, 'DELETE')
if res.status =~# '^2' if res.status =~# '^2'
if exists('b:gist') if exists('b:gist')
@ -651,13 +653,13 @@ endfunction
" GistID: 123123 " GistID: 123123
" "
function! s:GistPost(content, private, desc, anonymous) abort function! s:GistPost(content, private, desc, anonymous) abort
let gist = { "files" : {}, "description": "","public": function('webapi#json#true') } let gist = { 'files' : {}, 'description': '','public': function('webapi#json#true') }
if a:desc !=# ' ' | let gist['description'] = a:desc | endif if a:desc !=# ' ' | let gist['description'] = a:desc | endif
if a:private | let gist['public'] = function('webapi#json#false') | endif if a:private | let gist['public'] = function('webapi#json#false') | endif
let filename = s:get_current_filename(1) let filename = s:get_current_filename(1)
let gist.files[filename] = { "content": a:content, "filename": filename } let gist.files[filename] = { 'content': a:content, 'filename': filename }
let header = {"Content-Type": "application/json"} let header = {'Content-Type': 'application/json'}
if !a:anonymous if !a:anonymous
let auth = s:GistGetAuthHeader() let auth = s:GistGetAuthHeader()
if len(auth) == 0 if len(auth) == 0
@ -674,10 +676,10 @@ function! s:GistPost(content, private, desc, anonymous) abort
let obj = webapi#json#decode(res.content) let obj = webapi#json#decode(res.content)
let loc = obj['html_url'] let loc = obj['html_url']
let b:gist = { let b:gist = {
\ "filename": filename, \ 'filename': filename,
\ "id": matchstr(loc, '[^/]\+$'), \ 'id': matchstr(loc, '[^/]\+$'),
\ "description": gist['description'], \ 'description': gist['description'],
\ "private": a:private, \ 'private': a:private,
\} \}
if s:update_GistID(b:gist['id']) if s:update_GistID(b:gist['id'])
Gist -e Gist -e
@ -695,7 +697,7 @@ function! s:GistPostBuffers(private, desc, anonymous) abort
let bn = bufnr('%') let bn = bufnr('%')
let query = [] let query = []
let gist = { "files" : {}, "description": "","public": function('webapi#json#true') } let gist = { 'files' : {}, 'description': '','public': function('webapi#json#true') }
if a:desc !=# ' ' | let gist['description'] = a:desc | endif if a:desc !=# ' ' | let gist['description'] = a:desc | endif
if a:private | let gist['public'] = function('webapi#json#false') | endif if a:private | let gist['public'] = function('webapi#json#false') | endif
@ -708,12 +710,12 @@ function! s:GistPostBuffers(private, desc, anonymous) abort
silent! exec 'buffer!' bufnr silent! exec 'buffer!' bufnr
let content = join(getline(1, line('$')), "\n") let content = join(getline(1, line('$')), "\n")
let filename = s:get_current_filename(index) let filename = s:get_current_filename(index)
let gist.files[filename] = { "content": content, "filename": filename } let gist.files[filename] = { 'content': content, 'filename': filename }
let index = index + 1 let index = index + 1
endfor endfor
silent! exec 'buffer!' bn silent! exec 'buffer!' bn
let header = {"Content-Type": "application/json"} let header = {'Content-Type': 'application/json'}
if !a:anonymous if !a:anonymous
let auth = s:GistGetAuthHeader() let auth = s:GistGetAuthHeader()
if len(auth) == 0 if len(auth) == 0
@ -730,10 +732,10 @@ function! s:GistPostBuffers(private, desc, anonymous) abort
let obj = webapi#json#decode(res.content) let obj = webapi#json#decode(res.content)
let loc = obj['html_url'] let loc = obj['html_url']
let b:gist = { let b:gist = {
\ "filename": filename, \ 'filename': filename,
\ "id": matchstr(loc, '[^/]\+$'), \ 'id': matchstr(loc, '[^/]\+$'),
\ "description": gist['description'], \ 'description': gist['description'],
\ "private": a:private, \ 'private': a:private,
\} \}
if s:update_GistID(b:gist['id']) if s:update_GistID(b:gist['id'])
Gist -e Gist -e
@ -761,10 +763,12 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
let editpost = 0 let editpost = 0
let anonymous = get(g:, 'gist_post_anonymous', 0) let anonymous = get(g:, 'gist_post_anonymous', 0)
let openbrowser = 0 let openbrowser = 0
let setpagelimit = 0
let pagelimit = g:gist_per_page_limit
let listmx = '^\%(-l\|--list\)\s*\([^\s]\+\)\?$' let listmx = '^\%(-l\|--list\)\s*\([^\s]\+\)\?$'
let bufnamemx = '^' . s:bufprefix .'\(\zs[0-9a-f]\+\ze\|\zs[0-9a-f]\+\ze[/\\].*\)$' let bufnamemx = '^' . s:bufprefix .'\(\zs[0-9a-f]\+\ze\|\zs[0-9a-f]\+\ze[/\\].*\)$'
if strlen(g:github_user) == 0 && anonymous == 0 if strlen(g:github_user) == 0 && anonymous == 0
echohl ErrorMsg | echomsg 'You have not configured a Github account. Read '':help gist-vim-setup''.' | echohl None echohl ErrorMsg | echomsg 'You have not configured a Github account. Read '':help gist-setup''.' | echohl None
return return
endif endif
if a:bang == '!' if a:bang == '!'
@ -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') 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']) exe '!' printf('git clone git@github.com:%s', b:gist['id'])
return 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' elseif arg =~# '^\(-la\|--listall\)$\C'
let gistls = '-all' let gistls = '-all'
elseif arg =~# '^\(-ls\|--liststar\)$\C' elseif arg =~# '^\(-ls\|--liststar\)$\C'
@ -828,7 +840,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
echohl ErrorMsg | echomsg v:errmsg | echohl None echohl ErrorMsg | echomsg v:errmsg | echohl None
else else
let gistid = gistidbuf let gistid = gistidbuf
let res = webapi#http#post(g:gist_api_url.'gists/'.gistid.'/star', '', { "Authorization": auth }, 'PUT') let res = webapi#http#post(g:gist_api_url.'gists/'.gistid.'/star', '', { 'Authorization': auth }, 'PUT')
if res.status =~# '^2' if res.status =~# '^2'
echomsg 'Starred' gistid echomsg 'Starred' gistid
else else
@ -842,7 +854,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
echohl ErrorMsg | echomsg v:errmsg | echohl None echohl ErrorMsg | echomsg v:errmsg | echohl None
else else
let gistid = gistidbuf let gistid = gistidbuf
let res = webapi#http#post(g:gist_api_url.'gists/'.gistid.'/star', '', { "Authorization": auth }, 'DELETE') let res = webapi#http#post(g:gist_api_url.'gists/'.gistid.'/star', '', { 'Authorization': auth }, 'DELETE')
if res.status =~# '^2' if res.status =~# '^2'
echomsg 'Unstarred' gistid echomsg 'Unstarred' gistid
else else
@ -857,7 +869,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
return return
else else
let gistid = gistidbuf let gistid = gistidbuf
let res = webapi#http#post(g:gist_api_url.'gists/'.gistid.'/fork', '', { "Authorization": auth }) let res = webapi#http#post(g:gist_api_url.'gists/'.gistid.'/fork', '', { 'Authorization': auth })
if res.status =~# '^2' if res.status =~# '^2'
let obj = webapi#json#decode(res.content) let obj = webapi#json#decode(res.content)
let gistid = obj['id'] let gistid = obj['id']
@ -868,6 +880,14 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
endif endif
elseif arg =~# '^\(-b\|--browser\)$\C' elseif arg =~# '^\(-b\|--browser\)$\C'
let openbrowser = 1 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 elseif arg !~# '^-' && len(gistnm) == 0
if gistdesc !=# ' ' if gistdesc !=# ' '
let gistdesc = matchstr(arg, '^\s*\zs.*\ze\s*$') let gistdesc = matchstr(arg, '^\s*\zs.*\ze\s*$')
@ -904,7 +924,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
endif endif
if len(gistls) > 0 if len(gistls) > 0
call s:GistList(gistls, 1) call s:GistList(gistls, 1, pagelimit)
elseif len(gistid) > 0 && editpost == 0 && deletepost == 0 elseif len(gistid) > 0 && editpost == 0 && deletepost == 0
call s:GistGet(gistid, clipboard) call s:GistGet(gistid, clipboard)
else else
@ -986,12 +1006,12 @@ function! s:GistGetAuthHeader() abort
let note_url = 'http://www.vim.org/scripts/script.php?script_id=2423' let note_url = 'http://www.vim.org/scripts/script.php?script_id=2423'
let insecureSecret = printf('basic %s', webapi#base64#b64encode(g:github_user.':'.password)) let insecureSecret = printf('basic %s', webapi#base64#b64encode(g:github_user.':'.password))
let res = webapi#http#post(g:gist_api_url.'authorizations', webapi#json#encode({ let res = webapi#http#post(g:gist_api_url.'authorizations', webapi#json#encode({
\ "scopes" : ["gist"], \ 'scopes' : ['gist'],
\ "note" : note, \ 'note' : note,
\ "note_url" : note_url, \ 'note_url' : note_url,
\}), { \}), {
\ "Content-Type" : "application/json", \ 'Content-Type' : 'application/json',
\ "Authorization" : insecureSecret, \ 'Authorization' : insecureSecret,
\}) \})
let h = filter(res.header, 'stridx(v:val, "X-GitHub-OTP:") == 0') let h = filter(res.header, 'stridx(v:val, "X-GitHub-OTP:") == 0')
if len(h) if len(h)
@ -1001,13 +1021,13 @@ function! s:GistGetAuthHeader() abort
return '' return ''
endif endif
let res = webapi#http#post(g:gist_api_url.'authorizations', webapi#json#encode({ let res = webapi#http#post(g:gist_api_url.'authorizations', webapi#json#encode({
\ "scopes" : ["gist"], \ 'scopes' : ['gist'],
\ "note" : note, \ 'note' : note,
\ "note_url" : note_url, \ 'note_url' : note_url,
\}), { \}), {
\ "Content-Type" : "application/json", \ 'Content-Type' : 'application/json',
\ "Authorization" : insecureSecret, \ 'Authorization' : insecureSecret,
\ "X-GitHub-OTP" : otp, \ 'X-GitHub-OTP' : otp,
\}) \})
endif endif
let authorization = webapi#json#decode(res.content) let authorization = webapi#json#decode(res.content)
@ -1025,138 +1045,138 @@ function! s:GistGetAuthHeader() abort
endfunction endfunction
let s:extmap = extend({ let s:extmap = extend({
\".adb": "ada", \'.adb': 'ada',
\".ahk": "ahk", \'.ahk': 'ahk',
\".arc": "arc", \'.arc': 'arc',
\".as": "actionscript", \'.as': 'actionscript',
\".asm": "asm", \'.asm': 'asm',
\".asp": "asp", \'.asp': 'asp',
\".aw": "php", \'.aw': 'php',
\".b": "b", \'.b': 'b',
\".bat": "bat", \'.bat': 'bat',
\".befunge": "befunge", \'.befunge': 'befunge',
\".bmx": "bmx", \'.bmx': 'bmx',
\".boo": "boo", \'.boo': 'boo',
\".c-objdump": "c-objdump", \'.c-objdump': 'c-objdump',
\".c": "c", \'.c': 'c',
\".cfg": "cfg", \'.cfg': 'cfg',
\".cfm": "cfm", \'.cfm': 'cfm',
\".ck": "ck", \'.ck': 'ck',
\".cl": "cl", \'.cl': 'cl',
\".clj": "clj", \'.clj': 'clj',
\".cmake": "cmake", \'.cmake': 'cmake',
\".coffee": "coffee", \'.coffee': 'coffee',
\".cpp": "cpp", \'.cpp': 'cpp',
\".cppobjdump": "cppobjdump", \'.cppobjdump': 'cppobjdump',
\".cs": "csharp", \'.cs': 'csharp',
\".css": "css", \'.css': 'css',
\".cw": "cw", \'.cw': 'cw',
\".d-objdump": "d-objdump", \'.d-objdump': 'd-objdump',
\".d": "d", \'.d': 'd',
\".darcspatch": "darcspatch", \'.darcspatch': 'darcspatch',
\".diff": "diff", \'.diff': 'diff',
\".duby": "duby", \'.duby': 'duby',
\".dylan": "dylan", \'.dylan': 'dylan',
\".e": "e", \'.e': 'e',
\".ebuild": "ebuild", \'.ebuild': 'ebuild',
\".eclass": "eclass", \'.eclass': 'eclass',
\".el": "lisp", \'.el': 'lisp',
\".erb": "erb", \'.erb': 'erb',
\".erl": "erlang", \'.erl': 'erlang',
\".f90": "f90", \'.f90': 'f90',
\".factor": "factor", \'.factor': 'factor',
\".feature": "feature", \'.feature': 'feature',
\".fs": "fs", \'.fs': 'fs',
\".fy": "fy", \'.fy': 'fy',
\".go": "go", \'.go': 'go',
\".groovy": "groovy", \'.groovy': 'groovy',
\".gs": "gs", \'.gs': 'gs',
\".gsp": "gsp", \'.gsp': 'gsp',
\".haml": "haml", \'.haml': 'haml',
\".hs": "haskell", \'.hs': 'haskell',
\".html": "html", \'.html': 'html',
\".hx": "hx", \'.hx': 'hx',
\".ik": "ik", \'.ik': 'ik',
\".ino": "ino", \'.ino': 'ino',
\".io": "io", \'.io': 'io',
\".j": "j", \'.j': 'j',
\".java": "java", \'.java': 'java',
\".js": "javascript", \'.js': 'javascript',
\".json": "json", \'.json': 'json',
\".jsp": "jsp", \'.jsp': 'jsp',
\".kid": "kid", \'.kid': 'kid',
\".lhs": "lhs", \'.lhs': 'lhs',
\".lisp": "lisp", \'.lisp': 'lisp',
\".ll": "ll", \'.ll': 'll',
\".lua": "lua", \'.lua': 'lua',
\".ly": "ly", \'.ly': 'ly',
\".m": "objc", \'.m': 'objc',
\".mak": "mak", \'.mak': 'mak',
\".man": "man", \'.man': 'man',
\".mao": "mao", \'.mao': 'mao',
\".matlab": "matlab", \'.matlab': 'matlab',
\".md": "markdown", \'.md': 'markdown',
\".minid": "minid", \'.minid': 'minid',
\".ml": "ml", \'.ml': 'ml',
\".moo": "moo", \'.moo': 'moo',
\".mu": "mu", \'.mu': 'mu',
\".mustache": "mustache", \'.mustache': 'mustache',
\".mxt": "mxt", \'.mxt': 'mxt',
\".myt": "myt", \'.myt': 'myt',
\".n": "n", \'.n': 'n',
\".nim": "nim", \'.nim': 'nim',
\".nu": "nu", \'.nu': 'nu',
\".numpy": "numpy", \'.numpy': 'numpy',
\".objdump": "objdump", \'.objdump': 'objdump',
\".ooc": "ooc", \'.ooc': 'ooc',
\".parrot": "parrot", \'.parrot': 'parrot',
\".pas": "pas", \'.pas': 'pas',
\".pasm": "pasm", \'.pasm': 'pasm',
\".pd": "pd", \'.pd': 'pd',
\".phtml": "phtml", \'.phtml': 'phtml',
\".pir": "pir", \'.pir': 'pir',
\".pl": "perl", \'.pl': 'perl',
\".po": "po", \'.po': 'po',
\".py": "python", \'.py': 'python',
\".pytb": "pytb", \'.pytb': 'pytb',
\".pyx": "pyx", \'.pyx': 'pyx',
\".r": "r", \'.r': 'r',
\".raw": "raw", \'.raw': 'raw',
\".rb": "ruby", \'.rb': 'ruby',
\".rhtml": "rhtml", \'.rhtml': 'rhtml',
\".rkt": "rkt", \'.rkt': 'rkt',
\".rs": "rs", \'.rs': 'rs',
\".rst": "rst", \'.rst': 'rst',
\".s": "s", \'.s': 's',
\".sass": "sass", \'.sass': 'sass',
\".sc": "sc", \'.sc': 'sc',
\".scala": "scala", \'.scala': 'scala',
\".scm": "scheme", \'.scm': 'scheme',
\".scpt": "scpt", \'.scpt': 'scpt',
\".scss": "scss", \'.scss': 'scss',
\".self": "self", \'.self': 'self',
\".sh": "sh", \'.sh': 'sh',
\".sml": "sml", \'.sml': 'sml',
\".sql": "sql", \'.sql': 'sql',
\".st": "smalltalk", \'.st': 'smalltalk',
\".swift": "swift", \'.swift': 'swift',
\".tcl": "tcl", \'.tcl': 'tcl',
\".tcsh": "tcsh", \'.tcsh': 'tcsh',
\".tex": "tex", \'.tex': 'tex',
\".textile": "textile", \'.textile': 'textile',
\".tpl": "smarty", \'.tpl': 'smarty',
\".twig": "twig", \'.twig': 'twig',
\".txt" : "text", \'.txt' : 'text',
\".v": "verilog", \'.v': 'verilog',
\".vala": "vala", \'.vala': 'vala',
\".vb": "vbnet", \'.vb': 'vbnet',
\".vhd": "vhdl", \'.vhd': 'vhdl',
\".vim": "vim", \'.vim': 'vim',
\".weechatlog": "weechatlog", \'.weechatlog': 'weechatlog',
\".xml": "xml", \'.xml': 'xml',
\".xq": "xquery", \'.xq': 'xquery',
\".xs": "xs", \'.xs': 'xs',
\".yml": "yaml", \'.yml': 'yaml',
\}, get(g:, 'gist_extmap', {})) \}, get(g:, 'gist_extmap', {}))
let &cpo = s:save_cpo let &cpo = s:save_cpo

View file

@ -1,19 +1,19 @@
*Gist.vim* Vimscript for creating gists (http://gist.github.com) *Gist.vim* Vimscript for creating gists (http://gist.github.com)
Usage |gist-vim-usage| Usage |vim-gist-usage|
Tips |gist-vim-tips| Tips |vim-gist-tips|
License |gist-vim-license| License |vim-gist-license|
Install |gist-vim-install| Install |vim-gist-install|
Requirements |gist-vim-requirements| Requirements |vim-gist-requirements|
Setup |gist-vim-setup| Setup |vim-gist-setup|
FAQ |gist-vim-faq| FAQ |vim-gist-faq|
This is a vimscript for creating gists (http://gist.github.com) This is a vimscript for creating gists (http://gist.github.com)
For the latest version please see https://github.com/mattn/gist-vim. For the latest version please see https://github.com/mattn/vim-gist.
============================================================================== ==============================================================================
USAGE *:Gist* *gist-vim-usage* USAGE *:Gist* *vim-gist-usage*
- Post current buffer to gist, using default privacy option. > - Post current buffer to gist, using default privacy option. >
@ -102,6 +102,8 @@ USAGE *:Gist* *gist-vim-usage*
:Gist -l :Gist -l
:Gist --list :Gist --list
:Gist -l -n 100
:Gist --list --per-page 100
< <
- List gists from user "mattn". > - List gists from user "mattn". >
@ -120,15 +122,15 @@ USAGE *:Gist* *gist-vim-usage*
- While the gist list is visible, the following mappings apply: - While the gist list is visible, the following mappings apply:
- 'o' or 'Enter' will open the selected gist file in a new buffer - 'o' or 'Enter' will open the selected gist file in a new buffer
and close the gist-vim listing split. and close the vim-gist listing split.
- 'b' will open the selected gist file in a browser. If you are in - 'b' will open the selected gist file in a browser. If you are in
GUI vim you can also achieve this by pressing 'Shift-Enter'. GUI vim you can also achieve this by pressing 'Shift-Enter'.
- 'y' will copy the contents of the selected gist to the clipboard, - 'y' will copy the contents of the selected gist to the clipboard,
and close the gist-vim listing split. and close the vim-gist listing split.
- 'p' will (copy and) paste the contents of the selected gist to the - 'p' will (copy and) paste the contents of the selected gist to the
buffer from which gist-vim was called, and close the gist-vim buffer from which vim-gist was called, and close the vim-gist
listing split. listing split.
- 'Esc' will close the gist-vim listing split without performing any - 'Esc' will close the vim-gist listing split without performing any
further action. further action.
- Open the gist on browser after you post or update it. - Open the gist on browser after you post or update it.
@ -141,7 +143,7 @@ USAGE *:Gist* *gist-vim-usage*
:Gist! :Gist!
< <
============================================================================== ==============================================================================
TIPS *gist-vim-tips* TIPS *vim-gist-tips*
If you set "g:gist_clip_command", gist.vim will copy the gist code with option If you set "g:gist_clip_command", gist.vim will copy the gist code with option
"-c". "-c".
@ -201,6 +203,10 @@ If you want to open gist list/buffer as vertical split: >
let g:gist_list_vsplit = 1 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 If you want to modify filetype for the file on github, or add mapping of
filetype/file-extension: > filetype/file-extension: >
@ -216,13 +222,13 @@ in your local file, then call >
:Gist :Gist
The gist-vim listing split lists gists ids, names (filenames) as well as The vim-gist listing split lists gists ids, names (filenames) as well as
their description. This is done following a table layout, with fixed space their description. This is done following a table layout, with fixed space
for each column. For offering quick browsing, gist-vim will truncate all for each column. For offering quick browsing, vim-gist will truncate all
output exceeding the available horizontal space, assuring that every gist output exceeding the available horizontal space, assuring that every gist
listed only takes one line on the table. Although the gist id field width is listed only takes one line on the table. Although the gist id field width is
fixed internally, the user can define the length of the (file)name field on fixed internally, the user can define the length of the (file)name field on
the gist-vim listing. This can be done by the following declaration: the vim-gist listing. This can be done by the following declaration:
let g:gist_namelength = 20 let g:gist_namelength = 20
@ -241,7 +247,7 @@ All other values are treated as 1.
This variable's value is 1 by default. This variable's value is 1 by default.
============================================================================== ==============================================================================
LICENSE *gist-vim-license* LICENSE *vim-gist-license*
Copyright 2010 by Yasuhiro Matsumoto Copyright 2010 by Yasuhiro Matsumoto
@ -267,7 +273,7 @@ LICENSE *gist-vim-license*
OF THE POSSIBILITY OF SUCH DAMAGE. OF THE POSSIBILITY OF SUCH DAMAGE.
============================================================================== ==============================================================================
INSTALL *gist-vim-install* INSTALL *vim-gist-install*
Copy following files into your plugin directory. Copy following files into your plugin directory.
@ -275,7 +281,7 @@ rtp:
- autoload/gist.vim - autoload/gist.vim
- plugin/gist.vim - plugin/gist.vim
If you want to uninstall gist.vim, remember to also remove `~/.gist-vim`. If you want to uninstall gist.vim, remember to also remove `~/.vim-gist`.
You need to install webapi-vim also: You need to install webapi-vim also:
@ -286,17 +292,17 @@ If you want to use latest one:
https://github.com/mattn/webapi-vim https://github.com/mattn/webapi-vim
============================================================================== ==============================================================================
REQUIREMENTS *gist-vim-requirements* REQUIREMENTS *vim-gist-requirements*
- curl command (http://curl.haxx.se/) - curl command (http://curl.haxx.se/)
- webapi-vim (https://github.com/mattn/webapi-vim) - webapi-vim (https://github.com/mattn/webapi-vim)
- and, if you want to use your git profile, the git command-line client. - and, if you want to use your git profile, the git command-line client.
============================================================================== ==============================================================================
SETUP *gist-vim-setup* SETUP *vim-gist-setup*
This plugin uses GitHub API v3. The authentication value is stored in `~/.gist-vim`. This plugin uses GitHub API v3. The authentication value is stored in `~/.vim-gist`.
gist-vim provides two ways to authenticate against the GitHub APIs. vim-gist provides two ways to authenticate against the GitHub APIs.
First, you need to set your GitHub username in global git config: First, you need to set your GitHub username in global git config:
> >
@ -312,7 +318,7 @@ If you have two-factor authentication enabled on GitHub, you'll see the message
"Must specify two-factor authentication OTP code." In this case, you need to "Must specify two-factor authentication OTP code." In this case, you need to
create a "Personal Access Token" on GitHub's "Account Settings" page create a "Personal Access Token" on GitHub's "Account Settings" page
(https://github.com/settings/applications) and place it in a file (https://github.com/settings/applications) and place it in a file
named ~/.gist-vim like this: named ~/.vim-gist like this:
> >
token xxxxx token xxxxx
< <
@ -331,13 +337,13 @@ This is not secure at all, so strongly discouraged.
NOTE: the username is optional if you only send anonymous gists. NOTE: the username is optional if you only send anonymous gists.
============================================================================== ==============================================================================
FAQ *gist-vim-faq* FAQ *vim-gist-faq*
Q. :Gist returns a Forbidden error Q. :Gist returns a Forbidden error
A. Try deleting ~/.gist-vim and authenticating again. A. Try deleting ~/.vim-gist and authenticating again.
============================================================================== ==============================================================================
THANKS *gist-vim-thanks* THANKS *vim-gist-thanks*
AD7six AD7six
Bruno Bigras Bruno Bigras

View file

@ -1,303 +0,0 @@
script_name: Gist.vim
script_id: '2423'
script_type: utility
script_package: gist-vim.zip
script_version: '7.3'
required_vim_version: '7.0'
summary: vimscript for gist
detailed_description: |
This is vimscript for gist (http://gist.github.com)
Usage:
:Gist
post whole text to gist.
:'<,'>Gist
post selected text to gist.
:Gist -p
post whole text to gist with private.
if you got empty gist list, try :Gist --abandon
:Gist -a
post whole text to gist with anonymous.
:Gist -m
post multi buffer to gist.
:Gist -e
edit the gist. (should be work on gist buffer)
you can update the gist with :w command on gist buffer.
:Gist -e foo.js
edit the gist with name 'foo.js'. (should be work on gist buffer)
:Gist -d
delete the gist. (should be work on gist buffer)
authentication required.
:Gist -f
fork the gist. (should be work on gist buffer)
authentication required.
:Gist XXXXX
get gist XXXXX.
:Gist -c XXXXX.
get gist XXXXX and put to clipboard.
:Gist -l
list gists from mine.
:Gist -la
list gists from all.
Tips:
if set g:gist_clip_command, gist.vim will copy the gist code
with option '-c'.
# mac
let g:gist_clip_command = 'pbcopy'
# linux
let g:gist_clip_command = 'xclip -selection clipboard'
# others(cygwin?)
let g:gist_clip_command = 'putclip'
if you want to detect filetype from filename...
let g:gist_detect_filetype = 1
if you want to open browser after the post...
let g:gist_open_browser_after_post = 1
if you want to change the browser...
let g:gist_browser_command = 'w3m %URL%'
or
let g:gist_browser_command = 'opera %URL% &'
on windows, should work with original setting.
Require:
curl command (http://curl.haxx.se/)
and if you want to use profile of git, it require git command.
install_details: |
copy it to your plugin directory.
gist.vim leave cookie-jar file into runtimepath.
rtp:
plugin/gist.vim
cookies/github
See also: https://github.com/mattn/gist-vim/blob/master/README.mkd
versions:
- '7.3': |
This is an upgrade for Gist.vim: fixed many bugs. Added few list actions: yank, paste, open in browser.
- '7.2': |
This is an upgrade for Gist.vim: fixed many bugs.
- '7.1': |
This is an upgrade for Gist.vim: updated installation notes.
- '7.0': |
This is an upgrade for Gist.vim: fixed few bugs.
- '6.9': |
This is an upgrade for Gist.vim: fixed few bugs.
- '6.8': |
This is an upgrade for Gist.vim: changed authentication. removed password authentication. if you want to keep using password authentication, let gist_use_password_in_gitconfig to 1.
- '6.7': |
This is an upgrade for Gist.vim: fix behavior of g:gist_browser_command = ':OpenBrowser %URL%'.
- '6.6': |
This is an upgrade for Gist.vim: fixed detecting filetype.
- '6.5': |
This is an upgrade for Gist.vim: use webapi namespace. NOTE: please upgrade webapi-vim also.
- '6.4': |
This is an upgrade for Gist.vim: fixed updating with description.
- '6.3': |
This is an upgrade for Gist.vim: fixed typos.
- '6.2': |
This is an upgrade for Gist.vim: fixed some bugs.
- '6.1': |
This is an upgrade for Gist.vim: fixed opening browser.
- '6.0': |
This is an upgrade for Gist.vim: changed to use github APIs. Note to remove cookies directory if you used.
- '5.9': |
This is an upgrade for Gist.vim: add support anonymous post. fixed many bugs.
- '5.8': |
This is an upgrade for Gist.vim: add support for description. you can post description using -s option.
- '5.7': |
This is an upgrade for Gist.vim: post with filetype more cleverly.
- '5.6': |
This is an upgrade for Gist.vim: fix '--abandon'.
- '5.5': |
This is an upgrade for Gist.vim: fix: forgot to upload autoload/gist.vim.
- '5.4': |
This is an upgrade for Gist.vim: fix: does not work correctly with blockwize selection.
- '5.3': |
This is an upgrade for Gist.vim: upd: support autoload.
- '5.2': |
This is an upgrade for Gist.vim: add: support block-wise selection.
- '5.1': |
This is an upgrade for Gist.vim: fix: can't update privates.
- '5.0': |
This is an upgrade for Gist.vim: follow update of gist.github.com
- '4.9': |
fix: don't add new line after "Done: xxx".
fix: show WHY FAILED' when failed to post.
add: support for :OpenBrowser.
add: new option 'gist_curl_options'.
- '4.8': |
This is an upgrade for Gist.vim: fix: can't open private gist with ":Gist XXXXX".
- '4.7': |
This is an upgrade for Gist.vim: fix: filetype detection.
- '4.6': |
This is an upgrade for Gist.vim: fix: strange cookies folder.
- '4.5': |
This is an upgrade for Gist.vim: fix: use gist_clip_command for copying URL to clipboard. this fix strange behavior on Mac OSX.
- '4.4': |
This is an upgrade for Gist.vim: fix: gist is now only using https.
- '4.3': |
This is an upgrade for Gist.vim: add new option '-f' for fork.
- '4.2': |
This is an upgrade for Gist.vim: fixed code for login.
- '4.1': |
This is an upgrade for Gist.vim: fixed code cleanup.
- '4.0': |
This is an upgrade for Gist.vim: fixed deleting gist, listing privates.
- '3.9': |
This is an upgrade for Gist.vim: fixed :w handler in gist buffer.
- '3.8': |
This is an upgrade for Gist.vim: 'more...' on gist list.
- '3.7': |
This is an upgrade for Gist.vim: fix problem that break "gist list" window at twice.
- '3.6': |
This is an upgrade for Gist.vim: fix filetype detection for 'vimscript'.
- '3.5': |
This is an upgrade for Gist.vim: fix filetype detection.
- '3.4': |
This is an upgrade for Gist.vim: use '+' register on unix only if built with 'xterm_clipboard'. and some bug fixes.
- '3.3': |
This is an upgrade for Gist.vim: fix problem that append empty line when getting gist.
- '3.2': |
This is an upgrade for Gist.vim: added Gist header to recognize the gist. added script type header for Vimana.
- '3.1': |
This is an upgrade for Gist.vim: fix checking redirect url.
- '3.0': |
This is an upgrade for Gist.vim: fix for official changes(private button name was changed).
- '2.9': |
This is an upgrade for Gist.vim: fix for official changes(private button name was changed).
- '2.8': |
This is an upgrade for Gist.vim: be able to post multi buffer. currently updating or showing not supported. and ':Gist -d' delete the gist.
- '2.7': |
This is an upgrade for Gist.vim: be able to write the gist to local file with ':w foo.txt'.
- '2.6': |
This is an upgrade for Gist.vim: fixed problem that does not work 'Gist XXXX'.
- '2.5': |
This is an upgrade for Gist.vim: use existing buffer when open the list or gist.
- '2.4': |
This is an upgrade for Gist.vim: show error message when no any github settings.
- '2.3': |
This is an upgrade for Gist.vim: added :w BufWriteCmd for GistUpdate.
- '2.2': |
This is an upgrade for Gist.vim: fixed a bug for anonymous post. and new option '-a' for anonymous post.
- '2.1': |
This is an upgrade for Gist.vim: support changing gist filename.
- '2.0': |
This is an upgrade for Gist.vim: bugfix for listing gists in specified user.
- '1.9': |
This is an upgrade for Gist.vim: added support editing the gist. and bits bug fix.
- '1.8': |
This is an upgrade for Gist.vim: added new option g:gist_open_browser_after_post/g:gist_browser_command to open posted gist.
- '1.7': |
This is an upgrade for Gist.vim: now changed argument for putting clipboard as ':Gist -c XXXXX'.
- '1.6': |
This is an upgrade for Gist.vim: add gist's author in gist list.
- '1.5': |
This is an upgrade for Gist.vim: oops. bugfix for auto-detection.
- '1.4': |
This is an upgrade for Gist.vim: bugfix for auto-detection.
- '1.3': |
This is an upgrade for Gist.vim: more auto-detection for filetype.
- '1.2': |
This is an upgrade for Gist.vim: added new option for detect filetype from filename.
- '1.1': |
This is an upgrade for Gist.vim: calling StdinReadPost.
- '1.0': |
This is an upgrade for Gist.vim: treat literal "-" as part of username.
- '0.9': |
This is an upgrade for Gist.vim: added new option 'g:gist_clip_command' that copy the gist code.
# __END__
# vim: filetype=yaml

View file

@ -1,7 +1,7 @@
"============================================================================= "=============================================================================
" File: gist.vim " File: gist.vim
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com> " Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
" WebPage: http://github.com/mattn/gist-vim " WebPage: http://github.com/mattn/vim-gist
" License: BSD " License: BSD
" GetLatestVimScripts: 2423 1 :AutoInstall: gist.vim " GetLatestVimScripts: 2423 1 :AutoInstall: gist.vim
" script type: plugin " script type: plugin
@ -12,12 +12,13 @@ endif
let g:loaded_gist_vim = 1 let g:loaded_gist_vim = 1
function! s:CompleteArgs(arg_lead,cmdline,cursor_pos) 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", \ "--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') \ ]), 'stridx(v:val, a:arg_lead)==0')
endfunction 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>) command! -nargs=? -range=% -bang -complete=customlist,s:CompleteArgs Gist :call gist#Gist(<count>, "<bang>", <line1>, <line2>, <f-args>)
" vim:set et: " vim:set et:

View file

@ -87,6 +87,10 @@ For the latest version please see https://github.com/mattn/vim-gist.
:Gist -l mattn :Gist -l mattn
- Specify the number of gists listed:
:Gist -l -n 100
- List everyone's gists. - List everyone's gists.
:Gist -la :Gist -la
@ -188,6 +192,10 @@ You need to either set global git config:
$ git config --global github.user Username $ 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: ## License:
Copyright 2010 by Yasuhiro Matsumoto Copyright 2010 by Yasuhiro Matsumoto

View file

@ -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. " 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') ? ':' : '_') let s:bufprefix = 'gist' . (has('unix') ? ':' : '_')
function! s:GistList(gistls, page) abort function! s:GistList(gistls, page, pagelimit) abort
if a:gistls ==# '-all' if a:gistls ==# '-all'
let url = g:gist_api_url.'gists/public' let url = g:gist_api_url.'gists/public'
elseif get(g:, 'gist_show_privates', 0) && a:gistls ==# 'starred' 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 exec 'silent noautocmd split' s:bufprefix.a:gistls
endif endif
endif endif
let url = url . '?per_page=' . a:pagelimit
if a:page > 1 if a:page > 1
let oldlines = getline(0, line('$')) let oldlines = getline(0, line('$'))
let url = url . '?page=' . a:page let url = url . '&page=' . a:page
endif endif
setlocal modifiable setlocal modifiable
@ -527,7 +529,7 @@ function! s:GistListAction(mode) abort
return return
endif endif
if line =~# '^more\.\.\.$' 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 return
endif endif
endfunction endfunction
@ -761,6 +763,8 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
let editpost = 0 let editpost = 0
let anonymous = get(g:, 'gist_post_anonymous', 0) let anonymous = get(g:, 'gist_post_anonymous', 0)
let openbrowser = 0 let openbrowser = 0
let setpagelimit = 0
let pagelimit = g:gist_per_page_limit
let listmx = '^\%(-l\|--list\)\s*\([^\s]\+\)\?$' let listmx = '^\%(-l\|--list\)\s*\([^\s]\+\)\?$'
let bufnamemx = '^' . s:bufprefix .'\(\zs[0-9a-f]\+\ze\|\zs[0-9a-f]\+\ze[/\\].*\)$' let bufnamemx = '^' . s:bufprefix .'\(\zs[0-9a-f]\+\ze\|\zs[0-9a-f]\+\ze[/\\].*\)$'
if strlen(g:github_user) == 0 && anonymous == 0 if strlen(g:github_user) == 0 && anonymous == 0
@ -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') 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']) exe '!' printf('git clone git@github.com:%s', b:gist['id'])
return 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' elseif arg =~# '^\(-la\|--listall\)$\C'
let gistls = '-all' let gistls = '-all'
elseif arg =~# '^\(-ls\|--liststar\)$\C' elseif arg =~# '^\(-ls\|--liststar\)$\C'
@ -868,6 +880,14 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
endif endif
elseif arg =~# '^\(-b\|--browser\)$\C' elseif arg =~# '^\(-b\|--browser\)$\C'
let openbrowser = 1 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 elseif arg !~# '^-' && len(gistnm) == 0
if gistdesc !=# ' ' if gistdesc !=# ' '
let gistdesc = matchstr(arg, '^\s*\zs.*\ze\s*$') let gistdesc = matchstr(arg, '^\s*\zs.*\ze\s*$')
@ -904,7 +924,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
endif endif
if len(gistls) > 0 if len(gistls) > 0
call s:GistList(gistls, 1) call s:GistList(gistls, 1, pagelimit)
elseif len(gistid) > 0 && editpost == 0 && deletepost == 0 elseif len(gistid) > 0 && editpost == 0 && deletepost == 0
call s:GistGet(gistid, clipboard) call s:GistGet(gistid, clipboard)
else else

View file

@ -102,6 +102,8 @@ USAGE *:Gist* *vim-gist-usage*
:Gist -l :Gist -l
:Gist --list :Gist --list
:Gist -l -n 100
:Gist --list --per-page 100
< <
- List gists from user "mattn". > - 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 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 If you want to modify filetype for the file on github, or add mapping of
filetype/file-extension: > filetype/file-extension: >

View file

@ -12,12 +12,13 @@ endif
let g:loaded_gist_vim = 1 let g:loaded_gist_vim = 1
function! s:CompleteArgs(arg_lead,cmdline,cursor_pos) 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", \ "--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') \ ]), 'stridx(v:val, a:arg_lead)==0')
endfunction 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>) command! -nargs=? -range=% -bang -complete=customlist,s:CompleteArgs Gist :call gist#Gist(<count>, "<bang>", <line1>, <line2>, <f-args>)
" vim:set et: " vim:set et: