From b70deb34f5542b22ed503b245faec5f7e4f291b5 Mon Sep 17 00:00:00 2001 From: mattn Date: Sat, 31 Mar 2012 22:04:41 +0900 Subject: [PATCH 001/170] update for release. --- Makefile | 6 +++--- gist.vim.vimup | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 603a2fa..81370a8 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,11 @@ all : gist-vim.zip remove-zip: - -rm doc/tags - -rm gist-vim.zip + -rm -f doc/tags + -rm -f gist-vim.zip gist-vim.zip: remove-zip - zip -r gist-vim.zip autoload plugin doc + zip -r gist-vim.zip autoload plugin doc README.mkd release: gist-vim.zip vimup update-script gist.vim diff --git a/gist.vim.vimup b/gist.vim.vimup index edb9bc8..7e8cc59 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -2,7 +2,7 @@ script_name: Gist.vim script_id: '2423' script_type: utility script_package: gist-vim.zip -script_version: '5.9' +script_version: '6.0' required_vim_version: '7.0' summary: vimscript for gist @@ -100,7 +100,7 @@ install_details: | if you want to uninstall gist.vim, you have better to remove 'cookies/github'. - for using gist.vim, you should install git. or set g:github_user and g:github_token into your vimrc. + for using gist.vim, you should install git. or set g:github_user and g:github_token into your vimrc. note that g:github_token is NOT a your password. how get your token. @@ -110,6 +110,9 @@ install_details: | 4. you'll see it at following of 'API Token'. versions: +- '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. From 0daaa5c24ef9ac9330b859e2701f51f5ac026552 Mon Sep 17 00:00:00 2001 From: mattn Date: Sat, 31 Mar 2012 22:08:57 +0900 Subject: [PATCH 002/170] updated doc. --- README.mkd | 10 +++------- gist.vim.vimup | 2 ++ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/README.mkd b/README.mkd index c80b575..68fffc7 100644 --- a/README.mkd +++ b/README.mkd @@ -60,7 +60,7 @@ For the latest version please see https://github.com/mattn/gist-vim. Password authentication is needed. :Gist -f - + - Star the gist (you need to have opened the gist buffer first). Password authentication is needed. @@ -133,14 +133,10 @@ On windows, this should work with your user settings. If you want to show your private gists with ":Gist -l": let g:gist_show_privates = 1 - -If you want your gist to be private by default: - let g:gist_private = 1 - -If you get problems when creating gists try: +If you want your gist to be private by default: - :Gist --abandon + let g:gist_post_private = 1 You need to either set global git config diff --git a/gist.vim.vimup b/gist.vim.vimup index 7e8cc59..0bfb760 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -109,6 +109,8 @@ install_details: | 3. click "Account Admin" 4. you'll see it at following of 'API Token'. + See also: https://github.com/mattn/gist-vim/blob/master/README.mkd + versions: - '6.0': | This is an upgrade for Gist.vim: changed to use github APIs. Note to remove cookies directory if you used. From 05fcdfcddfa431074c91f22e45fa2bc740705f5c Mon Sep 17 00:00:00 2001 From: mattn Date: Sun, 1 Apr 2012 00:30:36 +0900 Subject: [PATCH 003/170] fixed opening browser. --- autoload/gist.vim | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 9fb26e2..23f20a7 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 31-Mar-2012. +" Last Change: 01-Apr-2012. " Version: 6.0 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -119,22 +119,22 @@ function! s:get_browser_command() let gist_browser_command = get(g:, 'gist_browser_command', '') if gist_browser_command == '' if has('win32') || has('win64') - let gist_browser_command = "!start rundll32 url.dll,FileProtocolHandler %URL%" + let gist_browser_command = '!start rundll32 url.dll,FileProtocolHandler %URL%' elseif has('mac') - let gist_browser_command = "open %URL%" + let gist_browser_command = 'open %URL%' elseif executable('xdg-open') - let gist_browser_command = "xdg-open %URL%" + let gist_browser_command = 'xdg-open %URL%' elseif executable('firefox') - let gist_browser_command = "firefox %URL% &" + let gist_browser_command = 'firefox %URL% &' else - let gist_browser_command = "" + let gist_browser_command = '' endif endif return gist_browser_command endfunction function! s:open_browser(url) - let cmd = substitute(s:get_browser_command(), '%URL%', '\=a:url', 'g') + let cmd = s:get_browser_command() if len(cmd) == 0 echohl WarningMsg echo "It seems that you don't have general web browser. Open URL below." @@ -142,14 +142,19 @@ function! s:open_browser(url) return endif if cmd =~ '^!' + let cmd = substitute(cmd, '%URL%', '\=shellescape(a:url)', 'g') silent! exec cmd elseif cmd =~ '^:[A-Z]' - exec cmd + let cmd = substitute(cmd, '%URL%', '\=a:url', 'g') + exec cmd url else + let cmd = substitute(cmd, '%URL%', '\=shellescape(a:url)', 'g') call system(cmd) endif endfunction +call s:open_browser("http://www.google.com/?foo=bar&client_id=bao") + function! s:shellwords(str) let words = split(a:str, '\%(\([^ \t\''"]\+\)\|''\([^\'']*\)''\|"\(\%([^\"\\]\|\\.\)*\)"\)\zs\s*\ze') let words = map(words, 'substitute(v:val, ''\\\([\\ ]\)'', ''\1'', "g")') From 9287341f4f7607c3e1cba14c4068fa77d824d22a Mon Sep 17 00:00:00 2001 From: mattn Date: Sun, 1 Apr 2012 00:31:37 +0900 Subject: [PATCH 004/170] version bump up. --- autoload/gist.vim | 2 +- gist.vim.vimup | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 23f20a7..5adb4b7 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -2,7 +2,7 @@ " File: gist.vim " Author: Yasuhiro Matsumoto " Last Change: 01-Apr-2012. -" Version: 6.0 +" Version: 6.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD " Usage: diff --git a/gist.vim.vimup b/gist.vim.vimup index 0bfb760..b82cc00 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -112,6 +112,9 @@ install_details: | See also: https://github.com/mattn/gist-vim/blob/master/README.mkd versions: +- '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. From 9779df862d52ec331674d609288eb3b5ab4dbc5b Mon Sep 17 00:00:00 2001 From: mattn Date: Sun, 1 Apr 2012 00:31:57 +0900 Subject: [PATCH 005/170] ooooooooooooops. --- autoload/gist.vim | 2 -- 1 file changed, 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 5adb4b7..8c04250 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -153,8 +153,6 @@ function! s:open_browser(url) endif endfunction -call s:open_browser("http://www.google.com/?foo=bar&client_id=bao") - function! s:shellwords(str) let words = split(a:str, '\%(\([^ \t\''"]\+\)\|''\([^\'']*\)''\|"\(\%([^\"\\]\|\\.\)*\)"\)\zs\s*\ze') let words = map(words, 'substitute(v:val, ''\\\([\\ ]\)'', ''\1'', "g")') From b6120b16603dad4b4e92aaa8575f3dc79bc8ebdb Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 2 Apr 2012 09:37:53 +0900 Subject: [PATCH 006/170] check g:github_user exists. --- autoload/gist.vim | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 8c04250..f034e4f 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 01-Apr-2012. +" Last Change: 02-Apr-2012. " Version: 6.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -115,6 +115,13 @@ let s:save_cpo = &cpo set cpo&vim +if !exists('g:github_user') + let g:github_user = substitute(system('git config --global github.user'), "\n", '', '') + if strlen(g:github_user) == 0 + let g:github_user = $GITHUB_USER + end +endif + function! s:get_browser_command() let gist_browser_command = get(g:, 'gist_browser_command', '') if gist_browser_command == '' @@ -490,11 +497,9 @@ endfunction function! gist#Gist(count, line1, line2, ...) redraw - if !exists('g:github_user') - let g:github_user = substitute(system('git config --global github.user'), "\n", '', '') - if strlen(g:github_user) == 0 - let g:github_user = $GITHUB_USER - end + if strlen(g:github_user) == 0 + echohl ErrorMsg | echomsg "You don't have github account. read ':help Gist.vim'." | echohl None + return endif let bufname = bufname("%") let gistid = '' @@ -671,12 +676,6 @@ function! s:GetAuthHeader() echohl None let api = inputlist(['Which API:', '1. basic auth', '2. oauth2']) if api == 1 - if !exists('g:github_user') - let g:github_user = substitute(system('git config --global github.user'), "\n", '', '') - if strlen(g:github_user) == 0 - let g:github_user = $GITHUB_USER - end - endif redraw | echo "\r" let password = inputsecret("Password:") let secret = printf("basic %s", base64#b64encode(g:github_user.":".password)) From 89829ee8e050f85aad7644d59bcdeecea7471b64 Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 2 Apr 2012 15:28:47 +0900 Subject: [PATCH 007/170] fix doc & message. --- autoload/gist.vim | 15 +++++++++++++-- doc/gist-vim.txt | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index f034e4f..1008a21 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -218,8 +218,15 @@ function! s:GistList(gistls, page) echohl ErrorMsg | echomsg 'Gists not found' | echohl None return endif + let content = json#decode(res.content) + if has_key(content, 'message') && len(content.message) + bw! + redraw + echohl ErrorMsg | echomsg content.message | echohl None + return + endif - let lines = map(json#decode(res.content), 's:format_gist(v:val)') + let lines = map(content, 's:format_gist(v:val)') call setline(1, split(join(lines, "\n"), "\n")) $put='more...' @@ -498,7 +505,7 @@ endfunction function! gist#Gist(count, line1, line2, ...) redraw if strlen(g:github_user) == 0 - echohl ErrorMsg | echomsg "You don't have github account. read ':help Gist.vim'." | echohl None + echohl ErrorMsg | echomsg "You don't have github account. read ':help gist-vim-setup'." | echohl None return endif let bufname = bufname("%") @@ -657,6 +664,10 @@ function! gist#Gist(count, line1, line2, ...) endfunction function! s:GetAuthHeader() + if get(g:, 'gist_use_password_in_gitconfig', 0) != 0 + let password = substitute(system('git config --global github.password'), "\n", '', '') + return printf("basic %s", base64#b64encode(g:github_user.":".password)) + endif let auth = "" let configfile = expand('~/.gist-vim') if filereadable(configfile) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index fe868ce..f63028c 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -142,10 +142,6 @@ If you want to show your private gists with ":Gist -l": > let g:gist_show_privates = 1 < -You need to either set global git config -> - $ git config --global github.user Username -< ============================================================================== REQUIREMENTS *gist-vim-requirements* @@ -201,7 +197,19 @@ gist-vim have two ways to access APIs. |BasicAuth| Require github user ID and password. This is easy but not secure. - + You need to either set global git config +> + $ git config --global github.user Username +< + If you want to use password written in ~/.gitconfig like below: +> + [github] + password = xxxxx +< + Add following into your ~/.vimrc +> + let g:gist_use_password_in_gitconfig = 1 +< |OAuth2| 1. Register your application. From 0b38a295fe13847c29a0455c2013f27037ded842 Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 2 Apr 2012 15:30:35 +0900 Subject: [PATCH 008/170] oops. remove debug file. --- autoload/gist.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 1008a21..45cb927 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -291,7 +291,6 @@ function! s:GistGet(gistid, clipboard) let res = http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' - call writefile(split(res.content, "\n"), "myjson.js") try let gist = json#decode(res.content) let filename = sort(keys(gist.files))[0] From a928e68f30f88cc5c33a19d263319821a350a90b Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 2 Apr 2012 15:46:57 +0900 Subject: [PATCH 009/170] Be able to open multiple files in a gist. close #56 --- autoload/gist.vim | 111 +++++++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 51 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 45cb927..915ee66 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -219,7 +219,7 @@ function! s:GistList(gistls, page) return endif let content = json#decode(res.content) - if has_key(content, 'message') && len(content.message) + if type(content) == 4 && has_key(content, 'message') && len(content.message) bw! redraw echohl ErrorMsg | echomsg content.message | echohl None @@ -275,66 +275,75 @@ function! s:GistWrite(fname) endfunction function! s:GistGet(gistid, clipboard) - let winnum = bufwinnr(bufnr(s:bufprefix.a:gistid)) - if winnum != -1 - if winnum != bufwinnr('%') - exe winnum 'wincmd w' - endif - setlocal modifiable - else - exec 'silent noautocmd split' s:bufprefix.a:gistid - endif - let old_undolevels = &undolevels - set undolevels=-1 - filetype detect - silent %d _ + redraw | echon 'Getting gist... ' let res = http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' - try - let gist = json#decode(res.content) - let filename = sort(keys(gist.files))[0] - let content = gist.files[filename].content - call setline(1, split(content, "\n")) - let b:gist = { - \ "filename": filename, - \ "id": gist.id, - \ "description": gist.description, - \ "private": gist.public =~ 'true', - \} - catch + let gist = json#decode(res.content) + if get(g:, 'gist_get_mutiplefile', 0) != 0 + let num_file = len(keys(gist.files)) + else + let num_file = 1 + endif + for n in range(num_file) + try + let filename = sort(keys(gist.files))[n] + + let winnum = bufwinnr(bufnr(s:bufprefix.a:gistid."/".filename)) + if winnum != -1 + if winnum != bufwinnr('%') + exe winnum 'wincmd w' + endif + setlocal modifiable + else + exec 'silent noautocmd split' s:bufprefix.a:gistid."/".filename + endif + let old_undolevels = &undolevels + set undolevels=-1 + filetype detect + silent %d _ + + let content = gist.files[filename].content + call setline(1, split(content, "\n")) + let b:gist = { + \ "filename": filename, + \ "id": gist.id, + \ "description": gist.description, + \ "private": gist.public =~ 'true', + \} + catch + let &undolevels = old_undolevels + bw! + redraw + echohl ErrorMsg | echomsg 'Gist contains binary' | echohl None + return + endtry let &undolevels = old_undolevels - bw! - redraw - echohl ErrorMsg | echomsg 'Gist contains binary' | echohl None - return - endtry + setlocal buftype=acwrite bufhidden=delete noswapfile + setlocal nomodified + doau StdinReadPost + let gist_detect_filetype = get(g:, 'gist_detect_filetype', 0) + if (&ft == '' && gist_detect_filetype == 1) || gist_detect_filetype == 2 + call s:GistDetectFiletype(a:gistid) + endif + if a:clipboard + if exists('g:gist_clip_command') + exec 'silent w !'.g:gist_clip_command + elseif has('clipboard') + silent! %yank + + else + %yank + endif + endif + 1 + au! BufWriteCmd call s:GistWrite(expand("")) + endfor else - let &undolevels = old_undolevels bw! redraw echohl ErrorMsg | echomsg 'Gist not found' | echohl None return endif - let &undolevels = old_undolevels - setlocal buftype=acwrite bufhidden=delete noswapfile - setlocal nomodified - doau StdinReadPost - let gist_detect_filetype = get(g:, 'gist_detect_filetype', 0) - if (&ft == '' && gist_detect_filetype == 1) || gist_detect_filetype == 2 - call s:GistDetectFiletype(a:gistid) - endif - if a:clipboard - if exists('g:gist_clip_command') - exec 'silent w !'.g:gist_clip_command - elseif has('clipboard') - silent! %yank + - else - %yank - endif - endif - 1 - au! BufWriteCmd call s:GistWrite(expand("")) endfunction function! s:GistListAction(shift) From 7bec249c8a3c635bd0e1b1371f5f41fdc48f3ea7 Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 2 Apr 2012 15:49:23 +0900 Subject: [PATCH 010/170] fixed issue #60 --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 915ee66..c28ddf9 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -116,7 +116,7 @@ let s:save_cpo = &cpo set cpo&vim if !exists('g:github_user') - let g:github_user = substitute(system('git config --global github.user'), "\n", '', '') + let g:github_user = substitute(system('git config --get github.user'), "\n", '', '') if strlen(g:github_user) == 0 let g:github_user = $GITHUB_USER end @@ -673,7 +673,7 @@ endfunction function! s:GetAuthHeader() if get(g:, 'gist_use_password_in_gitconfig', 0) != 0 - let password = substitute(system('git config --global github.password'), "\n", '', '') + let password = substitute(system('git config --get github.password'), "\n", '', '') return printf("basic %s", base64#b64encode(g:github_user.":".password)) endif let auth = "" From 7715b2c3b603ef2c4d7adec5e94f6d0886d48a59 Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 2 Apr 2012 16:09:19 +0900 Subject: [PATCH 011/170] welcome back GistID: --- autoload/gist.vim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index c28ddf9..d8f81a7 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -528,7 +528,7 @@ function! gist#Gist(count, line1, line2, ...) let editpost = 0 let anonymous = 0 let listmx = '^\%(-l\|--list\)\s*\([^\s]\+\)\?$' - let bufnamemx = '^' . s:bufprefix .'\zs\([0-9a-f]\+\)\ze$' + let bufnamemx = '^' . s:bufprefix .'\zs\([0-9a-f]\+\|[0-9a-f]\+[/\\].*\)\ze$' let args = (a:0 > 0) ? s:shellwords(a:1) : [] for arg in args @@ -600,12 +600,12 @@ function! gist#Gist(count, line1, line2, ...) elseif arg =~ '^[0-9a-z]\+$\C' let gistid = arg else - echohl ErrorMsg | echomsg 'Invalid arguments' | echohl None + echohl ErrorMsg | echomsg 'Invalid arguments: '.arg | echohl None unlet args return 0 endif elseif len(arg) > 0 - echohl ErrorMsg | echomsg 'Invalid arguments' | echohl None + echohl ErrorMsg | echomsg 'Invalid arguments: '.arg | echohl None unlet args return 0 endif @@ -638,6 +638,12 @@ function! gist#Gist(count, line1, line2, ...) let content = @" call setreg('"', save_regcont, save_regtype) endif + " find GistID: in content , then we should just update + let id = matchstr(content, '\(GistID:\s*\)\@<=[0-9]\+') + if len(id) > 0 + let gistid = id + let editpost = 1 + endif if editpost == 1 let url = s:GistUpdate(content, gistid, gistnm, gistdesc) elseif deletepost == 1 From 713b24ea18d9ce21df3c83b6e471e61616231933 Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 2 Apr 2012 16:27:02 +0900 Subject: [PATCH 012/170] version bump up. --- autoload/gist.vim | 2 +- gist.vim.vimup | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index d8f81a7..e9fa333 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -2,7 +2,7 @@ " File: gist.vim " Author: Yasuhiro Matsumoto " Last Change: 02-Apr-2012. -" Version: 6.1 +" Version: 6.2 " WebPage: http://github.com/mattn/gist-vim " License: BSD " Usage: diff --git a/gist.vim.vimup b/gist.vim.vimup index b82cc00..e3de6e7 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -2,7 +2,7 @@ script_name: Gist.vim script_id: '2423' script_type: utility script_package: gist-vim.zip -script_version: '6.0' +script_version: '6.2' required_vim_version: '7.0' summary: vimscript for gist @@ -112,6 +112,9 @@ install_details: | See also: https://github.com/mattn/gist-vim/blob/master/README.mkd versions: +- '6.2': | + This is an upgrade for Gist.vim: fixed some bugs. + - '6.1': | This is an upgrade for Gist.vim: fixed opening browser. From d6196e4f8783637434a8d475547d487f076aeada Mon Sep 17 00:00:00 2001 From: Richard Michael Date: Mon, 2 Apr 2012 18:55:29 +0300 Subject: [PATCH 013/170] Typos. --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index e9fa333..72bd85f 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -695,9 +695,9 @@ function! s:GetAuthHeader() endif echohl WarningMsg - echo 'Gist.vim need autholization to github API. This settings are stored in "~/.gist-vim". If you want to revoke, do "rm ~/.gist-vim".' + echo 'Gist.vim requires authorization to use the Github API. These settings are stored in "~/.gist-vim". If you want to revoke, do "rm ~/.gist-vim".' echohl ErrorMsg - echo 'Note to do "chmod 600 ~/.gist-vim" after this settings.' + echo 'Be sure to run "chmod 600 ~/.gist-vim" after finishing setup.' echohl None let api = inputlist(['Which API:', '1. basic auth', '2. oauth2']) if api == 1 From 022a3bf6d251c52cfa111286aca4506b7abe6894 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 3 Apr 2012 09:17:18 +0900 Subject: [PATCH 014/170] fix typo. --- README.mkd | 6 +++++- autoload/gist.vim | 4 ++-- doc/gist-vim.txt | 6 +++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.mkd b/README.mkd index 68fffc7..d334c18 100644 --- a/README.mkd +++ b/README.mkd @@ -138,7 +138,11 @@ If you want your gist to be private by default: let g:gist_post_private = 1 -You need to either set global git config +If you want to manipulate multiple files in a gist: + + let g:gist_get_multiplefile = 1 + +You need to either set global git config: $ git config --global github.user Username diff --git a/autoload/gist.vim b/autoload/gist.vim index e9fa333..5d9b12b 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 02-Apr-2012. +" Last Change: 03-Apr-2012. " Version: 6.2 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -280,7 +280,7 @@ function! s:GistGet(gistid, clipboard) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' let gist = json#decode(res.content) - if get(g:, 'gist_get_mutiplefile', 0) != 0 + if get(g:, 'gist_get_multiplefile', 0) != 0 let num_file = len(keys(gist.files)) else let num_file = 1 diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index f63028c..642f750 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -142,6 +142,10 @@ If you want to show your private gists with ":Gist -l": > let g:gist_show_privates = 1 < +If you want to manipulate multiple files in a gist: > + + let g:gist_get_multiplefile = 1 +< ============================================================================== REQUIREMENTS *gist-vim-requirements* @@ -197,7 +201,7 @@ gist-vim have two ways to access APIs. |BasicAuth| Require github user ID and password. This is easy but not secure. - You need to either set global git config + You need to either set global git config: > $ git config --global github.user Username < From a0c81572440f4b984619a430ed68a6c46f6d8a6b Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 3 Apr 2012 09:19:22 +0900 Subject: [PATCH 015/170] no need. doc is enough to get informations. --- autoload/gist.vim | 106 ---------------------------------------------- 1 file changed, 106 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 5d9b12b..8b65a6e 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -5,112 +5,6 @@ " Version: 6.2 " WebPage: http://github.com/mattn/gist-vim " License: BSD -" Usage: -" -" :Gist -" post current buffer to gist, using default privicy option -" (see g:gist_post_private) -" -" :'<,'>Gist -" post selected text to gist., using default privicy option -" This applies to all permutations listed below (except multi) -" (see g:gist_show_private) -" -" :Gist -p -" create a private gist -" -" :Gist -P -" create a public gist -" (only relevant if you've set gists to be private by default) -" -" :Gist -P -" post whole text to gist as public -" This is only relevant if you've set gists to be private by default -" :Gist -a -" create a gist anonymously -" -" :Gist -m -" create a gist with all open buffers -" -" :Gist -e -" edit the gist. (you need to have opend the gist buffer first) -" you can update the gist with :w command on gist buffer -" -" :Gist -d -" delete the gist. (you need to have opend the gist buffer first) -" password authentication is needed -" -" :Gist -f -" fork the gist. (you need to have opend the gist buffer first) -" password authentication is needed -" -" :Gist -e foo.js -" edit the gist with name 'foo.js'. (you need to have opend the gist buffer first) -" -" :Gist XXXXX -" get gist XXXXX -" -" :Gist -c XXXXX -" get gist XXXXX and add to clipboard -" -" :Gist -l -" list your public gists -" -" :Gist -l mattn -" list gists from mattn -" -" :Gist -la -" list all your (public and private) gists -" -" 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 gist's filename... -" -" # detect filetype if vim failed auto-detection. -" let g:gist_detect_filetype = 1 -" -" # detect filetype always. -" let g:gist_detect_filetype = 2 -" -" * 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. -" -" * if you want to show your private gists with ':Gist -l' -" -" let g:gist_show_privates = 1 -" -" * if don't you want to copy URL of the post... -" -" let g:gist_put_url_to_clipboard_after_post = 0 -" -" or if you want to copy URL and add linefeed at the last of URL, -" -" let g:gist_put_url_to_clipboard_after_post = 2 -" -" default value is 1. -" let s:save_cpo = &cpo set cpo&vim From 98de0bfbc9b9e127a33afdeecf7444da596f600c Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 3 Apr 2012 09:20:08 +0900 Subject: [PATCH 016/170] fixed doc that @fcharlier suggestion. --- doc/gist-vim.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 642f750..a39a38d 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -142,7 +142,7 @@ If you want to show your private gists with ":Gist -l": > let g:gist_show_privates = 1 < -If you want to manipulate multiple files in a gist: > +If you want to edit all files for gists containing more than one: > let g:gist_get_multiplefile = 1 < From 3074312be861298e8accec8543e31013c4815957 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 3 Apr 2012 09:22:36 +0900 Subject: [PATCH 017/170] version bump up. --- autoload/gist.vim | 2 +- gist.vim.vimup | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 023adc5..25b8685 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -2,7 +2,7 @@ " File: gist.vim " Author: Yasuhiro Matsumoto " Last Change: 03-Apr-2012. -" Version: 6.2 +" Version: 6.3 " WebPage: http://github.com/mattn/gist-vim " License: BSD diff --git a/gist.vim.vimup b/gist.vim.vimup index e3de6e7..0136b0a 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -2,7 +2,7 @@ script_name: Gist.vim script_id: '2423' script_type: utility script_package: gist-vim.zip -script_version: '6.2' +script_version: '6.3' required_vim_version: '7.0' summary: vimscript for gist @@ -112,6 +112,9 @@ install_details: | See also: https://github.com/mattn/gist-vim/blob/master/README.mkd versions: +- '6.3': | + This is an upgrade for Gist.vim: fixed typos. + - '6.2': | This is an upgrade for Gist.vim: fixed some bugs. From 4f5361b7f37212e519820ef5801b23532eb4b9aa Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 3 Apr 2012 10:58:01 +0900 Subject: [PATCH 018/170] can't delete gist if GistID: exists. close #70 --- autoload/gist.vim | 54 ++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 25b8685..16fd156 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -142,7 +142,10 @@ endfunction function! s:GistGetFileName(gistid) let res = http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }) let gist = json#decode(res.content) - return sort(keys(gist.files))[0] + if has_key(gist, 'files') + return sort(keys(gist.files))[0] + endif + return '' endfunction function! s:GistDetectFiletype(gistid) @@ -261,10 +264,10 @@ endfunction function! s:GistUpdate(content, gistid, gistnm, desc) let gist = { "id": a:gistid, "files" : {}, "description": "","public": function('json#true') } if a:desc != ' ' | let gist["description"] = a:desc | endif - if has('b:gist') && b:gist.private | let gist["public"] = function('json#false') | endif + if exists('b:gist') && b:gist.private | let gist["public"] = function('json#false') | endif let filename = a:gistnm - if exists('b:gistnm') > 0 - let filename = b:gistnm + if exists('b:gist') && has_key(b:gist, 'filename') + let filename = b:gist.filename elseif len(a:gistnm) == 0 let filename = s:GistGetFileName(a:gistid) endif @@ -273,7 +276,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) endif let gist.files[filename] = { "content": a:content, "filename": filename } - redraw | echon 'Posting it to gist... ' + redraw | echon 'Updating gist... ' let res = http#post('https://api.github.com/gists/' . a:gistid, \ json#encode(gist), { "Authorization": s:GetAuthHeader() }) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') @@ -297,7 +300,9 @@ function! s:GistDelete(gistid) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' redraw | echomsg 'Done: ' - unlet b:gist + if exists('b:gist') + unlet b:gist + endif else let status = matchstr(status, '^\d\+\s*\zs.*') echohl ErrorMsg | echomsg 'Delete failed: '.status | echohl None @@ -411,6 +416,7 @@ function! gist#Gist(count, line1, line2, ...) return endif let bufname = bufname("%") + " find GistID: in content , then we should just update let gistid = '' let gistls = '' let gistnm = '' @@ -423,6 +429,11 @@ function! gist#Gist(count, line1, line2, ...) let anonymous = 0 let listmx = '^\%(-l\|--list\)\s*\([^\s]\+\)\?$' let bufnamemx = '^' . s:bufprefix .'\zs\([0-9a-f]\+\|[0-9a-f]\+[/\\].*\)\ze$' + if bufname =~ bufnamemx + let gistidbuf = matchstr(bufname, bufnamemx) + else + let gistidbuf = matchstr(join(getline(a:line1, a:line2), "\n"), '\(GistID:\s*\)\@<=[0-9]\+') + endif let args = (a:0 > 0) ? s:shellwords(a:1) : [] for arg in args @@ -448,14 +459,14 @@ function! gist#Gist(count, line1, line2, ...) let gistdesc = '' elseif arg =~ '^\(-c\|--clipboard\)$\C' let clipboard = 1 - elseif arg =~ '^\(-d\|--delete\)$\C' && bufname =~ bufnamemx + elseif arg =~ '^\(-d\|--delete\)$\C' && gistidbuf != '' + let gistid = gistidbuf let deletepost = 1 - let gistid = matchstr(bufname, bufnamemx) - elseif arg =~ '^\(-e\|--edit\)$\C' && bufname =~ bufnamemx + elseif arg =~ '^\(-e\|--edit\)$\C' && gistidbuf != '' + let gistid = gistidbuf let editpost = 1 - let gistid = matchstr(bufname, bufnamemx) - elseif arg =~ '^\(+1\|--star\)$\C' && bufname =~ bufnamemx - let gistid = matchstr(bufname, bufnamemx) + elseif arg =~ '^\(+1\|--star\)$\C' && gistidbuf != '' + let gistid = gistidbuf let res = http#post('https://api.github.com/gists/'.gistid.'/star', '', { "Authorization": s:GetAuthHeader() }, 'PUT') let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' @@ -464,8 +475,8 @@ function! gist#Gist(count, line1, line2, ...) echohl ErrorMsg | echomsg 'Star failed' | echohl None endif return - elseif arg =~ '^\(-1\|--unstar\)$\C' && bufname =~ bufnamemx - let gistid = matchstr(bufname, bufnamemx) + elseif arg =~ '^\(-1\|--unstar\)$\C' && gistidbuf != '' + let gistid = gistidbuf let res = http#post('https://api.github.com/gists/'.gistid.'/star', '', { "Authorization": s:GetAuthHeader() }, 'DELETE') if status =~ '^2' echomsg "Unstared" gistid @@ -473,8 +484,8 @@ function! gist#Gist(count, line1, line2, ...) echohl ErrorMsg | echomsg 'Unstar failed' | echohl None endif return - elseif arg =~ '^\(-f\|--fork\)$\C' && bufname =~ bufnamemx - let gistid = matchstr(bufname, bufnamemx) + elseif arg =~ '^\(-f\|--fork\)$\C' && gistidbuf != '' + let gistid = gistidbuf let res = http#post('https://api.github.com/gists/'.gistid.'/fork', '', { "Authorization": s:GetAuthHeader() }) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' @@ -514,6 +525,11 @@ function! gist#Gist(count, line1, line2, ...) "echo "editpost=".editpost "echo "deletepost=".deletepost + if gistidbuf != '' && gistid == '' && editpost == 0 && deletepost == 0 + let editpost = 1 + let gistid = gistidbuf + endif + if len(gistls) > 0 call s:GistList(gistls, 1) elseif len(gistid) > 0 && editpost == 0 && deletepost == 0 @@ -532,12 +548,6 @@ function! gist#Gist(count, line1, line2, ...) let content = @" call setreg('"', save_regcont, save_regtype) endif - " find GistID: in content , then we should just update - let id = matchstr(content, '\(GistID:\s*\)\@<=[0-9]\+') - if len(id) > 0 - let gistid = id - let editpost = 1 - endif if editpost == 1 let url = s:GistUpdate(content, gistid, gistnm, gistdesc) elseif deletepost == 1 From 5910dfde4864bc1089b54509e6a81f928fefb681 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 3 Apr 2012 12:41:00 +0900 Subject: [PATCH 019/170] fix deleting gist. related #70 --- autoload/gist.vim | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 16fd156..f91496b 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -283,8 +283,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) if status =~ '^2' let obj = json#decode(res.content) let loc = obj["html_url"] - redraw - echomsg 'Done: '.loc + redraw | echomsg 'Done: '.loc let b:gist = {"id": a:gistid, "filename": filename} else let loc = '' @@ -297,6 +296,8 @@ endfunction function! s:GistDelete(gistid) redraw | echon 'Deleting to gist... ' let res = http#post('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }, 'DELETE') + echo a:gistid + let g:hoge = res let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' redraw | echomsg 'Done: ' @@ -352,8 +353,7 @@ function! s:GistPost(content, private, desc, anonymous) if status =~ '^2' let obj = json#decode(res.content) let loc = obj["html_url"] - redraw - echomsg 'Done: '.loc + redraw | echomsg 'Done: '.loc let b:gist = { \ "filename": filename, \ "id": matchstr(loc, '[^/]\+$'), @@ -398,8 +398,7 @@ function! s:GistPostBuffers(private, desc, anonymous) if status =~ '^2' let obj = json#decode(res.content) let loc = obj["html_url"] - redraw - echomsg 'Done: '.loc + redraw | echomsg 'Done: '.loc let b:gist = {"id": matchstr(loc, '[^/]\+$'), "filename": filename, "private": a:private} else let loc = '' @@ -428,7 +427,7 @@ function! gist#Gist(count, line1, line2, ...) let editpost = 0 let anonymous = 0 let listmx = '^\%(-l\|--list\)\s*\([^\s]\+\)\?$' - let bufnamemx = '^' . s:bufprefix .'\zs\([0-9a-f]\+\|[0-9a-f]\+[/\\].*\)\ze$' + let bufnamemx = '^' . s:bufprefix .'\(\zs[0-9a-f]\+\ze\|\zs[0-9a-f]\+\ze[/\\].*\)$' if bufname =~ bufnamemx let gistidbuf = matchstr(bufname, bufnamemx) else From e27918ff90391c4109812b44d5ba2e0c3411bbe9 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 3 Apr 2012 17:18:31 +0900 Subject: [PATCH 020/170] escape filename. close #71 --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index f91496b..1dddc4a 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -184,6 +184,7 @@ function! s:GistGet(gistid, clipboard) endif for n in range(num_file) try + let old_undolevels = &undolevels let filename = sort(keys(gist.files))[n] let winnum = bufwinnr(bufnr(s:bufprefix.a:gistid."/".filename)) @@ -193,9 +194,8 @@ function! s:GistGet(gistid, clipboard) endif setlocal modifiable else - exec 'silent noautocmd split' s:bufprefix.a:gistid."/".filename + exec 'silent noautocmd split' s:bufprefix.a:gistid."/".fnameescape(filename) endif - let old_undolevels = &undolevels set undolevels=-1 filetype detect silent %d _ From 3a3a6eab798451a8cd8abb8c4468d2186ef6d59d Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 4 Apr 2012 02:19:36 +0900 Subject: [PATCH 021/170] treat ! as bang for github.password. --- autoload/gist.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 1dddc4a..5952d7b 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 03-Apr-2012. +" Last Change: 04-Apr-2012. " Version: 6.3 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -583,6 +583,7 @@ endfunction function! s:GetAuthHeader() if get(g:, 'gist_use_password_in_gitconfig', 0) != 0 let password = substitute(system('git config --get github.password'), "\n", '', '') + if password =~ '^!' | password = system(password[1:]) | endif return printf("basic %s", base64#b64encode(g:github_user.":".password)) endif let auth = "" From bac65b2b378ab2247fc726df5369d40b76a0492b Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 4 Apr 2012 02:21:44 +0900 Subject: [PATCH 022/170] oops. --- autoload/gist.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 5952d7b..a85ee9d 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -583,7 +583,7 @@ endfunction function! s:GetAuthHeader() if get(g:, 'gist_use_password_in_gitconfig', 0) != 0 let password = substitute(system('git config --get github.password'), "\n", '', '') - if password =~ '^!' | password = system(password[1:]) | endif + if password =~ '^!' | let password = system(password[1:]) | endif return printf("basic %s", base64#b64encode(g:github_user.":".password)) endif let auth = "" From a629954243f75d67da0b5f0accf78131c76e6749 Mon Sep 17 00:00:00 2001 From: Capi Etheriel Date: Fri, 6 Apr 2012 12:27:33 -0300 Subject: [PATCH 023/170] documenting oauth authentication requires github.user in .gitconfig --- doc/gist-vim.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index a39a38d..ddb6a67 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -201,7 +201,7 @@ gist-vim have two ways to access APIs. |BasicAuth| Require github user ID and password. This is easy but not secure. - You need to either set global git config: + You need to set global git config: > $ git config --global github.user Username < @@ -227,7 +227,12 @@ gist-vim have two ways to access APIs. Callback URL should be http://mattn.github.com/gist-vim If you don't want to point this site, use URL parameter 'code' as PIN. - 2. Start `:Gist -l` + 2. If you haven't already set up your github user in .gitconfig: +> + $ git config --global github.user Username +< + + 3. Start `:Gist -l` You'll see some prompts. fill ClientID/CilentSecret. Then you can see browser show up. From 003a386edaba3acb35170dfed1aadac0aa4db893 Mon Sep 17 00:00:00 2001 From: mattn Date: Sat, 7 Apr 2012 23:14:35 +0900 Subject: [PATCH 024/170] remove debug message. --- autoload/gist.vim | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index a85ee9d..78d2dca 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 04-Apr-2012. +" Last Change: 07-Apr-2012. " Version: 6.3 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -296,8 +296,6 @@ endfunction function! s:GistDelete(gistid) redraw | echon 'Deleting to gist... ' let res = http#post('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }, 'DELETE') - echo a:gistid - let g:hoge = res let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' redraw | echomsg 'Done: ' From e00d440022fd1af2dcdcebea64f58cf019797e25 Mon Sep 17 00:00:00 2001 From: mattn Date: Sun, 8 Apr 2012 00:07:39 +0900 Subject: [PATCH 025/170] fixed bug: it was removed description with :w. close #73 --- autoload/gist.vim | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 78d2dca..e6ff584 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 07-Apr-2012. +" Last Change: 08-Apr-2012. " Version: 6.3 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -263,16 +263,15 @@ endfunction function! s:GistUpdate(content, gistid, gistnm, desc) let gist = { "id": a:gistid, "files" : {}, "description": "","public": function('json#true') } - if a:desc != ' ' | let gist["description"] = a:desc | endif - if exists('b:gist') && b:gist.private | let gist["public"] = function('json#false') | endif - let filename = a:gistnm - if exists('b:gist') && has_key(b:gist, 'filename') - let filename = b:gist.filename - elseif len(a:gistnm) == 0 - let filename = s:GistGetFileName(a:gistid) - endif - if len(filename) == 0 - let filename = s:get_current_filename(1) + if exists('b:gist') + if has_key(b:gist, 'private') && b:gist.private | let gist["public"] = function('json#false') | endif + if has_key(b:gist, 'description') | let gist["description"] = b:gist.description | endif + if has_key(b:gist, 'filename') | let filename = b:gist.filename | endif + else + if a:desc != ' ' | let gist["description"] = a:desc | endif + let filename = a:gistnm + if len(filename) == 0 | let filename = s:GistGetFileName(a:gistid) | endif + if len(filename) == 0 | let filename = s:get_current_filename(1) | endif endif let gist.files[filename] = { "content": a:content, "filename": filename } From ae427043865257e93f94976effa7ebdec41175b5 Mon Sep 17 00:00:00 2001 From: mattn Date: Sun, 8 Apr 2012 01:52:53 +0900 Subject: [PATCH 026/170] version bump up. --- autoload/gist.vim | 2 +- gist.vim.vimup | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index e6ff584..0bfc9e7 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -2,7 +2,7 @@ " File: gist.vim " Author: Yasuhiro Matsumoto " Last Change: 08-Apr-2012. -" Version: 6.3 +" Version: 6.4 " WebPage: http://github.com/mattn/gist-vim " License: BSD diff --git a/gist.vim.vimup b/gist.vim.vimup index 0136b0a..be7bb93 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -2,7 +2,7 @@ script_name: Gist.vim script_id: '2423' script_type: utility script_package: gist-vim.zip -script_version: '6.3' +script_version: '6.4' required_vim_version: '7.0' summary: vimscript for gist @@ -112,6 +112,9 @@ install_details: | See also: https://github.com/mattn/gist-vim/blob/master/README.mkd versions: +- '6.4': | + This is an upgrade for Gist.vim: fixed updating with description. + - '6.3': | This is an upgrade for Gist.vim: fixed typos. From 2db0cb00bbfd861f7b3a7a58a459c9d4b627b6a3 Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 9 Apr 2012 10:46:13 +0900 Subject: [PATCH 027/170] use namespace 'webapi'. --- autoload/gist.vim | 62 +++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 0bfc9e7..ddd8944 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 08-Apr-2012. +" Last Change: 09-Apr-2012. " Version: 6.4 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -105,14 +105,14 @@ function! s:GistList(gistls, page) silent %d _ redraw | echon 'Listing gists... ' - let res = http#get(url, '', { "Authorization": s:GetAuthHeader() }) + let res = webapi#http#get(url, '', { "Authorization": s:GetAuthHeader() }) if v:shell_error != 0 bw! redraw echohl ErrorMsg | echomsg 'Gists not found' | echohl None return endif - let content = json#decode(res.content) + let content = webapi#json#decode(res.content) if type(content) == 4 && has_key(content, 'message') && len(content.message) bw! redraw @@ -140,8 +140,8 @@ function! s:GistList(gistls, page) endfunction function! s:GistGetFileName(gistid) - let res = http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }) - let gist = json#decode(res.content) + let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }) + let gist = webapi#json#decode(res.content) if has_key(gist, 'files') return sort(keys(gist.files))[0] endif @@ -149,8 +149,8 @@ function! s:GistGetFileName(gistid) endfunction function! s:GistDetectFiletype(gistid) - let res = http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }) - let gist = json#decode(res.content) + let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }) + let gist = webapi#json#decode(res.content) let filename = sort(keys(gist.files))[0] let ext = fnamemodify(filename, ':e') if has_key(s:extmap, ext) @@ -173,10 +173,10 @@ endfunction function! s:GistGet(gistid, clipboard) redraw | echon 'Getting gist... ' - let res = http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }) + let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' - let gist = json#decode(res.content) + let gist = webapi#json#decode(res.content) if get(g:, 'gist_get_multiplefile', 0) != 0 let num_file = len(keys(gist.files)) else @@ -262,9 +262,9 @@ function! s:GistListAction(shift) endfunction function! s:GistUpdate(content, gistid, gistnm, desc) - let gist = { "id": a:gistid, "files" : {}, "description": "","public": function('json#true') } + let gist = { "id": a:gistid, "files" : {}, "description": "","public": function('webapi#json#true') } if exists('b:gist') - if has_key(b:gist, 'private') && b:gist.private | let gist["public"] = function('json#false') | endif + if has_key(b:gist, 'private') && b:gist.private | let gist["public"] = function('webapi#json#false') | endif if has_key(b:gist, 'description') | let gist["description"] = b:gist.description | endif if has_key(b:gist, 'filename') | let filename = b:gist.filename | endif else @@ -276,11 +276,11 @@ function! s:GistUpdate(content, gistid, gistnm, desc) let gist.files[filename] = { "content": a:content, "filename": filename } redraw | echon 'Updating gist... ' - let res = http#post('https://api.github.com/gists/' . a:gistid, - \ json#encode(gist), { "Authorization": s:GetAuthHeader() }) + let res = webapi#http#post('https://api.github.com/gists/' . a:gistid, + \ webapi#json#encode(gist), { "Authorization": s:GetAuthHeader() }) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' - let obj = json#decode(res.content) + let obj = webapi#json#decode(res.content) let loc = obj["html_url"] redraw | echomsg 'Done: '.loc let b:gist = {"id": a:gistid, "filename": filename} @@ -294,7 +294,7 @@ endfunction function! s:GistDelete(gistid) redraw | echon 'Deleting to gist... ' - let res = http#post('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }, 'DELETE') + let res = webapi#http#post('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }, 'DELETE') let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' redraw | echomsg 'Done: ' @@ -337,18 +337,18 @@ endfunction " GistID: 123123 " function! s:GistPost(content, private, desc, anonymous) - let gist = { "files" : {}, "description": "","public": function('json#true') } + let gist = { "files" : {}, "description": "","public": function('webapi#json#true') } if a:desc != ' ' | let gist["description"] = a:desc | endif - if a:private | let gist["public"] = function('json#false') | endif + if a:private | let gist["public"] = function('webapi#json#false') | endif let filename = s:get_current_filename(1) let gist.files[filename] = { "content": a:content, "filename": filename } redraw | echon 'Posting it to gist... ' let auth = a:anonymous ? {} : { "Authorization": s:GetAuthHeader() } - let res = http#post('https://api.github.com/gists', json#encode(gist), auth) + let res = webapi#http#post('https://api.github.com/gists', webapi#json#encode(gist), auth) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' - let obj = json#decode(res.content) + let obj = webapi#json#decode(res.content) let loc = obj["html_url"] redraw | echomsg 'Done: '.loc let b:gist = { @@ -370,9 +370,9 @@ function! s:GistPostBuffers(private, desc, anonymous) let bn = bufnr('%') let query = [] - let gist = { "files" : {}, "description": "","public": function('json#true') } + let gist = { "files" : {}, "description": "","public": function('webapi#json#true') } if a:desc != ' ' | let gist["description"] = a:desc | endif - if a:private | let gist["public"] = function('json#false') | endif + if a:private | let gist["public"] = function('webapi#json#false') | endif let index = 1 for bufnr in bufnrs @@ -390,10 +390,10 @@ function! s:GistPostBuffers(private, desc, anonymous) redraw | echon 'Posting it to gist... ' let auth = a:anonymous ? {} : { "Authorization": s:GetAuthHeader() } - let res = http#post('https://api.github.com/gists', json#encode(gist), auth) + let res = webapi#http#post('https://api.github.com/gists', webapi#json#encode(gist), auth) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' - let obj = json#decode(res.content) + let obj = webapi#json#decode(res.content) let loc = obj["html_url"] redraw | echomsg 'Done: '.loc let b:gist = {"id": matchstr(loc, '[^/]\+$'), "filename": filename, "private": a:private} @@ -463,7 +463,7 @@ function! gist#Gist(count, line1, line2, ...) let editpost = 1 elseif arg =~ '^\(+1\|--star\)$\C' && gistidbuf != '' let gistid = gistidbuf - let res = http#post('https://api.github.com/gists/'.gistid.'/star', '', { "Authorization": s:GetAuthHeader() }, 'PUT') + let res = webapi#http#post('https://api.github.com/gists/'.gistid.'/star', '', { "Authorization": s:GetAuthHeader() }, 'PUT') let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' echomsg "Stared" gistid @@ -473,7 +473,7 @@ function! gist#Gist(count, line1, line2, ...) return elseif arg =~ '^\(-1\|--unstar\)$\C' && gistidbuf != '' let gistid = gistidbuf - let res = http#post('https://api.github.com/gists/'.gistid.'/star', '', { "Authorization": s:GetAuthHeader() }, 'DELETE') + let res = webapi#http#post('https://api.github.com/gists/'.gistid.'/star', '', { "Authorization": s:GetAuthHeader() }, 'DELETE') if status =~ '^2' echomsg "Unstared" gistid else @@ -482,10 +482,10 @@ function! gist#Gist(count, line1, line2, ...) return elseif arg =~ '^\(-f\|--fork\)$\C' && gistidbuf != '' let gistid = gistidbuf - let res = http#post('https://api.github.com/gists/'.gistid.'/fork', '', { "Authorization": s:GetAuthHeader() }) + let res = webapi#http#post('https://api.github.com/gists/'.gistid.'/fork', '', { "Authorization": s:GetAuthHeader() }) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' - let obj = json#decode(res.content) + let obj = webapi#json#decode(res.content) let gistid = obj["id"] else echohl ErrorMsg | echomsg 'Fork failed' | echohl None @@ -581,7 +581,7 @@ function! s:GetAuthHeader() if get(g:, 'gist_use_password_in_gitconfig', 0) != 0 let password = substitute(system('git config --get github.password'), "\n", '', '') if password =~ '^!' | let password = system(password[1:]) | endif - return printf("basic %s", base64#b64encode(g:github_user.":".password)) + return printf("basic %s", webapi#base64#b64encode(g:github_user.":".password)) endif let auth = "" let configfile = expand('~/.gist-vim') @@ -604,7 +604,7 @@ function! s:GetAuthHeader() if api == 1 redraw | echo "\r" let password = inputsecret("Password:") - let secret = printf("basic %s", base64#b64encode(g:github_user.":".password)) + let secret = printf("basic %s", webapi#base64#b64encode(g:github_user.":".password)) call writefile([secret], configfile) return secret elseif api == 2 @@ -619,12 +619,12 @@ function! s:GetAuthHeader() let pin = input("PIN: ") redraw | echo '' - let res = http#post(access_token_url, {"client_id": client_id, "code": pin, "client_secret": client_secret}) + let res = webapi#http#post(access_token_url, {"client_id": client_id, "code": pin, "client_secret": client_secret}) let secret = '' for item in split(res.content, '&') let token = split(item, '=') if len(token) == 2 && token[0] == 'access_token' - let secret = printf("token %s", http#decodeURI(token[1])) + let secret = printf("token %s", webapi#http#decodeURI(token[1])) break endif endfor From db433a0110ffdde3f815d5135a5a4dedabeb01e0 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 10 Apr 2012 21:17:27 +0900 Subject: [PATCH 028/170] show URL. --- autoload/gist.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index ddd8944..e624c18 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 09-Apr-2012. +" Last Change: 10-Apr-2012. " Version: 6.4 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -36,10 +36,13 @@ endfunction function! s:open_browser(url) let cmd = s:get_browser_command() + let cmd = '' if len(cmd) == 0 + redraw echohl WarningMsg echo "It seems that you don't have general web browser. Open URL below." echohl None + echo a:url return endif if cmd =~ '^!' @@ -595,6 +598,7 @@ function! s:GetAuthHeader() return auth endif + redraw echohl WarningMsg echo 'Gist.vim requires authorization to use the Github API. These settings are stored in "~/.gist-vim". If you want to revoke, do "rm ~/.gist-vim".' echohl ErrorMsg From 2e2cbcb1bb92d6bcf3ab7e288b94de6c63c75ba7 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 10 Apr 2012 21:18:23 +0900 Subject: [PATCH 029/170] oops. --- autoload/gist.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index e624c18..d36e77e 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -36,7 +36,6 @@ endfunction function! s:open_browser(url) let cmd = s:get_browser_command() - let cmd = '' if len(cmd) == 0 redraw echohl WarningMsg From da4be5bd96fd100d68a203270671c676e4d8eb40 Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 16 Apr 2012 00:35:04 +0900 Subject: [PATCH 030/170] bump up version. --- autoload/gist.vim | 4 ++-- gist.vim.vimup | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index d36e77e..a87ac9b 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,8 +1,8 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 10-Apr-2012. -" Version: 6.4 +" Last Change: 16-Apr-2012. +" Version: 6.5 " WebPage: http://github.com/mattn/gist-vim " License: BSD diff --git a/gist.vim.vimup b/gist.vim.vimup index be7bb93..e417914 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -2,7 +2,7 @@ script_name: Gist.vim script_id: '2423' script_type: utility script_package: gist-vim.zip -script_version: '6.4' +script_version: '6.5' required_vim_version: '7.0' summary: vimscript for gist @@ -112,6 +112,9 @@ install_details: | See also: https://github.com/mattn/gist-vim/blob/master/README.mkd versions: +- '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. From e2ce76993a5092c51baa5486aa1d93fcdcb7e9b5 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 17 Apr 2012 13:15:47 +0900 Subject: [PATCH 031/170] set nomodified. --- autoload/gist.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/autoload/gist.vim b/autoload/gist.vim index a87ac9b..7993d47 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -286,6 +286,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) let loc = obj["html_url"] redraw | echomsg 'Done: '.loc let b:gist = {"id": a:gistid, "filename": filename} + setlocal nomodified else let loc = '' let status = matchstr(status, '^\d\+\s*\zs.*') From 6682b11f36d65dc4cb39f8c802922d40a5746be6 Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 26 Apr 2012 01:28:34 +0900 Subject: [PATCH 032/170] call doautocommands. close #78 --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 7993d47..87ddd4a 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 16-Apr-2012. +" Last Change: 26-Apr-2012. " Version: 6.5 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -220,7 +220,7 @@ function! s:GistGet(gistid, clipboard) let &undolevels = old_undolevels setlocal buftype=acwrite bufhidden=delete noswapfile setlocal nomodified - doau StdinReadPost + doau StdinReadPost,BufRead,BufReadPost let gist_detect_filetype = get(g:, 'gist_detect_filetype', 0) if (&ft == '' && gist_detect_filetype == 1) || gist_detect_filetype == 2 call s:GistDetectFiletype(a:gistid) From 7b4bcd0064c6050eac1c49c3426dc4e133f5ee0b Mon Sep 17 00:00:00 2001 From: Bao Pham Date: Wed, 2 May 2012 20:03:03 -0700 Subject: [PATCH 033/170] Fix GistID regex for private gists --- autoload/gist.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 87ddd4a..bc44806 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -431,7 +431,7 @@ function! gist#Gist(count, line1, line2, ...) if bufname =~ bufnamemx let gistidbuf = matchstr(bufname, bufnamemx) else - let gistidbuf = matchstr(join(getline(a:line1, a:line2), "\n"), '\(GistID:\s*\)\@<=[0-9]\+') + let gistidbuf = matchstr(join(getline(a:line1, a:line2), "\n"), '\(GistID:\s*\)\@<=\S\+') endif let args = (a:0 > 0) ? s:shellwords(a:1) : [] From 8cf5c5f37db50d64a7c62da732cef3bf80249b4a Mon Sep 17 00:00:00 2001 From: Bao Pham Date: Wed, 2 May 2012 20:19:39 -0700 Subject: [PATCH 034/170] Edit echo message and update doc --- autoload/gist.vim | 2 +- doc/gist-vim.txt | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 87ddd4a..7591722 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -296,7 +296,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) endfunction function! s:GistDelete(gistid) - redraw | echon 'Deleting to gist... ' + redraw | echon 'Deleting gist... ' let res = webapi#http#post('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }, 'DELETE') let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index ddb6a67..360e34d 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -146,6 +146,15 @@ If you want to edit all files for gists containing more than one: > let g:gist_get_multiplefile = 1 < + +If you want to update a gist, embed > + + GistID: xxxxx +> +in your local file, then call > + + :Gist +> ============================================================================== REQUIREMENTS *gist-vim-requirements* From 115dd91e6c94cdae3eac422734a05d0eeac1af7b Mon Sep 17 00:00:00 2001 From: mattn Date: Sat, 5 May 2012 22:58:18 +0900 Subject: [PATCH 035/170] fixes issue #84 --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 87ddd4a..240907e 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 26-Apr-2012. +" Last Change: 05-May-2012. " Version: 6.5 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -270,11 +270,11 @@ function! s:GistUpdate(content, gistid, gistnm, desc) if has_key(b:gist, 'description') | let gist["description"] = b:gist.description | endif if has_key(b:gist, 'filename') | let filename = b:gist.filename | endif else - if a:desc != ' ' | let gist["description"] = a:desc | endif let filename = a:gistnm if len(filename) == 0 | let filename = s:GistGetFileName(a:gistid) | endif if len(filename) == 0 | let filename = s:get_current_filename(1) | endif endif + if a:desc != ' ' | let gist["description"] = a:desc | endif let gist.files[filename] = { "content": a:content, "filename": filename } redraw | echon 'Updating gist... ' From 6d144196566144016f060dd2fc967de574a38ba2 Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 11 May 2012 09:26:42 +0900 Subject: [PATCH 036/170] why ruby... --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 820ccef..38cdc23 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 05-May-2012. +" Last Change: 11-May-2012. " Version: 6.5 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -313,7 +313,7 @@ endfunction function! s:get_current_filename(no) let filename = expand('%:t') if len(filename) == 0 && &ft != '' - let pair = filter(items(s:extmap), 'v:val[1] == "ruby"') + let pair = filter(items(s:extmap), 'v:val[1] == &ft') if len(pair) > 0 let filename = printf('gistfile%d%s', a:no, pair[0][0]) endif From c9eaf835bea30cb5b094d450977b646c5c2da544 Mon Sep 17 00:00:00 2001 From: Bao Pham Date: Tue, 22 May 2012 10:37:40 -0700 Subject: [PATCH 037/170] Old description should remain when updating gist If when updating, no new description is specified with option '-s' --- autoload/gist.vim | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 38cdc23..0bae078 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -274,7 +274,20 @@ function! s:GistUpdate(content, gistid, gistnm, desc) if len(filename) == 0 | let filename = s:GistGetFileName(a:gistid) | endif if len(filename) == 0 | let filename = s:get_current_filename(1) | endif endif - if a:desc != ' ' | let gist["description"] = a:desc | endif + + " Update description + " If no new description specified, keep the old description + if a:desc != ' ' + let gist["description"] = a:desc + else + let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }) + let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') + if status =~ '^2' + let old_gist = webapi#json#decode(res.content) + let gist["description"] = old_gist.description + endif + endif + let gist.files[filename] = { "content": a:content, "filename": filename } redraw | echon 'Updating gist... ' From 13ef9e47aa2be5511905de4496f4f4bcb9983499 Mon Sep 17 00:00:00 2001 From: tyru Date: Sun, 27 May 2012 19:27:05 +0900 Subject: [PATCH 038/170] fix invalid expression in s:open_browser() --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 0bae078..01ec49f 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 11-May-2012. +" Last Change: 2012-05-27. " Version: 6.5 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -49,7 +49,7 @@ function! s:open_browser(url) silent! exec cmd elseif cmd =~ '^:[A-Z]' let cmd = substitute(cmd, '%URL%', '\=a:url', 'g') - exec cmd url + exec cmd else let cmd = substitute(cmd, '%URL%', '\=shellescape(a:url)', 'g') call system(cmd) From 79cfb39e19d52defdcdf22d52a4d0c2080e7b447 Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 28 May 2012 20:03:57 +0900 Subject: [PATCH 039/170] version bump up. --- autoload/gist.vim | 4 ++-- gist.vim.vimup | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 01ec49f..5717ec2 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,8 +1,8 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 2012-05-27. -" Version: 6.5 +" Last Change: 28-May-2012. +" Version: 6.6 " WebPage: http://github.com/mattn/gist-vim " License: BSD diff --git a/gist.vim.vimup b/gist.vim.vimup index e417914..8d63bc4 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -2,7 +2,7 @@ script_name: Gist.vim script_id: '2423' script_type: utility script_package: gist-vim.zip -script_version: '6.5' +script_version: '6.6' required_vim_version: '7.0' summary: vimscript for gist @@ -112,6 +112,9 @@ install_details: | See also: https://github.com/mattn/gist-vim/blob/master/README.mkd versions: +- '6.6': | + This is an upgrade for Gist.vim: fix behavior of g:gist_browser_command = ':OpenBrowser %URL%'. + - '6.5': | This is an upgrade for Gist.vim: use webapi namespace. NOTE: please upgrade webapi-vim also. From 5954a994fba2ce75c92d9d211487534c2a525824 Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 28 May 2012 20:08:46 +0900 Subject: [PATCH 040/170] oops. version mismatched. --- autoload/gist.vim | 2 +- gist.vim.vimup | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 5717ec2..e487a28 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -2,7 +2,7 @@ " File: gist.vim " Author: Yasuhiro Matsumoto " Last Change: 28-May-2012. -" Version: 6.6 +" Version: 6.7 " WebPage: http://github.com/mattn/gist-vim " License: BSD diff --git a/gist.vim.vimup b/gist.vim.vimup index 8d63bc4..dfe1f65 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -2,7 +2,7 @@ script_name: Gist.vim script_id: '2423' script_type: utility script_package: gist-vim.zip -script_version: '6.6' +script_version: '6.7' required_vim_version: '7.0' summary: vimscript for gist @@ -112,9 +112,12 @@ install_details: | See also: https://github.com/mattn/gist-vim/blob/master/README.mkd versions: -- '6.6': | +- '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. From e8eaf77766001fb501e4543022d46c5c82771c89 Mon Sep 17 00:00:00 2001 From: Dejan Ranisavljevic Date: Tue, 19 Jun 2012 13:53:22 +0200 Subject: [PATCH 041/170] Fix for invalid gists to trown errors, list index out of range. Issue: https://github.com/mattn/gist-vim/issues/94 --- autoload/gist.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index e487a28..8d15779 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -65,6 +65,9 @@ endfunction function! s:format_gist(gist) let files = sort(keys(a:gist.files)) + if empty(files) + return "" + endif let file = a:gist.files[files[0]] if has_key(file, "content") let code = file.content @@ -75,7 +78,7 @@ function! s:format_gist(gist) return printf("gist: %s %s%s", a:gist.id, type(a:gist.description)==0?"": a:gist.description, code) 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') ? ':' : '_') function! s:GistList(gistls, page) if a:gistls == '-all' From 51b2d74b2bd15c9627f95896b85ea4df37d115c7 Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 20 Jun 2012 17:02:43 +0900 Subject: [PATCH 042/170] Check gist is empty or gone. --- autoload/gist.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 8d15779..16c3724 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 28-May-2012. +" Last Change: 20-Jun-2012. " Version: 6.7 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -125,7 +125,7 @@ function! s:GistList(gistls, page) return endif - let lines = map(content, 's:format_gist(v:val)') + let lines = map(filter(content, '!empty(v:val.files)'), 's:format_gist(v:val)') call setline(1, split(join(lines, "\n"), "\n")) $put='more...' @@ -187,6 +187,11 @@ function! s:GistGet(gistid, clipboard) else let num_file = 1 endif + if num_file > len(keys(gist.files)) + redraw + echohl ErrorMsg | echomsg 'Gist not found' | echohl None + return + endif for n in range(num_file) try let old_undolevels = &undolevels From 12f0df7f1ad6d3d885068ac99df74e6c927c3550 Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 22 Jun 2012 09:43:10 +0900 Subject: [PATCH 043/170] fix GistID matcher. close #96 --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 16c3724..9d437ce 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 20-Jun-2012. +" Last Change: 22-Jun-2012. " Version: 6.7 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -452,7 +452,7 @@ function! gist#Gist(count, line1, line2, ...) if bufname =~ bufnamemx let gistidbuf = matchstr(bufname, bufnamemx) else - let gistidbuf = matchstr(join(getline(a:line1, a:line2), "\n"), '\(GistID:\s*\)\@<=\S\+') + let gistidbuf = matchstr(join(getline(a:line1, a:line2), "\n"), 'GistID:\s*\zs\w\+') endif let args = (a:0 > 0) ? s:shellwords(a:1) : [] From c67e1a2ea9e1a66f6e08d0b83c795a3064ae61b4 Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 29 Jun 2012 09:00:38 +0900 Subject: [PATCH 044/170] set Content-Type header to post. --- autoload/gist.vim | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 9d437ce..8e0a755 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 22-Jun-2012. +" Last Change: 29-Jun-2012. " Version: 6.7 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -300,7 +300,10 @@ function! s:GistUpdate(content, gistid, gistnm, desc) redraw | echon 'Updating gist... ' let res = webapi#http#post('https://api.github.com/gists/' . a:gistid, - \ webapi#json#encode(gist), { "Authorization": s:GetAuthHeader() }) + \ webapi#json#encode(gist), { + \ "Authorization": s:GetAuthHeader(), + \ "Content-Type": "application/javascript", + \}) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' let obj = webapi#json#decode(res.content) @@ -318,7 +321,11 @@ endfunction function! s:GistDelete(gistid) redraw | echon 'Deleting gist... ' - let res = webapi#http#post('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }, 'DELETE') + let res = webapi#http#post('https://api.github.com/gists/'.a:gistid, '', + \ webapi#json#encode(gist), { + \ "Authorization": s:GetAuthHeader(), + \ "Content-Type": "application/javascript", + \}, 'DELETE') let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' redraw | echomsg 'Done: ' @@ -368,8 +375,11 @@ function! s:GistPost(content, private, desc, anonymous) let gist.files[filename] = { "content": a:content, "filename": filename } redraw | echon 'Posting it to gist... ' - let auth = a:anonymous ? {} : { "Authorization": s:GetAuthHeader() } - let res = webapi#http#post('https://api.github.com/gists', webapi#json#encode(gist), auth) + let header = {"Content-Type": "application/javascript"} + if !a:anonymous + let header["Authorization"] = s:GetAuthHeader() + endif + let res = webapi#http#post('https://api.github.com/gists', webapi#json#encode(gist), header) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' let obj = webapi#json#decode(res.content) @@ -413,8 +423,11 @@ function! s:GistPostBuffers(private, desc, anonymous) silent! exec "buffer!" bn redraw | echon 'Posting it to gist... ' - let auth = a:anonymous ? {} : { "Authorization": s:GetAuthHeader() } - let res = webapi#http#post('https://api.github.com/gists', webapi#json#encode(gist), auth) + let header = {"Content-Type": "application/javascript"} + if !a:anonymous + let header["Authorization"] = s:GetAuthHeader() + endif + let res = webapi#http#post('https://api.github.com/gists', webapi#json#encode(gist), header) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' let obj = webapi#json#decode(res.content) From 6edee86a4294dfad6690dda0523e0c24a250500c Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 29 Jun 2012 10:03:06 +0900 Subject: [PATCH 045/170] application/json is better. --- autoload/gist.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 8e0a755..425fbca 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -125,6 +125,7 @@ function! s:GistList(gistls, page) return endif + let g:hoge = deepcopy(content) let lines = map(filter(content, '!empty(v:val.files)'), 's:format_gist(v:val)') call setline(1, split(join(lines, "\n"), "\n")) @@ -302,7 +303,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) let res = webapi#http#post('https://api.github.com/gists/' . a:gistid, \ webapi#json#encode(gist), { \ "Authorization": s:GetAuthHeader(), - \ "Content-Type": "application/javascript", + \ "Content-Type": "application/json", \}) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' @@ -324,7 +325,7 @@ function! s:GistDelete(gistid) let res = webapi#http#post('https://api.github.com/gists/'.a:gistid, '', \ webapi#json#encode(gist), { \ "Authorization": s:GetAuthHeader(), - \ "Content-Type": "application/javascript", + \ "Content-Type": "application/json", \}, 'DELETE') let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' @@ -375,7 +376,7 @@ function! s:GistPost(content, private, desc, anonymous) let gist.files[filename] = { "content": a:content, "filename": filename } redraw | echon 'Posting it to gist... ' - let header = {"Content-Type": "application/javascript"} + let header = {"Content-Type": "application/json"} if !a:anonymous let header["Authorization"] = s:GetAuthHeader() endif @@ -423,7 +424,7 @@ function! s:GistPostBuffers(private, desc, anonymous) silent! exec "buffer!" bn redraw | echon 'Posting it to gist... ' - let header = {"Content-Type": "application/javascript"} + let header = {"Content-Type": "application/json"} if !a:anonymous let header["Authorization"] = s:GetAuthHeader() endif From a2e317a2ef97fe539d56287725a1a54b62ca05ba Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 29 Jun 2012 13:30:48 +0900 Subject: [PATCH 046/170] remove debug code. --- autoload/gist.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 425fbca..653d27d 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -125,7 +125,6 @@ function! s:GistList(gistls, page) return endif - let g:hoge = deepcopy(content) let lines = map(filter(content, '!empty(v:val.files)'), 's:format_gist(v:val)') call setline(1, split(join(lines, "\n"), "\n")) From 3e02137acd8c9fd5235b9afeae8a7675296aef77 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 3 Jul 2012 09:07:52 +0900 Subject: [PATCH 047/170] fix deleting gist. close #99 --- autoload/gist.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 653d27d..51fa55b 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 29-Jun-2012. +" Last Change: 03-Jul-2012. " Version: 6.7 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -321,8 +321,7 @@ endfunction function! s:GistDelete(gistid) redraw | echon 'Deleting gist... ' - let res = webapi#http#post('https://api.github.com/gists/'.a:gistid, '', - \ webapi#json#encode(gist), { + let res = webapi#http#post('https://api.github.com/gists/'.a:gistid, '', { \ "Authorization": s:GetAuthHeader(), \ "Content-Type": "application/json", \}, 'DELETE') From 91117196361bddf9ac571ec01806aef312bcc52e Mon Sep 17 00:00:00 2001 From: Jaeho Shin Date: Sun, 8 Jul 2012 04:46:32 -0700 Subject: [PATCH 048/170] Use password once to get OAuth token, and forget Github provides a simple way to create an OAuth token using Basic Auth: http://developer.github.com/v3/oauth/#create-a-new-authorization This enables Gist.vim to ask users' password once on first use, and store only the obtained token for later. User can easily revoke the token and create a new one at anytime, so this is much more secure. Forcing them to create their own Github application and exchanging client ID and secrets is totally a nonsense given this simple way to get the same token. :) --- README.mkd | 31 ++++++------------------ autoload/gist.vim | 62 +++++++++++++++++++---------------------------- doc/gist-vim.txt | 42 +++++++++----------------------- 3 files changed, 44 insertions(+), 91 deletions(-) diff --git a/README.mkd b/README.mkd index d334c18..6bf4c45 100644 --- a/README.mkd +++ b/README.mkd @@ -190,31 +190,14 @@ If you want to uninstall gist.vim, remember to also remove `~/.gist-vim`. ## Setup: -This plugin uses github API v3. Setting value is stored in `~/.gist.vim`. +This plugin uses github API v3. Setting value is stored in `~/.gist-vim`. gist-vim have two ways to access APIs. -### Basic Auth +First, you need to set your Github username in global git config: -Require github user ID and password. This is easy but not secure. + $ git config --global github.user Username -### OAuth2 - -1. Register your application. - -Note that you must set `Callback URL` as same as following. - -https://github.com/settings/applications/new - -fill like following - -![](http://mattn.github.com/gist-vim/static/image/setting1.png) - -2. Start `:Gist -l` - -You'll see some prompts. fill ClientID/CilentSecret. Then you can see browser show up. - -![](http://mattn.github.com/gist-vim/static/image/setting2.png) - -This is a PIN code. - -Copy this value and paste to prompt `PIN:`. +Then, gist.vim will ask for your password to create an authorization when you +first use it. The password is not stored and only the OAuth access token will +be kept for later use. You can revoke the token at any time from the list of +["Authorized applications" on Github's "Account Settings" page](https://github.com/settings/applications). diff --git a/autoload/gist.vim b/autoload/gist.vim index 51fa55b..b625ea4 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -9,6 +9,8 @@ let s:save_cpo = &cpo set cpo&vim +let s:configfile = expand('~/.gist-vim') + if !exists('g:github_user') let g:github_user = substitute(system('git config --get github.user'), "\n", '', '') if strlen(g:github_user) == 0 @@ -122,6 +124,9 @@ function! s:GistList(gistls, page) bw! redraw echohl ErrorMsg | echomsg content.message | echohl None + if content.message == 'Bad credentials' + call delete(s:configfile) + endif return endif @@ -620,9 +625,8 @@ function! s:GetAuthHeader() return printf("basic %s", webapi#base64#b64encode(g:github_user.":".password)) endif let auth = "" - let configfile = expand('~/.gist-vim') - if filereadable(configfile) - let str = join(readfile(configfile), "") + if filereadable(s:configfile) + let str = join(readfile(s:configfile), "") if type(str) == 1 let auth = str endif @@ -634,41 +638,25 @@ function! s:GetAuthHeader() redraw echohl WarningMsg echo 'Gist.vim requires authorization to use the Github API. These settings are stored in "~/.gist-vim". If you want to revoke, do "rm ~/.gist-vim".' - echohl ErrorMsg - echo 'Be sure to run "chmod 600 ~/.gist-vim" after finishing setup.' echohl None - let api = inputlist(['Which API:', '1. basic auth', '2. oauth2']) - if api == 1 - redraw | echo "\r" - let password = inputsecret("Password:") - let secret = printf("basic %s", webapi#base64#b64encode(g:github_user.":".password)) - call writefile([secret], configfile) - return secret - elseif api == 2 - let auth_url = "https://github.com/login/oauth/authorize" - let access_token_url = "https://github.com/login/oauth/access_token" - redraw | echo "\r" - let client_id = input("ClientID: ") - redraw | echo "\r" - let client_secret = input("ClientSecret: ") - let url = auth_url."?scope=gist&client_id=".client_id - call s:open_browser(url) - - let pin = input("PIN: ") - redraw | echo '' - let res = webapi#http#post(access_token_url, {"client_id": client_id, "code": pin, "client_secret": client_secret}) - let secret = '' - for item in split(res.content, '&') - let token = split(item, '=') - if len(token) == 2 && token[0] == 'access_token' - let secret = printf("token %s", webapi#http#decodeURI(token[1])) - break - endif - endfor - call writefile([secret], configfile) - return secret - endif - return "" + redraw | echo "\r" + let password = inputsecret("Github Password for ".g:github_user.":") + let insecureSecret = printf("basic %s", webapi#base64#b64encode(g:github_user.":".password)) + let res = webapi#http#post('https://api.github.com/authorizations', webapi#json#encode({ + \ "scopes" : ["gist"], + \ "note" : "Gist.vim on ".hostname(), + \ "note_url" : "http://www.vim.org/scripts/script.php?script_id=2423" + \}), { + \ "Content-Type" : "application/json", + \ "Authorization" : insecureSecret, + \}) + let authorization = webapi#json#decode(res.content) + let secret = printf("token %s", authorization.token) + call writefile([secret], s:configfile) + if !(has('win32') || has('win64')) + call system("chmod go= ".s:configfile) + endif + return secret endfunction let s:extmap = { diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 360e34d..b9a54e8 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -207,46 +207,27 @@ SETUP *gist-vim-setup* This plugin uses github API v3. Setting value is stored in `~/.gist.vim`. gist-vim have two ways to access APIs. -|BasicAuth| - - Require github user ID and password. This is easy but not secure. - You need to set global git config: +First, you need to set your Github username in global git config: > $ git config --global github.user Username < - If you want to use password written in ~/.gitconfig like below: +Then, gist.vim will ask for your password to create an authorization when you +first use it. The password is not stored and only the OAuth access token will +be kept for later use. You can revoke the token at any time from the list of +"Authorized applications" on Github's "Account Settings" page. +(https://github.com/settings/applications) + +If you happen to have your password already written in ~/.gitconfig like +below: > [github] password = xxxxx < - Add following into your ~/.vimrc +Then, add following into your ~/.vimrc > let g:gist_use_password_in_gitconfig = 1 < -|OAuth2| - - 1. Register your application. - - Note that you must set `Callback URL` as same as following. - - https://github.com/settings/applications/new - - fill like following - - Callback URL should be http://mattn.github.com/gist-vim - If you don't want to point this site, use URL parameter 'code' as PIN. - - 2. If you haven't already set up your github user in .gitconfig: -> - $ git config --global github.user Username -< - - 3. Start `:Gist -l` - - You'll see some prompts. fill ClientID/CilentSecret. Then you can see - browser show up. - If you set Callback URL above, you can see PIN code. - Copy this value and paste to prompt `PIN:`. +This is not secure at all, so strongly discouraged. ============================================================================== THANKS *gist-vim-thanks* @@ -265,5 +246,6 @@ THANKS *gist-vim-thanks* steve tyru Will Gray + netj vim:tw=78:ts=8:ft=help:norl: From 4469171a63b9d7a9d0335964e00f1e07c98ebb11 Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 9 Jul 2012 12:04:04 +0900 Subject: [PATCH 049/170] cancel gracefully. --- autoload/gist.vim | 160 +++++++++++++++++++++++++++++++++------------- 1 file changed, 114 insertions(+), 46 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index b625ea4..954e2df 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,8 +1,8 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 03-Jul-2012. -" Version: 6.7 +" Last Change: 09-Jul-2012. +" Version: 6.8 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -112,7 +112,14 @@ function! s:GistList(gistls, page) silent %d _ redraw | echon 'Listing gists... ' - let res = webapi#http#get(url, '', { "Authorization": s:GetAuthHeader() }) + let auth = s:GetAuthHeader() + if len(auth) == 0 + bw! + redraw + echohl ErrorMsg | echomsg 'Canceled' | echohl None + return + endif + let res = webapi#http#get(url, '', { "Authorization": auth }) if v:shell_error != 0 bw! redraw @@ -150,7 +157,11 @@ function! s:GistList(gistls, page) endfunction function! s:GistGetFileName(gistid) - let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }) + let auth = s:GetAuthHeader() + if len(auth) == 0 + return '' + endif + let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": auth }) let gist = webapi#json#decode(res.content) if has_key(gist, 'files') return sort(keys(gist.files))[0] @@ -159,7 +170,11 @@ function! s:GistGetFileName(gistid) endfunction function! s:GistDetectFiletype(gistid) - let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }) + let auth = s:GetAuthHeader() + if len(auth) == 0 + return '' + endif + let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": auth }) let gist = webapi#json#decode(res.content) let filename = sort(keys(gist.files))[0] let ext = fnamemodify(filename, ':e') @@ -288,12 +303,19 @@ function! s:GistUpdate(content, gistid, gistnm, desc) if len(filename) == 0 | let filename = s:get_current_filename(1) | endif endif + let auth = s:GetAuthHeader() + if len(auth) == 0 + redraw + echohl ErrorMsg | echomsg 'Canceled' | echohl None + return + endif + " Update description " If no new description specified, keep the old description if a:desc != ' ' let gist["description"] = a:desc else - let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }) + let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": auth }) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' let old_gist = webapi#json#decode(res.content) @@ -306,7 +328,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) redraw | echon 'Updating gist... ' let res = webapi#http#post('https://api.github.com/gists/' . a:gistid, \ webapi#json#encode(gist), { - \ "Authorization": s:GetAuthHeader(), + \ "Authorization": auth, \ "Content-Type": "application/json", \}) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') @@ -325,9 +347,16 @@ function! s:GistUpdate(content, gistid, gistnm, desc) endfunction function! s:GistDelete(gistid) + let auth = s:GetAuthHeader() + if len(auth) == 0 + redraw + echohl ErrorMsg | echomsg 'Canceled' | echohl None + return + endif + redraw | echon 'Deleting gist... ' let res = webapi#http#post('https://api.github.com/gists/'.a:gistid, '', { - \ "Authorization": s:GetAuthHeader(), + \ "Authorization": auth, \ "Content-Type": "application/json", \}, 'DELETE') let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') @@ -378,11 +407,18 @@ function! s:GistPost(content, private, desc, anonymous) let filename = s:get_current_filename(1) let gist.files[filename] = { "content": a:content, "filename": filename } - redraw | echon 'Posting it to gist... ' let header = {"Content-Type": "application/json"} if !a:anonymous - let header["Authorization"] = s:GetAuthHeader() + let auth = s:GetAuthHeader() + if len(auth) == 0 + redraw + echohl ErrorMsg | echomsg 'Canceled' | echohl None + return + endif + let header["Authorization"] = auth endif + + redraw | echon 'Posting it to gist... ' let res = webapi#http#post('https://api.github.com/gists', webapi#json#encode(gist), header) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' @@ -426,11 +462,17 @@ function! s:GistPostBuffers(private, desc, anonymous) endfor silent! exec "buffer!" bn - redraw | echon 'Posting it to gist... ' let header = {"Content-Type": "application/json"} if !a:anonymous - let header["Authorization"] = s:GetAuthHeader() + if len(auth) == 0 + redraw + echohl ErrorMsg | echomsg 'Canceled' | echohl None + return + endif + let header["Authorization"] = auth endif + + redraw | echon 'Posting it to gist... ' let res = webapi#http#post('https://api.github.com/gists', webapi#json#encode(gist), header) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' @@ -503,34 +545,50 @@ function! gist#Gist(count, line1, line2, ...) let gistid = gistidbuf let editpost = 1 elseif arg =~ '^\(+1\|--star\)$\C' && gistidbuf != '' - let gistid = gistidbuf - let res = webapi#http#post('https://api.github.com/gists/'.gistid.'/star', '', { "Authorization": s:GetAuthHeader() }, 'PUT') - let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') - if status =~ '^2' - echomsg "Stared" gistid + let auth = s:GetAuthHeader() + if len(auth) == 0 + echohl ErrorMsg | echomsg 'Canceled' | echohl None else - echohl ErrorMsg | echomsg 'Star failed' | echohl None + let gistid = gistidbuf + let res = webapi#http#post('https://api.github.com/gists/'.gistid.'/star', '', { "Authorization": auth }, 'PUT') + let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') + if status =~ '^2' + echomsg "Stared" gistid + else + echohl ErrorMsg | echomsg 'Star failed' | echohl None + endif endif return elseif arg =~ '^\(-1\|--unstar\)$\C' && gistidbuf != '' - let gistid = gistidbuf - let res = webapi#http#post('https://api.github.com/gists/'.gistid.'/star', '', { "Authorization": s:GetAuthHeader() }, 'DELETE') - if status =~ '^2' - echomsg "Unstared" gistid + let auth = s:GetAuthHeader() + if len(auth) == 0 + echohl ErrorMsg | echomsg 'Canceled' | echohl None else - echohl ErrorMsg | echomsg 'Unstar failed' | echohl None + let gistid = gistidbuf + let res = webapi#http#post('https://api.github.com/gists/'.gistid.'/star', '', { "Authorization": auth }, 'DELETE') + if status =~ '^2' + echomsg "Unstared" gistid + else + echohl ErrorMsg | echomsg 'Unstar failed' | echohl None + endif endif return elseif arg =~ '^\(-f\|--fork\)$\C' && gistidbuf != '' - let gistid = gistidbuf - let res = webapi#http#post('https://api.github.com/gists/'.gistid.'/fork', '', { "Authorization": s:GetAuthHeader() }) - let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') - if status =~ '^2' - let obj = webapi#json#decode(res.content) - let gistid = obj["id"] - else - echohl ErrorMsg | echomsg 'Fork failed' | echohl None + let auth = s:GetAuthHeader() + if len(auth) == 0 + echohl ErrorMsg | echomsg 'Canceled' | echohl None return + else + let gistid = gistidbuf + let res = webapi#http#post('https://api.github.com/gists/'.gistid.'/fork', '', { "Authorization": auth }) + let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') + if status =~ '^2' + let obj = webapi#json#decode(res.content) + let gistid = obj["id"] + else + echohl ErrorMsg | echomsg 'Fork failed' | echohl None + return + endif endif elseif arg !~ '^-' && len(gistnm) == 0 if gistdesc != ' ' @@ -639,22 +697,32 @@ function! s:GetAuthHeader() echohl WarningMsg echo 'Gist.vim requires authorization to use the Github API. These settings are stored in "~/.gist-vim". If you want to revoke, do "rm ~/.gist-vim".' echohl None - redraw | echo "\r" let password = inputsecret("Github Password for ".g:github_user.":") - let insecureSecret = printf("basic %s", webapi#base64#b64encode(g:github_user.":".password)) - let res = webapi#http#post('https://api.github.com/authorizations', webapi#json#encode({ - \ "scopes" : ["gist"], - \ "note" : "Gist.vim on ".hostname(), - \ "note_url" : "http://www.vim.org/scripts/script.php?script_id=2423" - \}), { - \ "Content-Type" : "application/json", - \ "Authorization" : insecureSecret, - \}) - let authorization = webapi#json#decode(res.content) - let secret = printf("token %s", authorization.token) - call writefile([secret], s:configfile) - if !(has('win32') || has('win64')) - call system("chmod go= ".s:configfile) + if len(password) > 0 + let insecureSecret = printf("basic %s", webapi#base64#b64encode(g:github_user.":".password)) + let res = webapi#http#post('https://api.github.com/authorizations', webapi#json#encode({ + \ "scopes" : ["gist"], + \ "note" : "Gist.vim on ".hostname(), + \ "note_url" : "http://www.vim.org/scripts/script.php?script_id=2423" + \}), { + \ "Content-Type" : "application/json", + \ "Authorization" : insecureSecret, + \}) + let authorization = webapi#json#decode(res.content) + if has_key(authorization, 'token') + let secret = printf("token %s", authorization.token) + call writefile([secret], s:configfile) + if !(has('win32') || has('win64')) + call system("chmod go= ".s:configfile) + endif + elseif has_key(authorization, 'message') + echohl WarningMsg + echo authorization.message + echohl None + let secret = '' + endif + else + let secret = '' endif return secret endfunction From f45d9383c6286250f910043573a976889a6798db Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 9 Jul 2012 12:11:57 +0900 Subject: [PATCH 050/170] update doc. --- gist.vim.vimup | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/gist.vim.vimup b/gist.vim.vimup index dfe1f65..32dd1af 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -2,7 +2,7 @@ script_name: Gist.vim script_id: '2423' script_type: utility script_package: gist-vim.zip -script_version: '6.7' +script_version: '6.8' required_vim_version: '7.0' summary: vimscript for gist @@ -36,11 +36,11 @@ detailed_description: | :Gist -d delete the gist. (should be work on gist buffer) - password authentication is needed. + authentication required. :Gist -f fork the gist. (should be work on gist buffer) - password authentication is needed. + authentication required. :Gist XXXXX get gist XXXXX. @@ -98,20 +98,12 @@ install_details: | plugin/gist.vim cookies/github - if you want to uninstall gist.vim, you have better to remove 'cookies/github'. - - for using gist.vim, you should install git. or set g:github_user and g:github_token into your vimrc. - note that g:github_token is NOT a your password. - - how get your token. - 1. login to github. - 2. click "Account Settings" - 3. click "Account Admin" - 4. you'll see it at following of 'API Token'. - See also: https://github.com/mattn/gist-vim/blob/master/README.mkd versions: +- '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%'. From ee9c5d31765221bdfa943416eb5bb01c49a2e7da Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 18 Jul 2012 11:13:00 +0900 Subject: [PATCH 051/170] :Gist --help --- autoload/gist.vim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 954e2df..bb67870 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 09-Jul-2012. +" Last Change: 18-Jul-2012. " Version: 6.8 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -516,7 +516,10 @@ function! gist#Gist(count, line1, line2, ...) let args = (a:0 > 0) ? s:shellwords(a:1) : [] for arg in args - if arg =~ '^\(-la\|--listall\)$\C' + if arg =~ '^\(-h\|--help\)$\C' + help :Gist + return + elseif arg =~ '^\(-la\|--listall\)$\C' let gistls = '-all' elseif arg =~ '^\(-ls\|--liststar\)$\C' let gistls = 'starred' From aad7fb31849c548ec21fcb018e2bf49629f4f290 Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 18 Jul 2012 21:48:03 +0900 Subject: [PATCH 052/170] use webapi#system_function. --- autoload/gist.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index bb67870..d47fd65 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -12,7 +12,8 @@ set cpo&vim let s:configfile = expand('~/.gist-vim') if !exists('g:github_user') - let g:github_user = substitute(system('git config --get github.user'), "\n", '', '') + let s:system = function(get(g:, 'webapi#system_function', 'system')) + let g:github_user = substitute(s:system('git config --get github.user'), "\n", '', '') if strlen(g:github_user) == 0 let g:github_user = $GITHUB_USER end From 3ce33313fb55c7b7db6e85796af050bc1eb5fb48 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 7 Aug 2012 10:54:46 +0900 Subject: [PATCH 053/170] fix browser command for mac. close #91 --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index d47fd65..5598a0d 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 18-Jul-2012. +" Last Change: 07-Aug-2012. " Version: 6.8 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -24,7 +24,7 @@ function! s:get_browser_command() if gist_browser_command == '' if has('win32') || has('win64') let gist_browser_command = '!start rundll32 url.dll,FileProtocolHandler %URL%' - elseif has('mac') + elseif has('mac') || has('macunix') || has('gui_macvim') || system('uname') =~? '^darwin' let gist_browser_command = 'open %URL%' elseif executable('xdg-open') let gist_browser_command = 'xdg-open %URL%' From 38d91f8cae0561c5d5c4fe740ef6a275812fc070 Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 7 Sep 2012 10:44:16 +0900 Subject: [PATCH 054/170] fix an error E303. --- autoload/gist.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 5598a0d..ef8b641 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 07-Aug-2012. +" Last Change: 07-Sep-2012. " Version: 6.8 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -225,7 +225,8 @@ function! s:GistGet(gistid, clipboard) endif setlocal modifiable else - exec 'silent noautocmd split' s:bufprefix.a:gistid."/".fnameescape(filename) + exec 'silent noautocmd new' + exec 'noautocmd file' s:bufprefix.a:gistid."/".fnameescape(filename) endif set undolevels=-1 filetype detect From e1e5e63081e887b86b9113ee1503a379a3f15f6b Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 7 Sep 2012 11:09:08 +0900 Subject: [PATCH 055/170] set noswapfile. --- autoload/gist.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/autoload/gist.vim b/autoload/gist.vim index ef8b641..0246b60 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -226,6 +226,7 @@ function! s:GistGet(gistid, clipboard) setlocal modifiable else exec 'silent noautocmd new' + setlocal noswapfile exec 'noautocmd file' s:bufprefix.a:gistid."/".fnameescape(filename) endif set undolevels=-1 From e8fad4a8b9e2d88e3e4a538b9f2c9317191fafdb Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 7 Sep 2012 11:14:09 +0900 Subject: [PATCH 056/170] version bump up. --- autoload/gist.vim | 2 +- gist.vim.vimup | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 0246b60..a222a31 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -2,7 +2,7 @@ " File: gist.vim " Author: Yasuhiro Matsumoto " Last Change: 07-Sep-2012. -" Version: 6.8 +" Version: 6.9 " WebPage: http://github.com/mattn/gist-vim " License: BSD diff --git a/gist.vim.vimup b/gist.vim.vimup index 32dd1af..3d126a4 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -2,7 +2,7 @@ script_name: Gist.vim script_id: '2423' script_type: utility script_package: gist-vim.zip -script_version: '6.8' +script_version: '6.9' required_vim_version: '7.0' summary: vimscript for gist @@ -101,6 +101,9 @@ install_details: | See also: https://github.com/mattn/gist-vim/blob/master/README.mkd versions: +- '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. From b8e046fbbc17e5f3fd22d84b22ae8982e2fdc814 Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 12 Sep 2012 17:50:00 +0900 Subject: [PATCH 057/170] rename. --- autoload/gist.vim | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index a222a31..656f11c 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 07-Sep-2012. +" Last Change: 12-Sep-2012. " Version: 6.9 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -113,7 +113,7 @@ function! s:GistList(gistls, page) silent %d _ redraw | echon 'Listing gists... ' - let auth = s:GetAuthHeader() + let auth = s:GistGetAuthHeader() if len(auth) == 0 bw! redraw @@ -157,8 +157,28 @@ function! s:GistList(gistls, page) redraw | echo '' endfunction +function! gist#list(user, ...) + let page = get(a:000, 0, 0) + if a:user == '-all' + let url = 'https://api.github.com/gists/public' + elseif get(g:, 'gist_show_privates', 0) && a:user == 'starred' + let url = 'https://api.github.com/gists/starred' + elseif get(g:, 'gist_show_privates') && a:user == 'mine' + let url = 'https://api.github.com/gists' + else + let url = 'https://api.github.com/users/'.a:user.'/gists' + endif + + let auth = s:GistGetAuthHeader() + if len(auth) == 0 + return [] + endif + let res = webapi#http#get(url, '', { "Authorization": auth }) + return webapi#json#decode(res.content) +endfunction + function! s:GistGetFileName(gistid) - let auth = s:GetAuthHeader() + let auth = s:GistGetAuthHeader() if len(auth) == 0 return '' endif @@ -171,7 +191,7 @@ function! s:GistGetFileName(gistid) endfunction function! s:GistDetectFiletype(gistid) - let auth = s:GetAuthHeader() + let auth = s:GistGetAuthHeader() if len(auth) == 0 return '' endif @@ -199,7 +219,7 @@ endfunction function! s:GistGet(gistid, clipboard) redraw | echon 'Getting gist... ' - let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() }) + let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GistGetAuthHeader() }) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' let gist = webapi#json#decode(res.content) @@ -306,7 +326,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) if len(filename) == 0 | let filename = s:get_current_filename(1) | endif endif - let auth = s:GetAuthHeader() + let auth = s:GistGetAuthHeader() if len(auth) == 0 redraw echohl ErrorMsg | echomsg 'Canceled' | echohl None @@ -350,7 +370,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) endfunction function! s:GistDelete(gistid) - let auth = s:GetAuthHeader() + let auth = s:GistGetAuthHeader() if len(auth) == 0 redraw echohl ErrorMsg | echomsg 'Canceled' | echohl None @@ -412,7 +432,7 @@ function! s:GistPost(content, private, desc, anonymous) let header = {"Content-Type": "application/json"} if !a:anonymous - let auth = s:GetAuthHeader() + let auth = s:GistGetAuthHeader() if len(auth) == 0 redraw echohl ErrorMsg | echomsg 'Canceled' | echohl None @@ -551,7 +571,7 @@ function! gist#Gist(count, line1, line2, ...) let gistid = gistidbuf let editpost = 1 elseif arg =~ '^\(+1\|--star\)$\C' && gistidbuf != '' - let auth = s:GetAuthHeader() + let auth = s:GistGetAuthHeader() if len(auth) == 0 echohl ErrorMsg | echomsg 'Canceled' | echohl None else @@ -566,7 +586,7 @@ function! gist#Gist(count, line1, line2, ...) endif return elseif arg =~ '^\(-1\|--unstar\)$\C' && gistidbuf != '' - let auth = s:GetAuthHeader() + let auth = s:GistGetAuthHeader() if len(auth) == 0 echohl ErrorMsg | echomsg 'Canceled' | echohl None else @@ -580,7 +600,7 @@ function! gist#Gist(count, line1, line2, ...) endif return elseif arg =~ '^\(-f\|--fork\)$\C' && gistidbuf != '' - let auth = s:GetAuthHeader() + let auth = s:GistGetAuthHeader() if len(auth) == 0 echohl ErrorMsg | echomsg 'Canceled' | echohl None return @@ -682,7 +702,7 @@ function! gist#Gist(count, line1, line2, ...) return 1 endfunction -function! s:GetAuthHeader() +function! s:GistGetAuthHeader() if get(g:, 'gist_use_password_in_gitconfig', 0) != 0 let password = substitute(system('git config --get github.password'), "\n", '', '') if password =~ '^!' | let password = system(password[1:]) | endif From f4854dfb21e5cef738dfc1d9103a19c2c3f0ad40 Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 12 Sep 2012 17:58:36 +0900 Subject: [PATCH 058/170] fix message. --- autoload/gist.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 656f11c..a6446f0 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -228,8 +228,8 @@ function! s:GistGet(gistid, clipboard) else let num_file = 1 endif + redraw if num_file > len(keys(gist.files)) - redraw echohl ErrorMsg | echomsg 'Gist not found' | echohl None return endif From 74128d2965bb79ce72b47372428a99cbcdf26afe Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 20 Sep 2012 10:45:24 +0900 Subject: [PATCH 059/170] fix filetype for markdown. --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index a6446f0..e49ec18 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 12-Sep-2012. +" Last Change: 20-Sep-2012. " Version: 6.9 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -824,7 +824,7 @@ let s:extmap = { \".man": "man", \".mao": "mao", \".matlab": "matlab", -\".md": "md", +\".md": "markdown", \".minid": "minid", \".ml": "ml", \".moo": "moo", From 1b273a5bc7bf0309cd8566ddfd27b9226464c040 Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 26 Sep 2012 19:47:58 +0900 Subject: [PATCH 060/170] fixed -m --- autoload/gist.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index e49ec18..b121da4 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 20-Sep-2012. +" Last Change: 26-Sep-2012. " Version: 6.9 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -487,6 +487,7 @@ function! s:GistPostBuffers(private, desc, anonymous) let header = {"Content-Type": "application/json"} if !a:anonymous + let auth = s:GistGetAuthHeader() if len(auth) == 0 redraw echohl ErrorMsg | echomsg 'Canceled' | echohl None From b41d650e38828c908e5c86d32745c5068e694a03 Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 27 Sep 2012 08:43:22 +0900 Subject: [PATCH 061/170] version bump up. --- autoload/gist.vim | 4 ++-- gist.vim.vimup | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index b121da4..d14ccf1 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,8 +1,8 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 26-Sep-2012. -" Version: 6.9 +" Last Change: 27-Sep-2012. +" Version: 7.0 " WebPage: http://github.com/mattn/gist-vim " License: BSD diff --git a/gist.vim.vimup b/gist.vim.vimup index 3d126a4..d6ce450 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -2,7 +2,7 @@ script_name: Gist.vim script_id: '2423' script_type: utility script_package: gist-vim.zip -script_version: '6.9' +script_version: '7.0' required_vim_version: '7.0' summary: vimscript for gist @@ -101,6 +101,9 @@ install_details: | See also: https://github.com/mattn/gist-vim/blob/master/README.mkd versions: +- '7.0': | + This is an upgrade for Gist.vim: fixed few bugs. + - '6.9': | This is an upgrade for Gist.vim: fixed few bugs. From 7b9152faf89cd86b7910144b0570e944f099822b Mon Sep 17 00:00:00 2001 From: superbrothers Date: Wed, 10 Oct 2012 20:52:24 +0900 Subject: [PATCH 062/170] support Github Enterprise let g:github_api_url = 'http://your-github-enterprise-domain/api/v3' --- README.mkd | 4 ++++ autoload/gist.vim | 44 ++++++++++++++++++++++++-------------------- doc/gist-vim.txt | 5 +++++ 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/README.mkd b/README.mkd index 6bf4c45..63041cd 100644 --- a/README.mkd +++ b/README.mkd @@ -142,6 +142,10 @@ If you want to manipulate multiple files in a gist: let g:gist_get_multiplefile = 1 +If you want to use on Github Enterprise: + + let g:github_api_url = 'http://your-github-enterprise-domain/api/v3' + You need to either set global git config: $ git config --global github.user Username diff --git a/autoload/gist.vim b/autoload/gist.vim index d14ccf1..a80cd23 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -19,6 +19,10 @@ if !exists('g:github_user') end endif +if !exists('g:github_api_url') + let g:github_api_url = 'https://api.github.com' +endif + function! s:get_browser_command() let gist_browser_command = get(g:, 'gist_browser_command', '') if gist_browser_command == '' @@ -85,13 +89,13 @@ endfunction let s:bufprefix = 'gist' . (has('unix') ? ':' : '_') function! s:GistList(gistls, page) if a:gistls == '-all' - let url = 'https://api.github.com/gists/public' + let url = g:github_api_url.'/gists/public' elseif get(g:, 'gist_show_privates', 0) && a:gistls == 'starred' - let url = 'https://api.github.com/gists/starred' + let url = g:github_api_url.'/gists/starred' elseif get(g:, 'gist_show_privates') && a:gistls == 'mine' - let url = 'https://api.github.com/gists' + let url = g:github_api_url.'/gists' else - let url = 'https://api.github.com/users/'.a:gistls.'/gists' + let url = g:github_api_url.'/users/'.a:gistls.'/gists' endif let winnum = bufwinnr(bufnr(s:bufprefix.a:gistls)) if winnum != -1 @@ -160,13 +164,13 @@ endfunction function! gist#list(user, ...) let page = get(a:000, 0, 0) if a:user == '-all' - let url = 'https://api.github.com/gists/public' + let url = g:github_api_url.'/gists/public' elseif get(g:, 'gist_show_privates', 0) && a:user == 'starred' - let url = 'https://api.github.com/gists/starred' + let url = g:github_api_url.'/gists/starred' elseif get(g:, 'gist_show_privates') && a:user == 'mine' - let url = 'https://api.github.com/gists' + let url = g:github_api_url.'/gists' else - let url = 'https://api.github.com/users/'.a:user.'/gists' + let url = g:github_api_url.'/users/'.a:user.'/gists' endif let auth = s:GistGetAuthHeader() @@ -182,7 +186,7 @@ function! s:GistGetFileName(gistid) if len(auth) == 0 return '' endif - let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": auth }) + let res = webapi#http#get(g:github_api_url.'/gists/'.a:gistid, '', { "Authorization": auth }) let gist = webapi#json#decode(res.content) if has_key(gist, 'files') return sort(keys(gist.files))[0] @@ -195,7 +199,7 @@ function! s:GistDetectFiletype(gistid) if len(auth) == 0 return '' endif - let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": auth }) + let res = webapi#http#get(g:github_api_url.'/gists/'.a:gistid, '', { "Authorization": auth }) let gist = webapi#json#decode(res.content) let filename = sort(keys(gist.files))[0] let ext = fnamemodify(filename, ':e') @@ -219,7 +223,7 @@ endfunction function! s:GistGet(gistid, clipboard) redraw | echon 'Getting gist... ' - let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GistGetAuthHeader() }) + let res = webapi#http#get(g:github_api_url.'/gists/'.a:gistid, '', { "Authorization": s:GistGetAuthHeader() }) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' let gist = webapi#json#decode(res.content) @@ -338,7 +342,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) if a:desc != ' ' let gist["description"] = a:desc else - let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": auth }) + let res = webapi#http#get(g:github_api_url.'/gists/'.a:gistid, '', { "Authorization": auth }) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' let old_gist = webapi#json#decode(res.content) @@ -349,7 +353,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) let gist.files[filename] = { "content": a:content, "filename": filename } redraw | echon 'Updating gist... ' - let res = webapi#http#post('https://api.github.com/gists/' . a:gistid, + let res = webapi#http#post(g:github_api_url.'/gists/' . a:gistid, \ webapi#json#encode(gist), { \ "Authorization": auth, \ "Content-Type": "application/json", @@ -378,7 +382,7 @@ function! s:GistDelete(gistid) endif redraw | echon 'Deleting gist... ' - let res = webapi#http#post('https://api.github.com/gists/'.a:gistid, '', { + let res = webapi#http#post(g:github_api_url.'/gists/'.a:gistid, '', { \ "Authorization": auth, \ "Content-Type": "application/json", \}, 'DELETE') @@ -442,7 +446,7 @@ function! s:GistPost(content, private, desc, anonymous) endif redraw | echon 'Posting it to gist... ' - let res = webapi#http#post('https://api.github.com/gists', webapi#json#encode(gist), header) + let res = webapi#http#post(g:github_api_url.'/gists', webapi#json#encode(gist), header) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' let obj = webapi#json#decode(res.content) @@ -497,7 +501,7 @@ function! s:GistPostBuffers(private, desc, anonymous) endif redraw | echon 'Posting it to gist... ' - let res = webapi#http#post('https://api.github.com/gists', webapi#json#encode(gist), header) + let res = webapi#http#post(g:github_api_url.'/gists', webapi#json#encode(gist), header) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' let obj = webapi#json#decode(res.content) @@ -577,7 +581,7 @@ function! gist#Gist(count, line1, line2, ...) echohl ErrorMsg | echomsg 'Canceled' | echohl None else let gistid = gistidbuf - let res = webapi#http#post('https://api.github.com/gists/'.gistid.'/star', '', { "Authorization": auth }, 'PUT') + let res = webapi#http#post(g:github_api_url.'/gists/'.gistid.'/star', '', { "Authorization": auth }, 'PUT') let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' echomsg "Stared" gistid @@ -592,7 +596,7 @@ function! gist#Gist(count, line1, line2, ...) echohl ErrorMsg | echomsg 'Canceled' | echohl None else let gistid = gistidbuf - let res = webapi#http#post('https://api.github.com/gists/'.gistid.'/star', '', { "Authorization": auth }, 'DELETE') + let res = webapi#http#post(g:github_api_url.'/gists/'.gistid.'/star', '', { "Authorization": auth }, 'DELETE') if status =~ '^2' echomsg "Unstared" gistid else @@ -607,7 +611,7 @@ function! gist#Gist(count, line1, line2, ...) return else let gistid = gistidbuf - let res = webapi#http#post('https://api.github.com/gists/'.gistid.'/fork', '', { "Authorization": auth }) + let res = webapi#http#post(g:github_api_url.'/gists/'.gistid.'/fork', '', { "Authorization": auth }) let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') if status =~ '^2' let obj = webapi#json#decode(res.content) @@ -727,7 +731,7 @@ function! s:GistGetAuthHeader() let password = inputsecret("Github Password for ".g:github_user.":") if len(password) > 0 let insecureSecret = printf("basic %s", webapi#base64#b64encode(g:github_user.":".password)) - let res = webapi#http#post('https://api.github.com/authorizations', webapi#json#encode({ + let res = webapi#http#post(g:github_api_url.'/authorizations', webapi#json#encode({ \ "scopes" : ["gist"], \ "note" : "Gist.vim on ".hostname(), \ "note_url" : "http://www.vim.org/scripts/script.php?script_id=2423" diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index b9a54e8..348b26c 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -147,6 +147,11 @@ If you want to edit all files for gists containing more than one: > let g:gist_get_multiplefile = 1 < +If you want to use on Github Enterprise: > + + let g:github_api_url = 'http://your-github-enterprise-domain/api/v3' +< + If you want to update a gist, embed > GistID: xxxxx From 61012e56f8e897bb646fd79e83b487be06d4a475 Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 13 Dec 2012 09:28:12 +0900 Subject: [PATCH 063/170] move checking part to autoload. --- autoload/gist.vim | 12 +++++++++++- plugin/gist.vim | 10 ---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index a80cd23..90ca4ba 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 27-Sep-2012. +" Last Change: 03-Dec-2012. " Version: 7.0 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -9,6 +9,16 @@ let s:save_cpo = &cpo set cpo&vim +if !exists('g:github_user') && !executable('git') + echohl ErrorMsg | echomsg "Gist: require 'git' command" | echohl None + finish +endif + +if !executable('curl') + echohl ErrorMsg | echomsg "Gist: require 'curl' command" | echohl None + finish +endif + let s:configfile = expand('~/.gist-vim') if !exists('g:github_user') diff --git a/plugin/gist.vim b/plugin/gist.vim index e94687c..973d300 100644 --- a/plugin/gist.vim +++ b/plugin/gist.vim @@ -11,16 +11,6 @@ if &cp || (exists('g:loaded_gist_vim') && g:loaded_gist_vim) endif let g:loaded_gist_vim = 1 -if !exists('g:github_user') && !executable('git') - echohl ErrorMsg | echomsg "Gist: require 'git' command" | echohl None - finish -endif - -if !executable('curl') - echohl ErrorMsg | echomsg "Gist: require 'curl' command" | echohl None - finish -endif - command! -nargs=? -range=% Gist :call gist#Gist(, , , ) " vim:set et: From 0fe42d8abd468065589a45889bc9de755b42350d Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 13 Dec 2012 09:28:30 +0900 Subject: [PATCH 064/170] updated doc. --- README.mkd | 2 +- doc/gist-vim.txt | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/README.mkd b/README.mkd index 63041cd..288a1e9 100644 --- a/README.mkd +++ b/README.mkd @@ -187,8 +187,8 @@ Copy it to your plugin directory. gist.vim will create a curl cookie-jar file in your runtimepath. - rtp: + - autoload/gist.vim - plugin/gist.vim - - cookies/github If you want to uninstall gist.vim, remember to also remove `~/.gist-vim`. diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 348b26c..66ecd6f 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -196,16 +196,13 @@ LICENSE *gist-vim-license* ============================================================================== INSTALL *gist-vim-install* -Copy gist.vim to your plugin directory. - -gist.vim will create a curl cookie-jar file in your runtimepath. +Copy following files into your plugin directory. rtp: + - autoload/gist.vim - plugin/gist.vim - - cookies/github - -If you want to uninstall gist.vim, remember to also remove "cookies/github". +If you want to uninstall gist.vim, remember to also remove `~/.gist-vim`. ============================================================================== SETUP *gist-vim-setup* From 04209912ef63b090af60e6bb3c5231c5dcaa7866 Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 13 Dec 2012 09:31:33 +0900 Subject: [PATCH 065/170] updated doc. --- README.mkd | 8 ++++++++ doc/gist-vim.txt | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/README.mkd b/README.mkd index 288a1e9..0a95ee7 100644 --- a/README.mkd +++ b/README.mkd @@ -192,6 +192,14 @@ gist.vim will create a curl cookie-jar file in your runtimepath. If you want to uninstall gist.vim, remember to also remove `~/.gist-vim`. +You need to install webapi-vim also: + + http://www.vim.org/scripts/script.php?script_id=4019 + +If you want to use latest one: + + https://github.com/mattn/webapi-vim + ## Setup: This plugin uses github API v3. Setting value is stored in `~/.gist-vim`. diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 66ecd6f..424915d 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -203,6 +203,14 @@ rtp: - plugin/gist.vim If you want to uninstall gist.vim, remember to also remove `~/.gist-vim`. + +You need to install webapi-vim also: + + http://www.vim.org/scripts/script.php?script_id=4019 + +If you want to use latest one: + + https://github.com/mattn/webapi-vim ============================================================================== SETUP *gist-vim-setup* From b2a52f9372670a9d7680aba6dc7b02fbb4753d5e Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 13 Dec 2012 09:32:41 +0900 Subject: [PATCH 066/170] updated doc. --- README.mkd | 12 ++++++------ doc/gist-vim.txt | 17 +++++++++-------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/README.mkd b/README.mkd index 0a95ee7..f03acc6 100644 --- a/README.mkd +++ b/README.mkd @@ -150,12 +150,6 @@ You need to either set global git config: $ git config --global github.user Username -## Requirements: - -- curl command (http://curl.haxx.se/) -- webapi-vim (https://github.com/mattn/webapi-vim) -- and if you want to use your git profile, the git command-line client. - ## License: Copyright 2010 by Yasuhiro Matsumoto @@ -200,6 +194,12 @@ If you want to use latest one: https://github.com/mattn/webapi-vim +## Requirements: + +- curl command (http://curl.haxx.se/) +- webapi-vim (https://github.com/mattn/webapi-vim) +- and if you want to use your git profile, the git command-line client. + ## Setup: This plugin uses github API v3. Setting value is stored in `~/.gist-vim`. diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 424915d..2f9d4c8 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -2,9 +2,9 @@ Usage |gist-vim-usage| Tips |gist-vim-tips| -Requirements |gist-vim-requirements| License |gist-vim-license| Install |gist-vim-install| +Requirements |gist-vim-requirements| Setup |gist-vim-setup| This is a vimscript for creating gists (http://gist.github.com) @@ -160,13 +160,6 @@ in your local file, then call > :Gist > -============================================================================== -REQUIREMENTS *gist-vim-requirements* - - - curl command (http://curl.haxx.se/) - - webapi-vim (https://github.com/mattn/webapi-vim) - - and, if you want to use your git profile, the git command-line client. - ============================================================================== LICENSE *gist-vim-license* @@ -211,6 +204,14 @@ You need to install webapi-vim also: If you want to use latest one: https://github.com/mattn/webapi-vim + +============================================================================== +REQUIREMENTS *gist-vim-requirements* + + - curl command (http://curl.haxx.se/) + - webapi-vim (https://github.com/mattn/webapi-vim) + - and, if you want to use your git profile, the git command-line client. + ============================================================================== SETUP *gist-vim-setup* From 28c34862d5d1fb6013c78046f95493b309ec94f0 Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 13 Dec 2012 09:34:05 +0900 Subject: [PATCH 067/170] version bump up. --- autoload/gist.vim | 4 ++-- gist.vim.vimup | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 90ca4ba..d6e8f18 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,8 +1,8 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 03-Dec-2012. -" Version: 7.0 +" Last Change: 13-Dec-2012. +" Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD diff --git a/gist.vim.vimup b/gist.vim.vimup index d6ce450..96e6a30 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -2,7 +2,7 @@ script_name: Gist.vim script_id: '2423' script_type: utility script_package: gist-vim.zip -script_version: '7.0' +script_version: '7.1' required_vim_version: '7.0' summary: vimscript for gist @@ -101,6 +101,9 @@ install_details: | See also: https://github.com/mattn/gist-vim/blob/master/README.mkd versions: +- '7.1': | + This is an upgrade for Gist.vim: updated installation notes. + - '7.0': | This is an upgrade for Gist.vim: fixed few bugs. From ba82d81d8b3eefa0d15aa9d4bd2bc7ddca60d2cc Mon Sep 17 00:00:00 2001 From: Jeremy Mack Date: Wed, 19 Dec 2012 13:55:43 -0500 Subject: [PATCH 068/170] Added installation instructions for Vundle Useful especially since gist-vim requires two bundles to function. --- README.mkd | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.mkd b/README.mkd index f03acc6..75daa9c 100644 --- a/README.mkd +++ b/README.mkd @@ -193,6 +193,15 @@ You need to install webapi-vim also: If you want to use latest one: https://github.com/mattn/webapi-vim + +### Install with [Vundle](https://github.com/gmarik/vundle) + +Add the following lines to your `.vimrc`. + + Bundle 'mattn/webapi-vim' + Bundle 'mattn/gist-vim' + +Now restart Vim and run `:BundleInstall`. ## Requirements: From 82f842d0f867a9fa00fb77a4a3de632cec951097 Mon Sep 17 00:00:00 2001 From: tyru Date: Sun, 6 Jan 2013 23:17:41 +0900 Subject: [PATCH 069/170] add g:gist_update_on_write and its help --- autoload/gist.vim | 10 ++++++++-- doc/gist-vim.txt | 12 ++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index d6e8f18..b5ef589 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 13-Dec-2012. +" Last Change: 06-Jan-2013. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -33,6 +33,10 @@ if !exists('g:github_api_url') let g:github_api_url = 'https://api.github.com' endif +if !exists('g:gist_update_on_write') + let g:gist_update_on_write = 1 +endif + function! s:get_browser_command() let gist_browser_command = get(g:, 'gist_browser_command', '') if gist_browser_command == '' @@ -223,7 +227,9 @@ endfunction function! s:GistWrite(fname) if substitute(a:fname, '\\', '/', 'g') == expand("%:p:gs@\\@/@") - Gist -e + if g:gist_update_on_write != 2 || v:cmdbang + Gist -e + endif else exe "w".(v:cmdbang ? "!" : "") fnameescape(v:cmdarg) fnameescape(a:fname) silent! exe "file" fnameescape(a:fname) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 2f9d4c8..b9fca32 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -160,6 +160,18 @@ in your local file, then call > :Gist > + +If you want to update a gist when only |:w!|: > + + " :w and :w! update a gist. + let g:gist_update_on_write = 1 + + " Only :w! updates a gist. + let g:gist_update_on_write = 2 +> +All other values are treated as 1. +This variable's value is 1 by default. + ============================================================================== LICENSE *gist-vim-license* From a5e308a17ca67bdb30a40713463e20740072c3a1 Mon Sep 17 00:00:00 2001 From: tyru Date: Mon, 7 Jan 2013 21:01:34 +0900 Subject: [PATCH 070/170] raise 'E21: Cannot make changes' error --- autoload/gist.vim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index b5ef589..16b88b6 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 06-Jan-2013. +" Last Change: 07-Jan-2013. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -229,6 +229,13 @@ function! s:GistWrite(fname) if substitute(a:fname, '\\', '/', 'g') == expand("%:p:gs@\\@/@") if g:gist_update_on_write != 2 || v:cmdbang Gist -e + else + setlocal nomodifiable + try + normal! i + finally + setlocal modifiable + endtry endif else exe "w".(v:cmdbang ? "!" : "") fnameescape(v:cmdarg) fnameescape(a:fname) From 126c8cb6eab91bf05040b0bd4c08c5ac5746f402 Mon Sep 17 00:00:00 2001 From: tyru Date: Tue, 8 Jan 2013 20:57:45 +0900 Subject: [PATCH 071/170] echo more understandable error message to user --- autoload/gist.vim | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 16b88b6..f13f507 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 07-Jan-2013. +" Last Change: 08-Jan-2013. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -230,12 +230,7 @@ function! s:GistWrite(fname) if g:gist_update_on_write != 2 || v:cmdbang Gist -e else - setlocal nomodifiable - try - normal! i - finally - setlocal modifiable - endtry + echohl ErrorMsg | echomsg 'Please type ":w!" to update a gist.' | echohl None endif else exe "w".(v:cmdbang ? "!" : "") fnameescape(v:cmdarg) fnameescape(a:fname) From 6732c630531270cf6132af77aea4169edb96d2bf Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 21 Jan 2013 13:54:31 +0900 Subject: [PATCH 072/170] better error message. close #114 --- autoload/gist.vim | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index d6e8f18..f410572 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 13-Dec-2012. +" Last Change: 21-Jan-2013. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -131,7 +131,7 @@ function! s:GistList(gistls, page) if len(auth) == 0 bw! redraw - echohl ErrorMsg | echomsg 'Canceled' | echohl None + echohl ErrorMsg | echomsg v:errmsg | echohl None return endif let res = webapi#http#get(url, '', { "Authorization": auth }) @@ -343,7 +343,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) let auth = s:GistGetAuthHeader() if len(auth) == 0 redraw - echohl ErrorMsg | echomsg 'Canceled' | echohl None + echohl ErrorMsg | echomsg v:errmsg | echohl None return endif @@ -387,7 +387,7 @@ function! s:GistDelete(gistid) let auth = s:GistGetAuthHeader() if len(auth) == 0 redraw - echohl ErrorMsg | echomsg 'Canceled' | echohl None + echohl ErrorMsg | echomsg v:errmsg | echohl None return endif @@ -449,7 +449,7 @@ function! s:GistPost(content, private, desc, anonymous) let auth = s:GistGetAuthHeader() if len(auth) == 0 redraw - echohl ErrorMsg | echomsg 'Canceled' | echohl None + echohl ErrorMsg | echomsg v:errmsg | echohl None return endif let header["Authorization"] = auth @@ -504,7 +504,7 @@ function! s:GistPostBuffers(private, desc, anonymous) let auth = s:GistGetAuthHeader() if len(auth) == 0 redraw - echohl ErrorMsg | echomsg 'Canceled' | echohl None + echohl ErrorMsg | echomsg v:errmsg | echohl None return endif let header["Authorization"] = auth @@ -588,7 +588,7 @@ function! gist#Gist(count, line1, line2, ...) elseif arg =~ '^\(+1\|--star\)$\C' && gistidbuf != '' let auth = s:GistGetAuthHeader() if len(auth) == 0 - echohl ErrorMsg | echomsg 'Canceled' | echohl None + echohl ErrorMsg | echomsg v:errmsg | echohl None else let gistid = gistidbuf let res = webapi#http#post(g:github_api_url.'/gists/'.gistid.'/star', '', { "Authorization": auth }, 'PUT') @@ -603,7 +603,7 @@ function! gist#Gist(count, line1, line2, ...) elseif arg =~ '^\(-1\|--unstar\)$\C' && gistidbuf != '' let auth = s:GistGetAuthHeader() if len(auth) == 0 - echohl ErrorMsg | echomsg 'Canceled' | echohl None + echohl ErrorMsg | echomsg v:errmsg | echohl None else let gistid = gistidbuf let res = webapi#http#post(g:github_api_url.'/gists/'.gistid.'/star', '', { "Authorization": auth }, 'DELETE') @@ -617,7 +617,7 @@ function! gist#Gist(count, line1, line2, ...) elseif arg =~ '^\(-f\|--fork\)$\C' && gistidbuf != '' let auth = s:GistGetAuthHeader() if len(auth) == 0 - echohl ErrorMsg | echomsg 'Canceled' | echohl None + echohl ErrorMsg | echomsg v:errmsg | echohl None return else let gistid = gistidbuf @@ -757,13 +757,12 @@ function! s:GistGetAuthHeader() call system("chmod go= ".s:configfile) endif elseif has_key(authorization, 'message') - echohl WarningMsg - echo authorization.message - echohl None let secret = '' + let v:errmsg = authorization.message endif else let secret = '' + let v:errmsg = 'Canceled' endif return secret endfunction From a84af49b69f6785fd4c125d20ba888db5548fddd Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 21 Jan 2013 13:55:28 +0900 Subject: [PATCH 073/170] merge conflict. --- autoload/gist.vim | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index f13f507..98e725d 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 08-Jan-2013. +" Last Change: 21-Jan-2013. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -135,7 +135,7 @@ function! s:GistList(gistls, page) if len(auth) == 0 bw! redraw - echohl ErrorMsg | echomsg 'Canceled' | echohl None + echohl ErrorMsg | echomsg v:errmsg | echohl None return endif let res = webapi#http#get(url, '', { "Authorization": auth }) @@ -351,7 +351,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) let auth = s:GistGetAuthHeader() if len(auth) == 0 redraw - echohl ErrorMsg | echomsg 'Canceled' | echohl None + echohl ErrorMsg | echomsg v:errmsg | echohl None return endif @@ -395,7 +395,7 @@ function! s:GistDelete(gistid) let auth = s:GistGetAuthHeader() if len(auth) == 0 redraw - echohl ErrorMsg | echomsg 'Canceled' | echohl None + echohl ErrorMsg | echomsg v:errmsg | echohl None return endif @@ -457,7 +457,7 @@ function! s:GistPost(content, private, desc, anonymous) let auth = s:GistGetAuthHeader() if len(auth) == 0 redraw - echohl ErrorMsg | echomsg 'Canceled' | echohl None + echohl ErrorMsg | echomsg v:errmsg | echohl None return endif let header["Authorization"] = auth @@ -512,7 +512,7 @@ function! s:GistPostBuffers(private, desc, anonymous) let auth = s:GistGetAuthHeader() if len(auth) == 0 redraw - echohl ErrorMsg | echomsg 'Canceled' | echohl None + echohl ErrorMsg | echomsg v:errmsg | echohl None return endif let header["Authorization"] = auth @@ -596,7 +596,7 @@ function! gist#Gist(count, line1, line2, ...) elseif arg =~ '^\(+1\|--star\)$\C' && gistidbuf != '' let auth = s:GistGetAuthHeader() if len(auth) == 0 - echohl ErrorMsg | echomsg 'Canceled' | echohl None + echohl ErrorMsg | echomsg v:errmsg | echohl None else let gistid = gistidbuf let res = webapi#http#post(g:github_api_url.'/gists/'.gistid.'/star', '', { "Authorization": auth }, 'PUT') @@ -611,7 +611,7 @@ function! gist#Gist(count, line1, line2, ...) elseif arg =~ '^\(-1\|--unstar\)$\C' && gistidbuf != '' let auth = s:GistGetAuthHeader() if len(auth) == 0 - echohl ErrorMsg | echomsg 'Canceled' | echohl None + echohl ErrorMsg | echomsg v:errmsg | echohl None else let gistid = gistidbuf let res = webapi#http#post(g:github_api_url.'/gists/'.gistid.'/star', '', { "Authorization": auth }, 'DELETE') @@ -625,7 +625,7 @@ function! gist#Gist(count, line1, line2, ...) elseif arg =~ '^\(-f\|--fork\)$\C' && gistidbuf != '' let auth = s:GistGetAuthHeader() if len(auth) == 0 - echohl ErrorMsg | echomsg 'Canceled' | echohl None + echohl ErrorMsg | echomsg v:errmsg | echohl None return else let gistid = gistidbuf @@ -765,13 +765,12 @@ function! s:GistGetAuthHeader() call system("chmod go= ".s:configfile) endif elseif has_key(authorization, 'message') - echohl WarningMsg - echo authorization.message - echohl None let secret = '' + let v:errmsg = authorization.message endif else let secret = '' + let v:errmsg = 'Canceled' endif return secret endfunction From f42ceff6b8eab96ddc917df020824370526e871b Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 21 Jan 2013 14:00:38 +0900 Subject: [PATCH 074/170] show raw url with --rawurl. close #109 --- autoload/gist.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/autoload/gist.vim b/autoload/gist.vim index 98e725d..97ab18a 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -587,6 +587,10 @@ function! gist#Gist(count, line1, line2, ...) let gistdesc = '' elseif arg =~ '^\(-c\|--clipboard\)$\C' let clipboard = 1 + elseif arg =~ '^--rawurl$\C' && gistidbuf != '' && g:github_api_url == 'https://api.github.com' + let gistid = gistidbuf + echo 'https://gist.github.com/raw/'.gistid + return elseif arg =~ '^\(-d\|--delete\)$\C' && gistidbuf != '' let gistid = gistidbuf let deletepost = 1 From 530c1c84455f1a63941aca81c4c9cb66caeffe2a Mon Sep 17 00:00:00 2001 From: Martinho Fernandes Date: Thu, 11 Apr 2013 19:01:25 +0200 Subject: [PATCH 075/170] Fix bad markup in README --- README.mkd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.mkd b/README.mkd index 75daa9c..d87b02f 100644 --- a/README.mkd +++ b/README.mkd @@ -48,8 +48,8 @@ For the latest version please see https://github.com/mattn/gist-vim. - Post/Edit with the description " (you need to have opened the gist buffer first). > - :Gist -s something - :Gist -e -s something + :Gist -s something + :Gist -e -s something - Delete the gist (you need to have opened the gist buffer first). Password authentication is needed. From 92bdefe2bd9a70c8f213caaf16e33fcc5fe3bfa8 Mon Sep 17 00:00:00 2001 From: Martinho Fernandes Date: Thu, 11 Apr 2013 22:43:29 +0200 Subject: [PATCH 076/170] Update docs to match README --- doc/gist-vim.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index b9fca32..aed7220 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -142,6 +142,11 @@ If you want to show your private gists with ":Gist -l": > let g:gist_show_privates = 1 < +If you want your gist to be private by default: > + + let g:gist_post_private = 1 + +< If you want to edit all files for gists containing more than one: > let g:gist_get_multiplefile = 1 From 51014f79b94bdbd289dd36f79a1adf8cfb7555ba Mon Sep 17 00:00:00 2001 From: mattn Date: Sun, 21 Apr 2013 23:56:55 +0900 Subject: [PATCH 077/170] Post with -c, copy URL to clipboard. close #123 --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 97ab18a..3f39089 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 21-Jan-2013. +" Last Change: 21-Apr-2013. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -712,7 +712,7 @@ function! gist#Gist(count, line1, line2, ...) call s:open_browser(url) endif let gist_put_url_to_clipboard_after_post = get(g:, 'gist_put_url_to_clipboard_after_post', 1) - if gist_put_url_to_clipboard_after_post > 0 + if gist_put_url_to_clipboard_after_post > 0 || clipboard if gist_put_url_to_clipboard_after_post == 2 let url = url . "\n" endif From 865fe18acbea457537bfb4c67c318e9521e48731 Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 10 May 2013 14:15:54 +0900 Subject: [PATCH 078/170] Refer status attribute. Just now, gist-vim require latest webapi-vim --- autoload/gist.vim | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 3f39089..531fd1f 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 21-Apr-2013. +" Last Change: 10-May-2013. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -242,8 +242,7 @@ endfunction function! s:GistGet(gistid, clipboard) redraw | echon 'Getting gist... ' let res = webapi#http#get(g:github_api_url.'/gists/'.a:gistid, '', { "Authorization": s:GistGetAuthHeader() }) - let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') - if status =~ '^2' + if res.status =~ '^2' let gist = webapi#json#decode(res.content) if get(g:, 'gist_get_multiplefile', 0) != 0 let num_file = len(keys(gist.files)) @@ -361,8 +360,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) let gist["description"] = a:desc else let res = webapi#http#get(g:github_api_url.'/gists/'.a:gistid, '', { "Authorization": auth }) - let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') - if status =~ '^2' + if res.status =~ '^2' let old_gist = webapi#json#decode(res.content) let gist["description"] = old_gist.description endif @@ -376,8 +374,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) \ "Authorization": auth, \ "Content-Type": "application/json", \}) - let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') - if status =~ '^2' + if res.status =~ '^2' let obj = webapi#json#decode(res.content) let loc = obj["html_url"] redraw | echomsg 'Done: '.loc @@ -385,8 +382,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) setlocal nomodified else let loc = '' - let status = matchstr(status, '^\d\+\s*\zs.*') - echohl ErrorMsg | echomsg 'Post failed: '.status | echohl None + echohl ErrorMsg | echomsg 'Post failed: ' . res.message | echohl None endif return loc endfunction @@ -404,15 +400,13 @@ function! s:GistDelete(gistid) \ "Authorization": auth, \ "Content-Type": "application/json", \}, 'DELETE') - let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') - if status =~ '^2' + if res.status =~ '^2' redraw | echomsg 'Done: ' if exists('b:gist') unlet b:gist endif else - let status = matchstr(status, '^\d\+\s*\zs.*') - echohl ErrorMsg | echomsg 'Delete failed: '.status | echohl None + echohl ErrorMsg | echomsg 'Delete failed: ' . res.message | echohl None endif endfunction @@ -465,8 +459,7 @@ function! s:GistPost(content, private, desc, anonymous) redraw | echon 'Posting it to gist... ' let res = webapi#http#post(g:github_api_url.'/gists', webapi#json#encode(gist), header) - let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') - if status =~ '^2' + if res.status =~ '^2' let obj = webapi#json#decode(res.content) let loc = obj["html_url"] redraw | echomsg 'Done: '.loc @@ -478,8 +471,7 @@ function! s:GistPost(content, private, desc, anonymous) \} else let loc = '' - let status = matchstr(status, '^\d\+\s*\zs.*') - echohl ErrorMsg | echomsg 'Post failed: '.status | echohl None + echohl ErrorMsg | echomsg 'Post failed: '. res.message | echohl None endif return loc endfunction @@ -520,16 +512,14 @@ function! s:GistPostBuffers(private, desc, anonymous) redraw | echon 'Posting it to gist... ' let res = webapi#http#post(g:github_api_url.'/gists', webapi#json#encode(gist), header) - let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') - if status =~ '^2' + if res.status =~ '^2' let obj = webapi#json#decode(res.content) let loc = obj["html_url"] redraw | echomsg 'Done: '.loc let b:gist = {"id": matchstr(loc, '[^/]\+$'), "filename": filename, "private": a:private} else let loc = '' - let status = matchstr(status, '^\d\+\s*\zs.*') - echohl ErrorMsg | echomsg 'Post failed: '.status | echohl None + echohl ErrorMsg | echomsg 'Post failed: ' . res.message | echohl None endif return loc endfunction @@ -604,8 +594,7 @@ function! gist#Gist(count, line1, line2, ...) else let gistid = gistidbuf let res = webapi#http#post(g:github_api_url.'/gists/'.gistid.'/star', '', { "Authorization": auth }, 'PUT') - let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') - if status =~ '^2' + if res.status =~ '^2' echomsg "Stared" gistid else echohl ErrorMsg | echomsg 'Star failed' | echohl None @@ -619,7 +608,7 @@ function! gist#Gist(count, line1, line2, ...) else let gistid = gistidbuf let res = webapi#http#post(g:github_api_url.'/gists/'.gistid.'/star', '', { "Authorization": auth }, 'DELETE') - if status =~ '^2' + if res.status =~ '^2' echomsg "Unstared" gistid else echohl ErrorMsg | echomsg 'Unstar failed' | echohl None @@ -634,8 +623,7 @@ function! gist#Gist(count, line1, line2, ...) else let gistid = gistidbuf let res = webapi#http#post(g:github_api_url.'/gists/'.gistid.'/fork', '', { "Authorization": auth }) - let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*') - if status =~ '^2' + if res.status =~ '^2' let obj = webapi#json#decode(res.content) let gistid = obj["id"] else From 1164bba797c43b617eff0f0720fd0f76853f2901 Mon Sep 17 00:00:00 2001 From: crazymaster Date: Fri, 10 May 2013 23:24:53 +0900 Subject: [PATCH 079/170] Fixed typo. --- doc/gist-vim.txt | 2 +- gist.vim.vimup | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index aed7220..08fbac5 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -18,7 +18,7 @@ USAGE *:Gist* *gist-vim-usage* :Gist < -- Post selected text to gist, using defualt privacy option. +- Post selected text to gist, using default privacy option. This applies to all permutations listed below (except multi). > :'<,'>Gist diff --git a/gist.vim.vimup b/gist.vim.vimup index 96e6a30..5aee712 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -28,11 +28,11 @@ detailed_description: | post multi buffer to gist. :Gist -e - edit the gist. (shoud be work on gist buffer) + 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'. (shoud be work on gist buffer) + edit the gist with name 'foo.js'. (should be work on gist buffer) :Gist -d delete the gist. (should be work on gist buffer) From 860b0e9f590c3bd578fe9ddc510d144d8e43aa0b Mon Sep 17 00:00:00 2001 From: manboubird Date: Sat, 11 May 2013 20:05:17 +0900 Subject: [PATCH 080/170] look up github.apiurl of git config to set github_api_url --- autoload/gist.vim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 531fd1f..e414427 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 10-May-2013. +" Last Change: 11-May-2013. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -30,7 +30,11 @@ if !exists('g:github_user') endif if !exists('g:github_api_url') - let g:github_api_url = 'https://api.github.com' + let s:system = function(get(g:, 'webapi#system_function', 'system')) + let g:github_api_url = substitute(s:system('git config --get github.apiurl'), "\n", '', '') + if strlen(g:github_api_url) == 0 + let g:github_api_url = 'https://api.github.com' + end endif if !exists('g:gist_update_on_write') From bc8489c5d1790313d273345612335d6b544f9b39 Mon Sep 17 00:00:00 2001 From: mattn Date: Sat, 11 May 2013 21:51:25 +0900 Subject: [PATCH 081/170] Set webapi#system_function in script local --- autoload/gist.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index e414427..a44813e 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -20,9 +20,9 @@ if !executable('curl') endif let s:configfile = expand('~/.gist-vim') +let s:system = function(get(g:, 'webapi#system_function', 'system')) if !exists('g:github_user') - let s:system = function(get(g:, 'webapi#system_function', 'system')) let g:github_user = substitute(s:system('git config --get github.user'), "\n", '', '') if strlen(g:github_user) == 0 let g:github_user = $GITHUB_USER @@ -30,7 +30,6 @@ if !exists('g:github_user') endif if !exists('g:github_api_url') - let s:system = function(get(g:, 'webapi#system_function', 'system')) let g:github_api_url = substitute(s:system('git config --get github.apiurl'), "\n", '', '') if strlen(g:github_api_url) == 0 let g:github_api_url = 'https://api.github.com' From f3165100ab92494236a208634f81671771172645 Mon Sep 17 00:00:00 2001 From: Alex Ciobica Date: Thu, 16 May 2013 18:46:19 +0300 Subject: [PATCH 082/170] Add gist name to Gist list. --- autoload/gist.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index a44813e..3c93b19 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -93,13 +93,14 @@ function! s:format_gist(gist) return "" endif let file = a:gist.files[files[0]] + let name = file.filename if has_key(file, "content") let code = file.content let code = "\n".join(map(split(code, "\n"), '" ".v:val'), "\n") else let code = "" endif - return printf("gist: %s %s%s", a:gist.id, type(a:gist.description)==0?"": a:gist.description, code) + return printf("gist: %s %s %s%s", a:gist.id, name, type(a:gist.description)==0?"":'('.a:gist.description.')', code) endfunction " Note: A colon in the file name has side effects on Windows due to NTFS Alternate Data Streams; avoid it. From 6b23c7e259d560c1cdf433f9dc848a75b9d89aec Mon Sep 17 00:00:00 2001 From: Alex Ciobica Date: Fri, 17 May 2013 14:34:42 +0300 Subject: [PATCH 083/170] Correct empty description check. --- autoload/gist.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 3c93b19..1686093 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -100,7 +100,7 @@ function! s:format_gist(gist) else let code = "" endif - return printf("gist: %s %s %s%s", a:gist.id, name, type(a:gist.description)==0?"":'('.a:gist.description.')', code) + return printf("gist: %s %s %s%s", a:gist.id, name, type(a:gist.description)==0 || a:gist.description==""?"":'('.a:gist.description.')', code) endfunction " Note: A colon in the file name has side effects on Windows due to NTFS Alternate Data Streams; avoid it. From b5ff84cc8eb0f282087d35f2c6807a7556c6ca4f Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 11 Jun 2013 13:21:51 +0900 Subject: [PATCH 084/170] Update blank "GistID:" when :Gist. Closes #126 --- autoload/gist.vim | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 1686093..5d9a72a 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 11-May-2013. +" Last Change: 11-Jun-2013. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -428,6 +428,17 @@ function! s:get_current_filename(no) return filename endfunction +function s:update_GistID(id) + let view = winsaveview() + normal! gg + if search('\:\s*$') + let line = getline('.') + let line = substitute(line, '\s\+$', '', 'g') + call setline('.', line . ' ' . a:id) + endif + call winrestview(view) +endfunction + " GistPost function: " Post new gist to github " @@ -473,6 +484,7 @@ function! s:GistPost(content, private, desc, anonymous) \ "description": gist['description'], \ "private": a:private, \} + call s:update_GistID(b:gist["id"]) else let loc = '' echohl ErrorMsg | echomsg 'Post failed: '. res.message | echohl None @@ -520,7 +532,13 @@ function! s:GistPostBuffers(private, desc, anonymous) let obj = webapi#json#decode(res.content) let loc = obj["html_url"] redraw | echomsg 'Done: '.loc - let b:gist = {"id": matchstr(loc, '[^/]\+$'), "filename": filename, "private": a:private} + let b:gist = { + \ "filename": filename, + \ "id": matchstr(loc, '[^/]\+$'), + \ "description": gist['description'], + \ "private": a:private, + \} + call s:update_GistID(b:gist["id"]) else let loc = '' echohl ErrorMsg | echomsg 'Post failed: ' . res.message | echohl None From 926e117d9a09e7909910e46ae515d1323a9046eb Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 11 Jun 2013 13:29:15 +0900 Subject: [PATCH 085/170] After posted, Gist -e should work as update. Fixes #129 --- autoload/gist.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/autoload/gist.vim b/autoload/gist.vim index 5d9a72a..4c81545 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -568,6 +568,8 @@ function! gist#Gist(count, line1, line2, ...) let bufnamemx = '^' . s:bufprefix .'\(\zs[0-9a-f]\+\ze\|\zs[0-9a-f]\+\ze[/\\].*\)$' if bufname =~ bufnamemx let gistidbuf = matchstr(bufname, bufnamemx) + elseif exists('b:gist') && has_key(b:gist, 'id') + let gistidbuf = b:gist['id'] else let gistidbuf = matchstr(join(getline(a:line1, a:line2), "\n"), 'GistID:\s*\zs\w\+') endif From fba218c27b4c3e55f21e31b94bc5b10f2851c7aa Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 17 Jul 2013 14:10:40 +0900 Subject: [PATCH 086/170] Add FAQ. Closes #120 --- doc/gist-vim.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 08fbac5..5406a7a 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -6,6 +6,7 @@ License |gist-vim-license| Install |gist-vim-install| Requirements |gist-vim-requirements| Setup |gist-vim-setup| +FAQ |gist-vim-faq| This is a vimscript for creating gists (http://gist.github.com) @@ -257,6 +258,12 @@ Then, add following into your ~/.vimrc < This is not secure at all, so strongly discouraged. +============================================================================== +FAQ *gist-vim-faq* + +Q. :Gist give Forbidden error +A. Try to delete ~/.gist-vim. And authenticate again. + ============================================================================== THANKS *gist-vim-thanks* From 61c6d09c7db212055f789a8fe5e7601d70089b00 Mon Sep 17 00:00:00 2001 From: mattn Date: Sat, 3 Aug 2013 14:12:06 +0900 Subject: [PATCH 087/170] git clone --- autoload/gist.vim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 1686093..20d2158 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 11-May-2013. +" Last Change: 03-Aug-2013. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -559,6 +559,12 @@ function! gist#Gist(count, line1, line2, ...) if arg =~ '^\(-h\|--help\)$\C' help :Gist return + elseif arg =~ '^\(-g\|--git\)$\C' && gistidbuf != '' && g:github_api_url == 'https://api.github.com' && has_key(b:, 'gist') && has_key(b:gist, 'id') + echo printf('git clone git@github.com:%s', b:gist['id']) + return + elseif arg =~ '^\(-G\|--gitclone\)$\C' && gistidbuf != '' && g:github_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 arg =~ '^\(-la\|--listall\)$\C' let gistls = '-all' elseif arg =~ '^\(-ls\|--liststar\)$\C' From b91567126f1fa2e1897f7cf73a3569c7ef5f8a23 Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 29 Aug 2013 09:43:43 +0900 Subject: [PATCH 088/170] Handle error --- autoload/gist.vim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 7bc640a..3efa23e 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 03-Aug-2013. +" Last Change: 29-Aug-2013. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -247,7 +247,13 @@ function! s:GistGet(gistid, clipboard) redraw | echon 'Getting gist... ' let res = webapi#http#get(g:github_api_url.'/gists/'.a:gistid, '', { "Authorization": s:GistGetAuthHeader() }) if res.status =~ '^2' - let gist = webapi#json#decode(res.content) + try + let gist = webapi#json#decode(res.content) + catch + redraw + echohl ErrorMsg | echomsg 'Gist seems to be broken' | echohl None + return + endtry if get(g:, 'gist_get_multiplefile', 0) != 0 let num_file = len(keys(gist.files)) else From db4bc8df66f8732df9a581fbf0417eb8cdb662de Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 18 Sep 2013 09:25:19 +0900 Subject: [PATCH 089/170] Add gist_list_vsplit --- autoload/gist.vim | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 3efa23e..b734b34 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 29-Aug-2013. +" Last Change: 18-Sep-2013. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -122,7 +122,13 @@ function! s:GistList(gistls, page) endif setlocal modifiable else - exec 'silent noautocmd split' s:bufprefix.a:gistls + if get(g:, 'gist_list_vsplit', 0) + exec 'silent noautocmd vsplit +set\ winfixwidth ' s:bufprefix.a:gistls + elseif get(g:, 'gist_list_rightbelow', 0) + exec 'silent noautocmd rightbelow 5 split +set\ winfixheight ' s:bufprefix.a:gistls + else + exec 'silent noautocmd split' s:bufprefix.a:gistls + endif endif if a:page > 1 let oldlines = getline(0, line('$')) @@ -171,6 +177,7 @@ function! s:GistList(gistls, page) setlocal nomodified setlocal nomodifiable syntax match SpecialKey /^gist:/he=e-1 + syntax match Title /^gist: \S\+/hs=s+5 contains=ALL nnoremap :call GistListAction(0) nnoremap :call GistListAction(1) @@ -276,7 +283,12 @@ function! s:GistGet(gistid, clipboard) endif setlocal modifiable else - exec 'silent noautocmd new' + if get(g:, 'gist_list_vsplit', 0) + exec 'only!' + exec 'silent noautocmd rightbelow vnew' + else + exec 'silent noautocmd new' + endif setlocal noswapfile exec 'noautocmd file' s:bufprefix.a:gistid."/".fnameescape(filename) endif From 2dd2d64d2db12ca9ad6a28abc62737611a03ed58 Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 18 Sep 2013 09:30:10 +0900 Subject: [PATCH 090/170] Possible to override token file path --- autoload/gist.vim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index b734b34..1e9d2ed 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -19,7 +19,7 @@ if !executable('curl') finish endif -let s:configfile = expand('~/.gist-vim') +let s:gist_token_file = expand(get(g:, 'gist_token_file', '~/.gist-vim')) let s:system = function(get(g:, 'webapi#system_function', 'system')) if !exists('g:github_user') @@ -161,7 +161,7 @@ function! s:GistList(gistls, page) redraw echohl ErrorMsg | echomsg content.message | echohl None if content.message == 'Bad credentials' - call delete(s:configfile) + call delete(s:gist_token_file) endif return endif @@ -772,8 +772,8 @@ function! s:GistGetAuthHeader() return printf("basic %s", webapi#base64#b64encode(g:github_user.":".password)) endif let auth = "" - if filereadable(s:configfile) - let str = join(readfile(s:configfile), "") + if filereadable(s:gist_token_file) + let str = join(readfile(s:gist_token_file), "") if type(str) == 1 let auth = str endif @@ -800,9 +800,9 @@ function! s:GistGetAuthHeader() let authorization = webapi#json#decode(res.content) if has_key(authorization, 'token') let secret = printf("token %s", authorization.token) - call writefile([secret], s:configfile) + call writefile([secret], s:gist_token_file) if !(has('win32') || has('win64')) - call system("chmod go= ".s:configfile) + call system("chmod go= ".s:gist_token_file) endif elseif has_key(authorization, 'message') let secret = '' From 70b1f05fc3a67939a2ba4c18c7b9dc56891864d5 Mon Sep 17 00:00:00 2001 From: Shohei Fujii Date: Tue, 30 Jul 2013 11:35:24 +0900 Subject: [PATCH 091/170] complete args --- plugin/gist.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin/gist.vim b/plugin/gist.vim index 973d300..00c3df4 100644 --- a/plugin/gist.vim +++ b/plugin/gist.vim @@ -11,6 +11,10 @@ if &cp || (exists('g:loaded_gist_vim') && g:loaded_gist_vim) endif let g:loaded_gist_vim = 1 -command! -nargs=? -range=% Gist :call gist#Gist(, , , ) +function! s:CompleteArgs(arg_lead,cmdline,cursor_pos) + return ["-p", "-P", "-a", "-m", "-e", "-s", "-d", "-f", "-c", "-l", "-la", "-ls"] +endfunction + +command! -nargs=? -range=% -complete=customlist,s:CompleteArgs Gist :call gist#Gist(, , , ) " vim:set et: From 4416a5360596740effe17b699172ff3768098f35 Mon Sep 17 00:00:00 2001 From: Shohei Fujii Date: Tue, 30 Jul 2013 20:22:48 +0900 Subject: [PATCH 092/170] add double dash options --- plugin/gist.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin/gist.vim b/plugin/gist.vim index 00c3df4..7e53cd1 100644 --- a/plugin/gist.vim +++ b/plugin/gist.vim @@ -12,7 +12,10 @@ endif let g:loaded_gist_vim = 1 function! s:CompleteArgs(arg_lead,cmdline,cursor_pos) - return ["-p", "-P", "-a", "-m", "-e", "-s", "-d", "-f", "-c", "-l", "-la", "-ls"] + return ["-p", "-P", "-a", "-m", "-e", "-s", "-d", "+1", "-1", "-f", "-c", "-l", "-la", "-ls", + \ "--listall", "--liststar", "--list", "--multibuffer", "--private", "--public", "--anonymous", "--description", "--clipboard", + \ "--rawurl", "--delete", "--edit", "--star", "--unstar", "--fork" + \ ] endfunction command! -nargs=? -range=% -complete=customlist,s:CompleteArgs Gist :call gist#Gist(, , , ) From 96c82ec8b9f1a0cbc804d5655d0112c81341d1e7 Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 18 Sep 2013 09:37:47 +0900 Subject: [PATCH 093/170] normalize name and description --- autoload/gist.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 1e9d2ed..9c42d20 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -100,7 +100,12 @@ function! s:format_gist(gist) else let code = "" endif - return printf("gist: %s %s %s%s", a:gist.id, name, type(a:gist.description)==0 || a:gist.description==""?"":'('.a:gist.description.')', code) + let desc = type(a:gist.description)==0 || a:gist.description == "" ? "" : '('.a:gist.description.')' + let name = substitute(name, '[\r\n\t]', ' ', 'g') + let name = substitute(name, ' ', ' ', 'g') + let desc = substitute(desc, '[\r\n\t]', ' ', 'g') + let desc = substitute(desc, ' ', ' ', 'g') + return printf("gist: %s %s %s%s", a:gist.id, name, desc, code) endfunction " Note: A colon in the file name has side effects on Windows due to NTFS Alternate Data Streams; avoid it. @@ -446,7 +451,7 @@ function! s:get_current_filename(no) return filename endfunction -function s:update_GistID(id) +function! s:update_GistID(id) let view = winsaveview() normal! gg if search('\:\s*$') From 1aed2e01b0e124295b705ae5b6de8ea3c82a2a2b Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 18 Sep 2013 09:41:22 +0900 Subject: [PATCH 094/170] 2 panes --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 9c42d20..59811c6 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -288,11 +288,11 @@ function! s:GistGet(gistid, clipboard) endif setlocal modifiable else + silent only! if get(g:, 'gist_list_vsplit', 0) - exec 'only!' exec 'silent noautocmd rightbelow vnew' else - exec 'silent noautocmd new' + exec 'silent noautocmd rightbelow new' endif setlocal noswapfile exec 'noautocmd file' s:bufprefix.a:gistid."/".fnameescape(filename) From dcdf83edb210750d751a2c0357ce5235f90661cc Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 7 Oct 2013 17:30:33 +0900 Subject: [PATCH 095/170] Update GistID with Gist -e --- autoload/gist.vim | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 59811c6..2f61600 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 18-Sep-2013. +" Last Change: 07-Oct-2013. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -454,12 +454,15 @@ endfunction function! s:update_GistID(id) let view = winsaveview() normal! gg + let ret = 0 if search('\:\s*$') let line = getline('.') let line = substitute(line, '\s\+$', '', 'g') call setline('.', line . ' ' . a:id) + let ret = 1 endif call winrestview(view) + return ret endfunction " GistPost function: @@ -507,7 +510,9 @@ function! s:GistPost(content, private, desc, anonymous) \ "description": gist['description'], \ "private": a:private, \} - call s:update_GistID(b:gist["id"]) + if s:update_GistID(b:gist["id"]) + Gist -e + endif else let loc = '' echohl ErrorMsg | echomsg 'Post failed: '. res.message | echohl None @@ -561,7 +566,9 @@ function! s:GistPostBuffers(private, desc, anonymous) \ "description": gist['description'], \ "private": a:private, \} - call s:update_GistID(b:gist["id"]) + if s:update_GistID(b:gist["id"]) + Gist -e + endif else let loc = '' echohl ErrorMsg | echomsg 'Post failed: ' . res.message | echohl None From 917056752acdb8984307648ef64ba255441010d4 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 15 Oct 2013 09:42:53 +0900 Subject: [PATCH 096/170] Fixes displaying multiple files. related issue #56 --- autoload/gist.vim | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 2f61600..f19d416 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 07-Oct-2013. +" Last Change: 15-Oct-2013. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -288,14 +288,16 @@ function! s:GistGet(gistid, clipboard) endif setlocal modifiable else - silent only! + if num_file == 1 + silent only! + endif if get(g:, 'gist_list_vsplit', 0) exec 'silent noautocmd rightbelow vnew' else exec 'silent noautocmd rightbelow new' endif setlocal noswapfile - exec 'noautocmd file' s:bufprefix.a:gistid."/".fnameescape(filename) + silent exec 'noautocmd file' s:bufprefix.a:gistid."/".fnameescape(filename) endif set undolevels=-1 filetype detect @@ -472,10 +474,6 @@ endfunction " it will just update it. " -- by c9s " -" embedded gist url format: -" -" Gist: https://gist.github.com/123123 -" " embedded gist id format: " " GistID: 123123 From bd941d058b319e2b7bfc07de584e975a51782cc9 Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 17 Oct 2013 17:20:08 +0900 Subject: [PATCH 097/170] Check webapi-vim is installed or not. Closes #140 --- autoload/gist.vim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index f19d416..b1d094d 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 15-Oct-2013. +" Last Change: 17-Oct-2013. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -19,6 +19,11 @@ if !executable('curl') finish endif +if globpath(&rtp, 'autoload/webapi/http.vim') == '' + echohl ErrorMsg | echomsg "Gist: require 'webapi', install https://github.com/mattn/webapi-vim" | echohl None + finish +endif + let s:gist_token_file = expand(get(g:, 'gist_token_file', '~/.gist-vim')) let s:system = function(get(g:, 'webapi#system_function', 'system')) From b4196418aa02543dc30b82439ade3a7ffce19d55 Mon Sep 17 00:00:00 2001 From: "Michael C. Harris" Date: Sat, 30 Nov 2013 14:38:27 +1100 Subject: [PATCH 098/170] Describe two-factor auth setup --- doc/gist-vim.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 5406a7a..3b7055e 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -246,6 +246,14 @@ be kept for later use. You can revoke the token at any time from the list of "Authorized applications" on Github's "Account Settings" page. (https://github.com/settings/applications) +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 +create a "Personal Access Token" on Github's "Account Settings" page +(https://github.com/settings/applications) and place it in a file +named ~/.gist-vim like this: +> + token xxxxx +< If you happen to have your password already written in ~/.gitconfig like below: > From 930cf6a4d80722a2d261e7779e0d170eb64b495b Mon Sep 17 00:00:00 2001 From: "Michael C. Harris" Date: Sat, 30 Nov 2013 14:44:51 +1100 Subject: [PATCH 099/170] Correct GitHub to use correct capitalization. --- README.mkd | 6 +++--- doc/gist-vim.txt | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.mkd b/README.mkd index d87b02f..9266b93 100644 --- a/README.mkd +++ b/README.mkd @@ -142,7 +142,7 @@ If you want to manipulate multiple files in a gist: let g:gist_get_multiplefile = 1 -If you want to use on Github Enterprise: +If you want to use on GitHub Enterprise: let g:github_api_url = 'http://your-github-enterprise-domain/api/v3' @@ -211,7 +211,7 @@ Now restart Vim and run `:BundleInstall`. ## Setup: -This plugin uses github API v3. Setting value is stored in `~/.gist-vim`. +This plugin uses GitHub API v3. Setting value is stored in `~/.gist-vim`. gist-vim have two ways to access APIs. First, you need to set your Github username in global git config: @@ -221,4 +221,4 @@ First, you need to set your Github username in global git config: Then, gist.vim will ask for your password to create an authorization when you first use it. The password is not stored and only the OAuth access token will be kept for later use. You can revoke the token at any time from the list of -["Authorized applications" on Github's "Account Settings" page](https://github.com/settings/applications). +["Authorized applications" on GitHub's "Account Settings" page](https://github.com/settings/applications). diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 5406a7a..f62b229 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -153,7 +153,7 @@ If you want to edit all files for gists containing more than one: > let g:gist_get_multiplefile = 1 < -If you want to use on Github Enterprise: > +If you want to use on GitHub Enterprise: > let g:github_api_url = 'http://your-github-enterprise-domain/api/v3' < @@ -233,17 +233,17 @@ REQUIREMENTS *gist-vim-requirements* ============================================================================== SETUP *gist-vim-setup* -This plugin uses github API v3. Setting value is stored in `~/.gist.vim`. +This plugin uses GitHub API v3. Setting value is stored in `~/.gist.vim`. gist-vim have two ways to access 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: > $ git config --global github.user Username < Then, gist.vim will ask for your password to create an authorization when you first use it. The password is not stored and only the OAuth access token will be kept for later use. You can revoke the token at any time from the list of -"Authorized applications" on Github's "Account Settings" page. +"Authorized applications" on GitHub's "Account Settings" page. (https://github.com/settings/applications) If you happen to have your password already written in ~/.gitconfig like From b79e1993797743261fae5ed019699f2367fd44b7 Mon Sep 17 00:00:00 2001 From: "Michael C. Harris" Date: Sat, 30 Nov 2013 14:51:22 +1100 Subject: [PATCH 100/170] Use correct capitalization. Not great to mix pull requests like this, but it's minor so hopefully you won't mind. --- doc/gist-vim.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 3b7055e..79f0192 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -246,9 +246,9 @@ be kept for later use. You can revoke the token at any time from the list of "Authorized applications" on Github's "Account Settings" page. (https://github.com/settings/applications) -If you have two-factor authentication enabled on Github, you'll see the message +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 -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 named ~/.gist-vim like this: > From d3c07325b32d8dd9e8c67fa8f1810f36d4de2ea8 Mon Sep 17 00:00:00 2001 From: Vadim Golub Date: Tue, 14 Jan 2014 22:54:26 +0200 Subject: [PATCH 101/170] Documentation file updated Typo fixed ~/.gist.vim => ~/.gist-vim. --- doc/gist-vim.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 7e1381a..b21a078 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -233,7 +233,7 @@ REQUIREMENTS *gist-vim-requirements* ============================================================================== SETUP *gist-vim-setup* -This plugin uses GitHub API v3. Setting value is stored in `~/.gist.vim`. +This plugin uses GitHub API v3. Setting value is stored in `~/.gist-vim`. gist-vim have two ways to access APIs. First, you need to set your GitHub username in global git config: From cec9546d9d704d028ce1e833f99c143ce501c621 Mon Sep 17 00:00:00 2001 From: Peter Aronoff Date: Wed, 9 Apr 2014 10:22:46 -0400 Subject: [PATCH 102/170] Add two-factor authentication setup instructions --- README.mkd | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/README.mkd b/README.mkd index 9266b93..85fa177 100644 --- a/README.mkd +++ b/README.mkd @@ -211,6 +211,11 @@ Now restart Vim and run `:BundleInstall`. ## Setup: +### Basic Authentication + +If you don't have two-factor authentication enabled, follow the +instructions in this section. + This plugin uses GitHub API v3. Setting value is stored in `~/.gist-vim`. gist-vim have two ways to access APIs. @@ -221,4 +226,23 @@ First, you need to set your Github username in global git config: Then, gist.vim will ask for your password to create an authorization when you first use it. The password is not stored and only the OAuth access token will be kept for later use. You can revoke the token at any time from the list of -["Authorized applications" on GitHub's "Account Settings" page](https://github.com/settings/applications). +["Authorized applications" on GitHub's "Account Settings" page][uas]. + +### Two-factor Authentication + +If you use two-factor authentication, you will need to set things up +slightly differently. Luckily, it's not hard at all. + +First, go to your [user application settings page][uas] on GitHub. In the +section 'Personal access tokens', click the button to 'Generate new +token'. Name the token something easy to remember, like 'gist-vim', and +then copy the token itself. Finally paste the token you just made into +`~/.gist-vim`. (Create that file, if it doesn't already exist.) The final +result should look like this: + + token + +Done! You can revoke this token at any time from your [application +settings][uas]. + +[uas]: https://github.com/settings/applications From fe9a5314511f5873454382b633865331cc4ce0f5 Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 11 Apr 2014 11:05:44 +0900 Subject: [PATCH 103/170] Support two factor authentication --- autoload/gist.vim | 50 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index b1d094d..c6c227e 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -799,11 +799,31 @@ function! s:GistGetAuthHeader() redraw echohl WarningMsg - echo 'Gist.vim requires authorization to use the Github API. These settings are stored in "~/.gist-vim". If you want to revoke, do "rm ~/.gist-vim".' + echo 'Gist.vim requires authorization to use the GitHub API. These settings are stored in "~/.gist-vim". If you want to revoke, do "rm ~/.gist-vim".' echohl None - let password = inputsecret("Github Password for ".g:github_user.":") - if len(password) > 0 - let insecureSecret = printf("basic %s", webapi#base64#b64encode(g:github_user.":".password)) + let password = inputsecret("GitHub Password for ".g:github_user.":") + if len(password) == 0 + let secret = '' + let v:errmsg = 'Canceled' + return secrert + endif + let insecureSecret = printf("basic %s", webapi#base64#b64encode(g:github_user.":".password)) + let res = webapi#http#post(g:github_api_url.'/authorizations', webapi#json#encode({ + \ "scopes" : ["gist"], + \ "note" : "Gist.vim on ".hostname(), + \ "note_url" : "http://www.vim.org/scripts/script.php?script_id=2423" + \}), { + \ "Content-Type" : "application/json", + \ "Authorization" : insecureSecret, + \}) + let h = filter(res.header, 'v:val =~ "^X-GitHub-OTP: require"') + if len(h) + let otp = inputsecret("OTP:") + if len(otp) == 0 + let secret = '' + let v:errmsg = 'Canceled' + return secrert + endif let res = webapi#http#post(g:github_api_url.'/authorizations', webapi#json#encode({ \ "scopes" : ["gist"], \ "note" : "Gist.vim on ".hostname(), @@ -811,21 +831,19 @@ function! s:GistGetAuthHeader() \}), { \ "Content-Type" : "application/json", \ "Authorization" : insecureSecret, + \ "X-GitHub-OTP" : otp, \}) - let authorization = webapi#json#decode(res.content) - if has_key(authorization, 'token') - let secret = printf("token %s", authorization.token) - call writefile([secret], s:gist_token_file) - if !(has('win32') || has('win64')) - call system("chmod go= ".s:gist_token_file) - endif - elseif has_key(authorization, 'message') - let secret = '' - let v:errmsg = authorization.message + endif + let authorization = webapi#json#decode(res.content) + if has_key(authorization, 'token') + let secret = printf("token %s", authorization.token) + call writefile([secret], s:gist_token_file) + if !(has('win32') || has('win64')) + call system("chmod go= ".s:gist_token_file) endif - else + elseif has_key(authorization, 'message') let secret = '' - let v:errmsg = 'Canceled' + let v:errmsg = authorization.message endif return secret endfunction From d1364d6471995245e5a53915f73bcf0c2e1315b3 Mon Sep 17 00:00:00 2001 From: mattn Date: Sun, 13 Apr 2014 01:51:13 +0900 Subject: [PATCH 104/170] Fixed typo --- autoload/gist.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index c6c227e..cf505de 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 17-Oct-2013. +" Last Change: 13-Apr-2014. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -803,9 +803,8 @@ function! s:GistGetAuthHeader() echohl None let password = inputsecret("GitHub Password for ".g:github_user.":") if len(password) == 0 - let secret = '' let v:errmsg = 'Canceled' - return secrert + return '' endif let insecureSecret = printf("basic %s", webapi#base64#b64encode(g:github_user.":".password)) let res = webapi#http#post(g:github_api_url.'/authorizations', webapi#json#encode({ From 9f99bc4ef10d229d68fdd9c7fd5e9032e4eadd8a Mon Sep 17 00:00:00 2001 From: Peter Aronoff Date: Sat, 12 Apr 2014 20:38:40 -0400 Subject: [PATCH 105/170] Merge basic and two-factor setup --- README.mkd | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/README.mkd b/README.mkd index 85fa177..8fc822d 100644 --- a/README.mkd +++ b/README.mkd @@ -211,38 +211,22 @@ Now restart Vim and run `:BundleInstall`. ## Setup: -### Basic Authentication +This plugin supports both basic and two-factor authentication using GitHub +API v3. The plugin stores its credentials in `~/.gist-vim`. -If you don't have two-factor authentication enabled, follow the -instructions in this section. +First, you need to set your GitHub username in git's global configuration: -This plugin uses GitHub API v3. Setting value is stored in `~/.gist-vim`. -gist-vim have two ways to access APIs. + $ git config --global github.user -First, you need to set your Github username in global git config: +Then gist-vim will ask for your password in order to create an access +token. If you have two-factor authentication enabled, gist-vim will also +prompt you to enter the two-factor key you receive. - $ git config --global github.user Username - -Then, gist.vim will ask for your password to create an authorization when you -first use it. The password is not stored and only the OAuth access token will -be kept for later use. You can revoke the token at any time from the list of -["Authorized applications" on GitHub's "Account Settings" page][uas]. - -### Two-factor Authentication - -If you use two-factor authentication, you will need to set things up -slightly differently. Luckily, it's not hard at all. - -First, go to your [user application settings page][uas] on GitHub. In the -section 'Personal access tokens', click the button to 'Generate new -token'. Name the token something easy to remember, like 'gist-vim', and -then copy the token itself. Finally paste the token you just made into -`~/.gist-vim`. (Create that file, if it doesn't already exist.) The final -result should look like this: - - token - -Done! You can revoke this token at any time from your [application -settings][uas]. +Whichever type of authentication you use, your GitHub password will not be +stored, only a OAuth access token produced specifically for gist-vim. The +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 +list of ["Authorized applications" on GitHub's "Account Settings" +page][uas]. [uas]: https://github.com/settings/applications From 92cc44ae684fbc03f496fe05083068a18e99c201 Mon Sep 17 00:00:00 2001 From: mattn Date: Sun, 13 Apr 2014 21:22:16 +0900 Subject: [PATCH 106/170] Fixes detecting two factor authentication --- autoload/gist.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index cf505de..a5c3761 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -815,13 +815,12 @@ function! s:GistGetAuthHeader() \ "Content-Type" : "application/json", \ "Authorization" : insecureSecret, \}) - let h = filter(res.header, 'v:val =~ "^X-GitHub-OTP: require"') + let h = filter(res.header, 'stridx(v:val, "X-GitHub-OTP:") == 0') if len(h) let otp = inputsecret("OTP:") if len(otp) == 0 - let secret = '' let v:errmsg = 'Canceled' - return secrert + return '' endif let res = webapi#http#post(g:github_api_url.'/authorizations', webapi#json#encode({ \ "scopes" : ["gist"], From 341b9c56eaff525cce2af4d51407e2aef1b1cd84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poisot?= Date: Wed, 16 Apr 2014 11:53:26 -0400 Subject: [PATCH 107/170] Fixes trailing slash problem --- README.mkd | 2 +- autoload/gist.vim | 58 +++++++++++++++++++++++------------------------ doc/gist-vim.txt | 2 +- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/README.mkd b/README.mkd index 8fc822d..102ac80 100644 --- a/README.mkd +++ b/README.mkd @@ -144,7 +144,7 @@ If you want to manipulate multiple files in a gist: If you want to use on GitHub Enterprise: - let g:github_api_url = 'http://your-github-enterprise-domain/api/v3' + let g:gist_api_url = 'http://your-github-enterprise-domain/api/v3' You need to either set global git config: diff --git a/autoload/gist.vim b/autoload/gist.vim index a5c3761..68a2db6 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 13-Apr-2014. +" Last Change: 15-Apr-2014. " Version: 7.1 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -34,10 +34,10 @@ if !exists('g:github_user') end endif -if !exists('g:github_api_url') - let g:github_api_url = substitute(s:system('git config --get github.apiurl'), "\n", '', '') - if strlen(g:github_api_url) == 0 - let g:github_api_url = 'https://api.github.com' +if !exists('g:gist_api_url') + let g:gist_api_url = substitute(s:system('git config --get github.apiurl'), "\n", '', '') + if strlen(g:gist_api_url) == 0 + let g:gist_api_url = 'https://api.github.com/' end endif @@ -117,13 +117,13 @@ endfunction let s:bufprefix = 'gist' . (has('unix') ? ':' : '_') function! s:GistList(gistls, page) if a:gistls == '-all' - let url = g:github_api_url.'/gists/public' + let url = g:gist_api_url.'gists/public' elseif get(g:, 'gist_show_privates', 0) && a:gistls == 'starred' - let url = g:github_api_url.'/gists/starred' + let url = g:gist_api_url.'gists/starred' elseif get(g:, 'gist_show_privates') && a:gistls == 'mine' - let url = g:github_api_url.'/gists' + let url = g:gist_api_url.'gists' else - let url = g:github_api_url.'/users/'.a:gistls.'/gists' + let url = g:gist_api_url.'users/'.a:gistls.'/gists' endif let winnum = bufwinnr(bufnr(s:bufprefix.a:gistls)) if winnum != -1 @@ -199,13 +199,13 @@ endfunction function! gist#list(user, ...) let page = get(a:000, 0, 0) if a:user == '-all' - let url = g:github_api_url.'/gists/public' + let url = g:gist_api_url.'gists/public' elseif get(g:, 'gist_show_privates', 0) && a:user == 'starred' - let url = g:github_api_url.'/gists/starred' + let url = g:gist_api_url.'gists/starred' elseif get(g:, 'gist_show_privates') && a:user == 'mine' - let url = g:github_api_url.'/gists' + let url = g:gist_api_url.'gists' else - let url = g:github_api_url.'/users/'.a:user.'/gists' + let url = g:gist_api_url.'users/'.a:user.'/gists' endif let auth = s:GistGetAuthHeader() @@ -221,7 +221,7 @@ function! s:GistGetFileName(gistid) if len(auth) == 0 return '' endif - let res = webapi#http#get(g:github_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) if has_key(gist, 'files') return sort(keys(gist.files))[0] @@ -234,7 +234,7 @@ function! s:GistDetectFiletype(gistid) if len(auth) == 0 return '' endif - let res = webapi#http#get(g:github_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 filename = sort(keys(gist.files))[0] let ext = fnamemodify(filename, ':e') @@ -262,7 +262,7 @@ endfunction function! s:GistGet(gistid, clipboard) redraw | echon 'Getting gist... ' - let res = webapi#http#get(g:github_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' try let gist = webapi#json#decode(res.content) @@ -393,7 +393,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) if a:desc != ' ' let gist["description"] = a:desc else - let res = webapi#http#get(g:github_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' let old_gist = webapi#json#decode(res.content) let gist["description"] = old_gist.description @@ -403,7 +403,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) let gist.files[filename] = { "content": a:content, "filename": filename } redraw | echon 'Updating gist... ' - let res = webapi#http#post(g:github_api_url.'/gists/' . a:gistid, + let res = webapi#http#post(g:gist_api_url.'gists/' . a:gistid, \ webapi#json#encode(gist), { \ "Authorization": auth, \ "Content-Type": "application/json", @@ -430,7 +430,7 @@ function! s:GistDelete(gistid) endif redraw | echon 'Deleting gist... ' - let res = webapi#http#post(g:github_api_url.'/gists/'.a:gistid, '', { + let res = webapi#http#post(g:gist_api_url.'gists/'.a:gistid, '', { \ "Authorization": auth, \ "Content-Type": "application/json", \}, 'DELETE') @@ -502,7 +502,7 @@ function! s:GistPost(content, private, desc, anonymous) endif redraw | echon 'Posting it to gist... ' - let res = webapi#http#post(g:github_api_url.'/gists', webapi#json#encode(gist), header) + let res = webapi#http#post(g:gist_api_url.'gists', webapi#json#encode(gist), header) if res.status =~ '^2' let obj = webapi#json#decode(res.content) let loc = obj["html_url"] @@ -558,7 +558,7 @@ function! s:GistPostBuffers(private, desc, anonymous) endif redraw | echon 'Posting it to gist... ' - let res = webapi#http#post(g:github_api_url.'/gists', webapi#json#encode(gist), header) + let res = webapi#http#post(g:gist_api_url.'gists', webapi#json#encode(gist), header) if res.status =~ '^2' let obj = webapi#json#decode(res.content) let loc = obj["html_url"] @@ -612,10 +612,10 @@ function! gist#Gist(count, line1, line2, ...) if arg =~ '^\(-h\|--help\)$\C' help :Gist return - elseif arg =~ '^\(-g\|--git\)$\C' && gistidbuf != '' && g:github_api_url == 'https://api.github.com' && has_key(b:, 'gist') && has_key(b:gist, 'id') + elseif arg =~ '^\(-g\|--git\)$\C' && gistidbuf != '' && g:gist_api_url == 'https://api.github.com/' && has_key(b:, 'gist') && has_key(b:gist, 'id') echo printf('git clone git@github.com:%s', b:gist['id']) return - elseif arg =~ '^\(-G\|--gitclone\)$\C' && gistidbuf != '' && g:github_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']) return elseif arg =~ '^\(-la\|--listall\)$\C' @@ -640,7 +640,7 @@ function! gist#Gist(count, line1, line2, ...) let gistdesc = '' elseif arg =~ '^\(-c\|--clipboard\)$\C' let clipboard = 1 - elseif arg =~ '^--rawurl$\C' && gistidbuf != '' && g:github_api_url == 'https://api.github.com' + elseif arg =~ '^--rawurl$\C' && gistidbuf != '' && g:gist_api_url == 'https://api.github.com/' let gistid = gistidbuf echo 'https://gist.github.com/raw/'.gistid return @@ -656,7 +656,7 @@ function! gist#Gist(count, line1, line2, ...) echohl ErrorMsg | echomsg v:errmsg | echohl None else let gistid = gistidbuf - let res = webapi#http#post(g:github_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' echomsg "Stared" gistid else @@ -670,7 +670,7 @@ function! gist#Gist(count, line1, line2, ...) echohl ErrorMsg | echomsg v:errmsg | echohl None else let gistid = gistidbuf - let res = webapi#http#post(g:github_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' echomsg "Unstared" gistid else @@ -685,7 +685,7 @@ function! gist#Gist(count, line1, line2, ...) return else let gistid = gistidbuf - let res = webapi#http#post(g:github_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' let obj = webapi#json#decode(res.content) let gistid = obj["id"] @@ -807,7 +807,7 @@ function! s:GistGetAuthHeader() return '' endif let insecureSecret = printf("basic %s", webapi#base64#b64encode(g:github_user.":".password)) - let res = webapi#http#post(g:github_api_url.'/authorizations', webapi#json#encode({ + let res = webapi#http#post(g:gist_api_url.'authorizations', webapi#json#encode({ \ "scopes" : ["gist"], \ "note" : "Gist.vim on ".hostname(), \ "note_url" : "http://www.vim.org/scripts/script.php?script_id=2423" @@ -822,7 +822,7 @@ function! s:GistGetAuthHeader() let v:errmsg = 'Canceled' return '' endif - let res = webapi#http#post(g:github_api_url.'/authorizations', webapi#json#encode({ + let res = webapi#http#post(g:gist_api_url.'authorizations', webapi#json#encode({ \ "scopes" : ["gist"], \ "note" : "Gist.vim on ".hostname(), \ "note_url" : "http://www.vim.org/scripts/script.php?script_id=2423" diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index b21a078..07311d0 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -155,7 +155,7 @@ If you want to edit all files for gists containing more than one: > If you want to use on GitHub Enterprise: > - let g:github_api_url = 'http://your-github-enterprise-domain/api/v3' + let g:gist_api_url = 'http://your-github-enterprise-domain/api/v3' < If you want to update a gist, embed > From 71ed5f7e3a60dc0bbcfe419a4476f72a2004fcd8 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 22 Apr 2014 10:21:22 +0900 Subject: [PATCH 108/170] Check using another API endpoint. ex: github enterprise edition. related issue #154 --- autoload/gist.vim | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 68a2db6..810ade6 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -9,6 +9,12 @@ let s:save_cpo = &cpo set cpo&vim +if exists('g:gist_disabled') && g:gist_disabled == 1 + function gist#Gist(...) + endfunction + finish +endif + if !exists('g:github_user') && !executable('git') echohl ErrorMsg | echomsg "Gist: require 'git' command" | echohl None finish @@ -39,6 +45,20 @@ if !exists('g:gist_api_url') if strlen(g:gist_api_url) == 0 let g:gist_api_url = 'https://api.github.com/' end + if exists('g:github_api_url') && !exists('g:gist_shutup_issue154') + if matchstr(g:gist_api_url, 'https\?://\zs[^/]\+\ze') != matchstr(g:github_api_url, 'https\?://\zs[^/]\+\ze') + echohl WarningMsg + echo "--- Warning ---" + echo "It seems that you set different URIs for github_api_url/gist_api_url." + echo "If you want to remove this message: let g:gist_shutup_issue154 = 1" + echohl None + if confirm("Continue?", "&Yes\n&No") != 1 + let g:gist_disabled = 1 + finish + endif + redraw! + endif + endif endif if !exists('g:gist_update_on_write') @@ -115,7 +135,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) +function! s:GistList(gistls, page) abort if a:gistls == '-all' let url = g:gist_api_url.'gists/public' elseif get(g:, 'gist_show_privates', 0) && a:gistls == 'starred' @@ -216,7 +236,7 @@ function! gist#list(user, ...) return webapi#json#decode(res.content) endfunction -function! s:GistGetFileName(gistid) +function! s:GistGetFileName(gistid) abort let auth = s:GistGetAuthHeader() if len(auth) == 0 return '' @@ -229,7 +249,7 @@ function! s:GistGetFileName(gistid) return '' endfunction -function! s:GistDetectFiletype(gistid) +function! s:GistDetectFiletype(gistid) abort let auth = s:GistGetAuthHeader() if len(auth) == 0 return '' @@ -246,7 +266,7 @@ function! s:GistDetectFiletype(gistid) silent! exec "setlocal ft=".tolower(type) endfunction -function! s:GistWrite(fname) +function! s:GistWrite(fname) abort if substitute(a:fname, '\\', '/', 'g') == expand("%:p:gs@\\@/@") if g:gist_update_on_write != 2 || v:cmdbang Gist -e @@ -260,7 +280,7 @@ function! s:GistWrite(fname) endif endfunction -function! s:GistGet(gistid, clipboard) +function! s:GistGet(gistid, clipboard) abort redraw | echon 'Getting gist... ' let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { "Authorization": s:GistGetAuthHeader() }) if res.status =~ '^2' @@ -351,7 +371,7 @@ function! s:GistGet(gistid, clipboard) endif endfunction -function! s:GistListAction(shift) +function! s:GistListAction(shift) abort let line = getline('.') let mx = '^gist:\s*\zs\(\w\+\)\ze.*' if line =~# mx @@ -369,7 +389,7 @@ function! s:GistListAction(shift) endif endfunction -function! s:GistUpdate(content, gistid, gistnm, desc) +function! s:GistUpdate(content, gistid, gistnm, desc) abort let gist = { "id": a:gistid, "files" : {}, "description": "","public": function('webapi#json#true') } if exists('b:gist') if has_key(b:gist, 'private') && b:gist.private | let gist["public"] = function('webapi#json#false') | endif @@ -421,7 +441,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc) return loc endfunction -function! s:GistDelete(gistid) +function! s:GistDelete(gistid) abort let auth = s:GistGetAuthHeader() if len(auth) == 0 redraw @@ -483,7 +503,7 @@ endfunction " " GistID: 123123 " -function! s:GistPost(content, private, desc, anonymous) +function! s:GistPost(content, private, desc, anonymous) abort let gist = { "files" : {}, "description": "","public": function('webapi#json#true') } if a:desc != ' ' | let gist["description"] = a:desc | endif if a:private | let gist["public"] = function('webapi#json#false') | endif @@ -523,7 +543,7 @@ function! s:GistPost(content, private, desc, anonymous) return loc endfunction -function! s:GistPostBuffers(private, desc, anonymous) +function! s:GistPostBuffers(private, desc, anonymous) abort let bufnrs = range(1, bufnr("$")) let bn = bufnr('%') let query = [] @@ -579,7 +599,7 @@ function! s:GistPostBuffers(private, desc, anonymous) return loc endfunction -function! gist#Gist(count, line1, line2, ...) +function! gist#Gist(count, line1, line2, ...) abort redraw if strlen(g:github_user) == 0 echohl ErrorMsg | echomsg "You don't have github account. read ':help gist-vim-setup'." | echohl None @@ -780,7 +800,7 @@ function! gist#Gist(count, line1, line2, ...) return 1 endfunction -function! s:GistGetAuthHeader() +function! s:GistGetAuthHeader() abort if get(g:, 'gist_use_password_in_gitconfig', 0) != 0 let password = substitute(system('git config --get github.password'), "\n", '', '') if password =~ '^!' | let password = system(password[1:]) | endif From 187c2a0479cacd28f84d60a798bab0b5426cf6b1 Mon Sep 17 00:00:00 2001 From: Bao Pham Date: Sun, 1 Jun 2014 16:41:34 -0700 Subject: [PATCH 109/170] Add option to open browser after posting or updating gist --- README.mkd | 4 ++++ autoload/gist.vim | 5 ++++- doc/gist-vim.txt | 4 ++++ plugin/gist.vim | 4 ++-- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.mkd b/README.mkd index 102ac80..1ea916d 100644 --- a/README.mkd +++ b/README.mkd @@ -95,6 +95,10 @@ For the latest version please see https://github.com/mattn/gist-vim. :Gist -ls +- Open the gist on browser after you post or update it. + + :Gist -b + ## Tips: If you set g:gist_clip_command, gist.vim will copy the gist code with option diff --git a/autoload/gist.vim b/autoload/gist.vim index 810ade6..a5b5e82 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -617,6 +617,7 @@ function! gist#Gist(count, line1, line2, ...) abort let deletepost = 0 let editpost = 0 let anonymous = 0 + let openbrowser = 0 let listmx = '^\%(-l\|--list\)\s*\([^\s]\+\)\?$' let bufnamemx = '^' . s:bufprefix .'\(\zs[0-9a-f]\+\ze\|\zs[0-9a-f]\+\ze[/\\].*\)$' if bufname =~ bufnamemx @@ -714,6 +715,8 @@ function! gist#Gist(count, line1, line2, ...) abort return endif endif + elseif arg =~ '^\(-b\|--browser\)$\C' + let openbrowser = 1 elseif arg !~ '^-' && len(gistnm) == 0 if gistdesc != ' ' let gistdesc = matchstr(arg, '^\s*\zs.*\ze\s*$') @@ -779,7 +782,7 @@ function! gist#Gist(count, line1, line2, ...) abort endif endif if len(url) > 0 - if get(g:, 'gist_open_browser_after_post', 0) == 1 + if get(g:, 'gist_open_browser_after_post', 0) == 1 || openbrowser call s:open_browser(url) endif let gist_put_url_to_clipboard_after_post = get(g:, 'gist_put_url_to_clipboard_after_post', 1) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 07311d0..a02f0d9 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -106,6 +106,10 @@ USAGE *:Gist* *gist-vim-usage* > :Gist -ls < +- Open the gist on browser after you post or update it. +> + :Gist -b +< ============================================================================== TIPS *gist-vim-tips* diff --git a/plugin/gist.vim b/plugin/gist.vim index 7e53cd1..63eda8e 100644 --- a/plugin/gist.vim +++ b/plugin/gist.vim @@ -12,9 +12,9 @@ endif let g:loaded_gist_vim = 1 function! s:CompleteArgs(arg_lead,cmdline,cursor_pos) - return ["-p", "-P", "-a", "-m", "-e", "-s", "-d", "+1", "-1", "-f", "-c", "-l", "-la", "-ls", + return ["-p", "-P", "-a", "-m", "-e", "-s", "-d", "+1", "-1", "-f", "-c", "-l", "-la", "-ls", "-b", \ "--listall", "--liststar", "--list", "--multibuffer", "--private", "--public", "--anonymous", "--description", "--clipboard", - \ "--rawurl", "--delete", "--edit", "--star", "--unstar", "--fork" + \ "--rawurl", "--delete", "--edit", "--star", "--unstar", "--fork", "--browser" \ ] endfunction From 1b97d16c8525a4fb47a4dca2ecaa171d3d146f9f Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 6 Jun 2014 10:04:11 +0900 Subject: [PATCH 110/170] Add slash suffix if not have --- autoload/gist.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/autoload/gist.vim b/autoload/gist.vim index a5b5e82..8731193 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -60,6 +60,9 @@ if !exists('g:gist_api_url') endif endif endif +if g:gist_api_url !~ '/$' + let g:gist_api_url .= '/' +endif if !exists('g:gist_update_on_write') let g:gist_update_on_write = 1 From d5bab505ba0d6687ffccb4882aa01bc609e9fa45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=9Blisue?= Date: Thu, 12 Jun 2014 18:54:42 +0900 Subject: [PATCH 111/170] Add gist#list_recursively function. gist#list_recursively(user, [use_cache: 1], [limit: -1], [verbose: 1]) Load gists recursively when there are several pages. --- autoload/gist.vim | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/autoload/gist.vim b/autoload/gist.vim index 8731193..3880de7 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -219,6 +219,62 @@ function! s:GistList(gistls, page) abort redraw | echo '' endfunction +function! gist#list_recursively(user, ...) + let use_cache = get(a:000, 0, 1) + let limit = get(a:000, 1, -1) + let verbose = get(a:000, 2, 1) + if a:user == 'mine' + let url = g:gist_api_url . 'gists' + elseif a:user == 'starred' + let url = g:gist_api_url . 'gists/starred' + else + let url = g:gist_api_url.'users/'.a:user.'/gists' + endif + + let auth = s:GistGetAuthHeader() + if len(auth) == 0 + " anonymous user cannot get gists to prevent infinite recursive loading + return [] + endif + + if use_cache && exists('g:gist_list_recursively_cache') + if has_key(g:gist_list_recursively_cache, a:user) + return webapi#json#decode(g:gist_list_recursively_cache[a:user]) + endif + endif + + let page = 1 + let gists = [] + let lastpage = -1 + + function! s:get_lastpage(res) + let links = split(a:res.header[match(a:res.header, 'Link')], ',') + let link = links[match(links, 'rel=[''"]last[''"]')] + let page = str2nr(matchlist(link, '\%(page=\)\(\d\+\)')[1]) + return page + endfunction + + if verbose > 0 + redraw | echon "Loading gists..." + endif + + while limit == -1 || page <= limit + let res = webapi#http#get(url.'?page='.page, '', {'Authorization': auth}) + if limit == -1 + " update limit to the last page + let limit = s:get_lastpage(res) + endif + if verbose > 0 + redraw | echon "Loading gists... " . page . '/' . limit . " pages has loaded." + endif + let gists = gists + webapi#json#decode(res.content) + let page = page + 1 + endwhile + let g:gist_list_recursively_cache = get(g:, 'gist_list_recursively_cache', {}) + let g:gist_list_recursively_cache[a:user] = webapi#json#encode(gists) + return gists +endfunction + function! gist#list(user, ...) let page = get(a:000, 0, 0) if a:user == '-all' From b37b633e88089c9ac280b07b15e5aa77fe4d99c2 Mon Sep 17 00:00:00 2001 From: pmav99 Date: Sun, 15 Jun 2014 21:08:20 +0300 Subject: [PATCH 112/170] Add installation instructions for NeoBundle Add installation instructions for NeoBundle --- README.mkd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.mkd b/README.mkd index 1ea916d..5c385cd 100644 --- a/README.mkd +++ b/README.mkd @@ -207,6 +207,12 @@ Add the following lines to your `.vimrc`. Now restart Vim and run `:BundleInstall`. +### Install with [NeoBundle](https://github.com/Shougo/neobundle.vim) + +Add the following line to your `.vimrc`. + + NeoBundle 'mattn/gist-vim', {'depends': 'mattn/webapi-vim'} + ## Requirements: - curl command (http://curl.haxx.se/) From 71f123a460afbe46d9e9218a0ba1991fd0c2832d Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 2 Jul 2014 09:47:08 +0900 Subject: [PATCH 113/170] Don't update gist when anonymous. Close #145 --- autoload/gist.vim | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 8731193..c4c24f2 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -741,16 +741,16 @@ function! gist#Gist(count, line1, line2, ...) abort endif endfor unlet args - "echo "gistid=".gistid - "echo "gistls=".gistls - "echo "gistnm=".gistnm - "echo "gistdesc=".gistdesc - "echo "private=".private - "echo "clipboard=".clipboard - "echo "editpost=".editpost - "echo "deletepost=".deletepost - - if gistidbuf != '' && gistid == '' && editpost == 0 && deletepost == 0 + "echom "gistid=".gistid + "echom "gistls=".gistls + "echom "gistnm=".gistnm + "echom "gistdesc=".gistdesc + "echom "private=".private + "echom "clipboard=".clipboard + "echom "editpost=".editpost + "echom "deletepost=".deletepost + + if gistidbuf != '' && gistid == '' && editpost == 0 && deletepost == 0 && anonymous == 0 let editpost = 1 let gistid = gistidbuf endif From 809638707229d73b95b657556cd425c15f886324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Galliat?= Date: Sat, 30 Aug 2014 18:13:39 +0200 Subject: [PATCH 114/170] Add `gist_post_anonymous` option --- autoload/gist.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index eb2203f..6b32186 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -675,7 +675,7 @@ function! gist#Gist(count, line1, line2, ...) abort let clipboard = 0 let deletepost = 0 let editpost = 0 - let anonymous = 0 + let anonymous = get(g:, 'gist_post_anonymous', 0) let openbrowser = 0 let listmx = '^\%(-l\|--list\)\s*\([^\s]\+\)\?$' let bufnamemx = '^' . s:bufprefix .'\(\zs[0-9a-f]\+\ze\|\zs[0-9a-f]\+\ze[/\\].*\)$' From 23d297e7ff664c9a019df4739049451eefccade9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Galliat?= Date: Sat, 30 Aug 2014 18:37:46 +0200 Subject: [PATCH 115/170] Error only if not anonymous --- autoload/gist.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 6b32186..299dcfe 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -660,10 +660,6 @@ endfunction function! gist#Gist(count, line1, line2, ...) abort redraw - if strlen(g:github_user) == 0 - echohl ErrorMsg | echomsg "You don't have github account. read ':help gist-vim-setup'." | echohl None - return - endif let bufname = bufname("%") " find GistID: in content , then we should just update let gistid = '' @@ -679,6 +675,10 @@ function! gist#Gist(count, line1, line2, ...) abort let openbrowser = 0 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 + echohl ErrorMsg | echomsg "You don't have github account. read ':help gist-vim-setup'." | echohl None + return + endif if bufname =~ bufnamemx let gistidbuf = matchstr(bufname, bufnamemx) elseif exists('b:gist') && has_key(b:gist, 'id') From a934a1b6ac753d8a8ecea20deccb9ca326db0964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Galliat?= Date: Sun, 31 Aug 2014 09:21:29 +0200 Subject: [PATCH 116/170] Add `gist_post_anonymous` doc --- README.mkd | 6 ++++++ doc/gist-vim.txt | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/README.mkd b/README.mkd index 5c385cd..5d18bb0 100644 --- a/README.mkd +++ b/README.mkd @@ -142,6 +142,10 @@ If you want your gist to be private by default: let g:gist_post_private = 1 +If you want your gist to be anonymous by default: + + let g:gist_post_anonymous = 1 + If you want to manipulate multiple files in a gist: let g:gist_get_multiplefile = 1 @@ -240,3 +244,5 @@ list of ["Authorized applications" on GitHub's "Account Settings" page][uas]. [uas]: https://github.com/settings/applications + +**Note:** the username is optional if you only send anonymous gists. diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index a02f0d9..9b1504e 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -150,7 +150,10 @@ If you want to show your private gists with ":Gist -l": > If you want your gist to be private by default: > let g:gist_post_private = 1 +< +If you want your gist to be anonymous by default: > + let g:gist_post_anonymous = 1 < If you want to edit all files for gists containing more than one: > @@ -270,6 +273,8 @@ Then, add following into your ~/.vimrc < This is not secure at all, so strongly discouraged. +NOTE: the username is optional if you only send anonymous gists. + ============================================================================== FAQ *gist-vim-faq* From 14eead64c6eea9653ba586e94c75b015c072c601 Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 5 Sep 2014 10:47:53 +0900 Subject: [PATCH 117/170] Create new authentication --- autoload/gist.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index eb2203f..cc511bb 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -906,7 +906,7 @@ function! s:GistGetAuthHeader() abort endif let res = webapi#http#post(g:gist_api_url.'authorizations', webapi#json#encode({ \ "scopes" : ["gist"], - \ "note" : "Gist.vim on ".hostname(), + \ "note" : "Gist.vim on ".hostname().'-'.localtime(), \ "note_url" : "http://www.vim.org/scripts/script.php?script_id=2423" \}), { \ "Content-Type" : "application/json", From a8f44c3cc496a35df812586c2539b4b3d950235c Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 9 Sep 2014 15:55:12 +0900 Subject: [PATCH 118/170] Fix note --- autoload/gist.vim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index dea9211..8c30acf 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -888,11 +888,13 @@ function! s:GistGetAuthHeader() abort let v:errmsg = 'Canceled' return '' endif + let note = "Gist.vim on ".hostname() + 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 res = webapi#http#post(g:gist_api_url.'authorizations', webapi#json#encode({ \ "scopes" : ["gist"], - \ "note" : "Gist.vim on ".hostname(), - \ "note_url" : "http://www.vim.org/scripts/script.php?script_id=2423" + \ "note" : note, + \ "note_url" : note_url, \}), { \ "Content-Type" : "application/json", \ "Authorization" : insecureSecret, @@ -906,8 +908,8 @@ function! s:GistGetAuthHeader() abort endif let res = webapi#http#post(g:gist_api_url.'authorizations', webapi#json#encode({ \ "scopes" : ["gist"], - \ "note" : "Gist.vim on ".hostname().'-'.localtime(), - \ "note_url" : "http://www.vim.org/scripts/script.php?script_id=2423" + \ "note" : note, + \ "note_url" : note_url, \}), { \ "Content-Type" : "application/json", \ "Authorization" : insecureSecret, From 7726ddc55e3c703109767e39441b181c45a47c54 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 9 Sep 2014 22:36:43 +0900 Subject: [PATCH 119/170] Oooooooooooooooooops --- autoload/gist.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 8c30acf..4e3984a 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -889,7 +889,7 @@ function! s:GistGetAuthHeader() abort return '' endif let note = "Gist.vim on ".hostname() - 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 res = webapi#http#post(g:gist_api_url.'authorizations', webapi#json#encode({ \ "scopes" : ["gist"], From 415a1a94e52333130e5b200f5d4828a9055f35c7 Mon Sep 17 00:00:00 2001 From: Justin Page Date: Thu, 25 Sep 2014 11:01:55 -0700 Subject: [PATCH 120/170] resolved #167 --- autoload/gist.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 4e3984a..21183bc 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -888,7 +888,7 @@ function! s:GistGetAuthHeader() abort let v:errmsg = 'Canceled' return '' endif - let note = "Gist.vim on ".hostname() + let note = "Gist.vim on ".hostname()." ".strftime("%Y/%m/%d-%H:%M:%S") 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 res = webapi#http#post(g:gist_api_url.'authorizations', webapi#json#encode({ From bf719108a5e480710fb99b0120af4cd320f37ede Mon Sep 17 00:00:00 2001 From: mattn Date: Sun, 19 Oct 2014 11:31:06 +0900 Subject: [PATCH 121/170] mv --- README.mkd => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.mkd => README.md (100%) diff --git a/README.mkd b/README.md similarity index 100% rename from README.mkd rename to README.md From 9265aaa3fb3f090a292c3fb883eab4cea9d2a722 Mon Sep 17 00:00:00 2001 From: mattn Date: Sun, 19 Oct 2014 11:31:36 +0900 Subject: [PATCH 122/170] Bump up version --- autoload/gist.vim | 4 ++-- gist.vim.vimup | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 21183bc..c717871 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,8 +1,8 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 15-Apr-2014. -" Version: 7.1 +" Last Change: 19-Oct-2014. +" Version: 7.2 " WebPage: http://github.com/mattn/gist-vim " License: BSD diff --git a/gist.vim.vimup b/gist.vim.vimup index 5aee712..a866bf1 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -101,6 +101,9 @@ install_details: | See also: https://github.com/mattn/gist-vim/blob/master/README.mkd versions: +- '7.2': | + This is an upgrade for Gist.vim: fixed many bugs. + - '7.1': | This is an upgrade for Gist.vim: updated installation notes. From d609d93472db9cf45bd701bebe51adc356631547 Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 31 Oct 2014 14:48:06 +0900 Subject: [PATCH 123/170] Fix vimup file --- gist.vim.vimup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gist.vim.vimup b/gist.vim.vimup index a866bf1..fc7ec74 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -2,7 +2,7 @@ script_name: Gist.vim script_id: '2423' script_type: utility script_package: gist-vim.zip -script_version: '7.1' +script_version: '7.2' required_vim_version: '7.0' summary: vimscript for gist From 8a567b823163d349406dffaff4519e0bac10eade Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 17 Dec 2014 17:43:36 +0900 Subject: [PATCH 124/170] Fixes against errors/warnings via vint --- autoload/gist.vim | 247 +++++++++++++++++++++++----------------------- plugin/gist.vim | 2 +- 2 files changed, 126 insertions(+), 123 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index c717871..7810050 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -6,27 +6,27 @@ " WebPage: http://github.com/mattn/gist-vim " License: BSD -let s:save_cpo = &cpo -set cpo&vim +let s:save_cpo = &cpoptions +set cpoptions&vim if exists('g:gist_disabled') && g:gist_disabled == 1 - function gist#Gist(...) + function! gist#Gist(...) abort endfunction finish endif if !exists('g:github_user') && !executable('git') - echohl ErrorMsg | echomsg "Gist: require 'git' command" | echohl None + echohl ErrorMsg | echomsg 'Gist: require ''git'' command' | echohl None finish endif if !executable('curl') - echohl ErrorMsg | echomsg "Gist: require 'curl' command" | echohl None + echohl ErrorMsg | echomsg 'Gist: require ''curl'' command' | echohl None finish endif -if globpath(&rtp, 'autoload/webapi/http.vim') == '' - echohl ErrorMsg | echomsg "Gist: require 'webapi', install https://github.com/mattn/webapi-vim" | echohl None +if globpath(&rtp, 'autoload/webapi/http.vim') ==# '' + echohl ErrorMsg | echomsg 'Gist: require ''webapi'', install https://github.com/mattn/webapi-vim' | echohl None finish endif @@ -48,11 +48,11 @@ if !exists('g:gist_api_url') if exists('g:github_api_url') && !exists('g:gist_shutup_issue154') if matchstr(g:gist_api_url, 'https\?://\zs[^/]\+\ze') != matchstr(g:github_api_url, 'https\?://\zs[^/]\+\ze') echohl WarningMsg - echo "--- Warning ---" - echo "It seems that you set different URIs for github_api_url/gist_api_url." - echo "If you want to remove this message: let g:gist_shutup_issue154 = 1" + echo '--- Warning ---' + echo 'It seems that you set different URIs for github_api_url/gist_api_url.' + echo 'If you want to remove this message: let g:gist_shutup_issue154 = 1' echohl None - if confirm("Continue?", "&Yes\n&No") != 1 + if confirm('Continue?', '&Yes\n&No') != 1 let g:gist_disabled = 1 finish endif @@ -60,7 +60,7 @@ if !exists('g:gist_api_url') endif endif endif -if g:gist_api_url !~ '/$' +if g:gist_api_url !~# '/$' let g:gist_api_url .= '/' endif @@ -68,9 +68,9 @@ if !exists('g:gist_update_on_write') let g:gist_update_on_write = 1 endif -function! s:get_browser_command() +function! s:get_browser_command() abort let gist_browser_command = get(g:, 'gist_browser_command', '') - if gist_browser_command == '' + if gist_browser_command ==# '' if has('win32') || has('win64') let gist_browser_command = '!start rundll32 url.dll,FileProtocolHandler %URL%' elseif has('mac') || has('macunix') || has('gui_macvim') || system('uname') =~? '^darwin' @@ -86,20 +86,20 @@ function! s:get_browser_command() return gist_browser_command endfunction -function! s:open_browser(url) +function! s:open_browser(url) abort let cmd = s:get_browser_command() if len(cmd) == 0 redraw echohl WarningMsg - echo "It seems that you don't have general web browser. Open URL below." + echo 'It seems that you don''t have general web browser. Open URL below.' echohl None echo a:url return endif - if cmd =~ '^!' + if cmd =~# '^!' let cmd = substitute(cmd, '%URL%', '\=shellescape(a:url)', 'g') silent! exec cmd - elseif cmd =~ '^:[A-Z]' + elseif cmd =~# '^:[A-Z]' let cmd = substitute(cmd, '%URL%', '\=a:url', 'g') exec cmd else @@ -108,42 +108,42 @@ function! s:open_browser(url) endif endfunction -function! s:shellwords(str) +function! s:shellwords(str) abort let words = split(a:str, '\%(\([^ \t\''"]\+\)\|''\([^\'']*\)''\|"\(\%([^\"\\]\|\\.\)*\)"\)\zs\s*\ze') let words = map(words, 'substitute(v:val, ''\\\([\\ ]\)'', ''\1'', "g")') let words = map(words, 'matchstr(v:val, ''^\%\("\zs\(.*\)\ze"\|''''\zs\(.*\)\ze''''\|.*\)$'')') return words endfunction -function! s:format_gist(gist) +function! s:format_gist(gist) abort let files = sort(keys(a:gist.files)) if empty(files) - return "" + return '' endif let file = a:gist.files[files[0]] let name = file.filename - if has_key(file, "content") + if has_key(file, 'content') let code = file.content let code = "\n".join(map(split(code, "\n"), '" ".v:val'), "\n") else - let code = "" + let code = '' endif - let desc = type(a:gist.description)==0 || a:gist.description == "" ? "" : '('.a:gist.description.')' + let desc = type(a:gist.description)==0 || a:gist.description ==# '' ? '' : '('.a:gist.description.')' let name = substitute(name, '[\r\n\t]', ' ', 'g') let name = substitute(name, ' ', ' ', 'g') let desc = substitute(desc, '[\r\n\t]', ' ', 'g') let desc = substitute(desc, ' ', ' ', 'g') - return printf("gist: %s %s %s%s", a:gist.id, name, desc, code) + return printf('gist: %s %s %s%s', a:gist.id, name, desc, code) 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 - if a:gistls == '-all' + if a:gistls ==# '-all' 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' let url = g:gist_api_url.'gists/starred' - elseif get(g:, 'gist_show_privates') && a:gistls == 'mine' + elseif get(g:, 'gist_show_privates') && a:gistls ==# 'mine' let url = g:gist_api_url.'gists' else let url = g:gist_api_url.'users/'.a:gistls.'/gists' @@ -193,7 +193,7 @@ function! s:GistList(gistls, page) abort bw! redraw echohl ErrorMsg | echomsg content.message | echohl None - if content.message == 'Bad credentials' + if content.message ==# 'Bad credentials' call delete(s:gist_token_file) endif return @@ -219,13 +219,13 @@ function! s:GistList(gistls, page) abort redraw | echo '' endfunction -function! gist#list_recursively(user, ...) +function! gist#list_recursively(user, ...) abort let use_cache = get(a:000, 0, 1) let limit = get(a:000, 1, -1) let verbose = get(a:000, 2, 1) - if a:user == 'mine' + if a:user ==# 'mine' let url = g:gist_api_url . 'gists' - elseif a:user == 'starred' + elseif a:user ==# 'starred' let url = g:gist_api_url . 'gists/starred' else let url = g:gist_api_url.'users/'.a:user.'/gists' @@ -247,7 +247,7 @@ function! gist#list_recursively(user, ...) let gists = [] let lastpage = -1 - function! s:get_lastpage(res) + function! s:get_lastpage(res) abort let links = split(a:res.header[match(a:res.header, 'Link')], ',') let link = links[match(links, 'rel=[''"]last[''"]')] let page = str2nr(matchlist(link, '\%(page=\)\(\d\+\)')[1]) @@ -255,7 +255,7 @@ function! gist#list_recursively(user, ...) endfunction if verbose > 0 - redraw | echon "Loading gists..." + redraw | echon 'Loading gists...' endif while limit == -1 || page <= limit @@ -265,7 +265,7 @@ function! gist#list_recursively(user, ...) let limit = s:get_lastpage(res) endif if verbose > 0 - redraw | echon "Loading gists... " . page . '/' . limit . " pages has loaded." + redraw | echon 'Loading gists... ' . page . '/' . limit . ' pages has loaded.' endif let gists = gists + webapi#json#decode(res.content) let page = page + 1 @@ -275,13 +275,13 @@ function! gist#list_recursively(user, ...) return gists endfunction -function! gist#list(user, ...) +function! gist#list(user, ...) abort let page = get(a:000, 0, 0) - if a:user == '-all' + if a:user ==# '-all' let url = g:gist_api_url.'gists/public' - elseif get(g:, 'gist_show_privates', 0) && a:user == 'starred' + elseif get(g:, 'gist_show_privates', 0) && a:user ==# 'starred' let url = g:gist_api_url.'gists/starred' - elseif get(g:, 'gist_show_privates') && a:user == 'mine' + elseif get(g:, 'gist_show_privates') && a:user ==# 'mine' let url = g:gist_api_url.'gists' else let url = g:gist_api_url.'users/'.a:user.'/gists' @@ -320,9 +320,9 @@ function! s:GistDetectFiletype(gistid) abort if has_key(s:extmap, ext) let type = s:extmap[ext] else - let type = get(gist.files[filename], "type", "text") + let type = get(gist.files[filename], 'type', 'text') endif - silent! exec "setlocal ft=".tolower(type) + silent! exec 'setlocal ft='.tolower(type) endfunction function! s:GistWrite(fname) abort @@ -333,8 +333,8 @@ function! s:GistWrite(fname) abort echohl ErrorMsg | echomsg 'Please type ":w!" to update a gist.' | echohl None endif else - exe "w".(v:cmdbang ? "!" : "") fnameescape(v:cmdarg) fnameescape(a:fname) - silent! exe "file" fnameescape(a:fname) + exe 'w'.(v:cmdbang ? '!' : '') fnameescape(v:cmdarg) fnameescape(a:fname) + silent! exe 'file' fnameescape(a:fname) silent! au! BufWriteCmd endif endfunction @@ -342,7 +342,7 @@ endfunction function! s:GistGet(gistid, clipboard) abort redraw | echon 'Getting gist... ' let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { "Authorization": s:GistGetAuthHeader() }) - if res.status =~ '^2' + if res.status =~# '^2' try let gist = webapi#json#decode(res.content) catch @@ -365,7 +365,7 @@ function! s:GistGet(gistid, clipboard) abort let old_undolevels = &undolevels let filename = sort(keys(gist.files))[n] - let winnum = bufwinnr(bufnr(s:bufprefix.a:gistid."/".filename)) + let winnum = bufwinnr(bufnr(s:bufprefix.a:gistid.'/'.filename)) if winnum != -1 if winnum != bufwinnr('%') exe winnum 'wincmd w' @@ -381,7 +381,7 @@ function! s:GistGet(gistid, clipboard) abort exec 'silent noautocmd rightbelow new' endif setlocal noswapfile - silent exec 'noautocmd file' s:bufprefix.a:gistid."/".fnameescape(filename) + silent exec 'noautocmd file' s:bufprefix.a:gistid.'/'.fnameescape(filename) endif set undolevels=-1 filetype detect @@ -407,7 +407,7 @@ function! s:GistGet(gistid, clipboard) abort setlocal nomodified doau StdinReadPost,BufRead,BufReadPost let gist_detect_filetype = get(g:, 'gist_detect_filetype', 0) - if (&ft == '' && gist_detect_filetype == 1) || gist_detect_filetype == 2 + if (&ft ==# '' && gist_detect_filetype == 1) || gist_detect_filetype == 2 call s:GistDetectFiletype(a:gistid) endif if a:clipboard @@ -420,7 +420,10 @@ function! s:GistGet(gistid, clipboard) abort endif endif 1 - au! BufWriteCmd call s:GistWrite(expand("")) + augroup GistWrite + au! + au! BufWriteCmd call s:GistWrite(expand("")) + augroup END endfor else bw! @@ -436,7 +439,7 @@ function! s:GistListAction(shift) abort if line =~# mx let gistid = matchstr(line, mx) if a:shift - call s:open_browser("https://gist.github.com/" . gistid) + call s:open_browser('https://gist.github.com/' . gistid) else call s:GistGet(gistid, 0) endif @@ -451,8 +454,8 @@ endfunction function! s:GistUpdate(content, gistid, gistnm, desc) abort let gist = { "id": a:gistid, "files" : {}, "description": "","public": function('webapi#json#true') } if exists('b:gist') - if has_key(b:gist, 'private') && b:gist.private | let gist["public"] = function('webapi#json#false') | endif - if has_key(b:gist, 'description') | let gist["description"] = b:gist.description | endif + if has_key(b:gist, 'private') && b:gist.private | let gist['public'] = function('webapi#json#false') | endif + if has_key(b:gist, 'description') | let gist['description'] = b:gist.description | endif if has_key(b:gist, 'filename') | let filename = b:gist.filename | endif else let filename = a:gistnm @@ -469,13 +472,13 @@ function! s:GistUpdate(content, gistid, gistnm, desc) abort " Update description " If no new description specified, keep the old description - if a:desc != ' ' - let gist["description"] = a:desc + if a:desc !=# ' ' + let gist['description'] = a:desc else 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 gist["description"] = old_gist.description + let gist['description'] = old_gist.description endif endif @@ -487,9 +490,9 @@ function! s:GistUpdate(content, gistid, gistnm, desc) abort \ "Authorization": auth, \ "Content-Type": "application/json", \}) - if res.status =~ '^2' + if res.status =~# '^2' let obj = webapi#json#decode(res.content) - let loc = obj["html_url"] + let loc = obj['html_url'] redraw | echomsg 'Done: '.loc let b:gist = {"id": a:gistid, "filename": filename} setlocal nomodified @@ -513,7 +516,7 @@ function! s:GistDelete(gistid) abort \ "Authorization": auth, \ "Content-Type": "application/json", \}, 'DELETE') - if res.status =~ '^2' + if res.status =~# '^2' redraw | echomsg 'Done: ' if exists('b:gist') unlet b:gist @@ -523,21 +526,21 @@ function! s:GistDelete(gistid) abort endif endfunction -function! s:get_current_filename(no) +function! s:get_current_filename(no) abort let filename = expand('%:t') - if len(filename) == 0 && &ft != '' + if len(filename) == 0 && &ft !=# '' let pair = filter(items(s:extmap), 'v:val[1] == &ft') if len(pair) > 0 let filename = printf('gistfile%d%s', a:no, pair[0][0]) endif endif - if filename == '' + if filename ==# '' let filename = printf('gistfile%d.txt', a:no) endif return filename endfunction -function! s:update_GistID(id) +function! s:update_GistID(id) abort let view = winsaveview() normal! gg let ret = 0 @@ -564,8 +567,8 @@ endfunction " function! s:GistPost(content, private, desc, anonymous) abort let gist = { "files" : {}, "description": "","public": function('webapi#json#true') } - if a:desc != ' ' | let gist["description"] = a:desc | endif - if a:private | let gist["public"] = function('webapi#json#false') | endif + if a:desc !=# ' ' | let gist['description'] = a:desc | endif + if a:private | let gist['public'] = function('webapi#json#false') | endif let filename = s:get_current_filename(1) let gist.files[filename] = { "content": a:content, "filename": filename } @@ -577,14 +580,14 @@ function! s:GistPost(content, private, desc, anonymous) abort echohl ErrorMsg | echomsg v:errmsg | echohl None return endif - let header["Authorization"] = auth + let header['Authorization'] = auth endif redraw | echon 'Posting it to gist... ' let res = webapi#http#post(g:gist_api_url.'gists', webapi#json#encode(gist), header) - if res.status =~ '^2' + if res.status =~# '^2' let obj = webapi#json#decode(res.content) - let loc = obj["html_url"] + let loc = obj['html_url'] redraw | echomsg 'Done: '.loc let b:gist = { \ "filename": filename, @@ -592,7 +595,7 @@ function! s:GistPost(content, private, desc, anonymous) abort \ "description": gist['description'], \ "private": a:private, \} - if s:update_GistID(b:gist["id"]) + if s:update_GistID(b:gist['id']) Gist -e endif else @@ -603,27 +606,27 @@ function! s:GistPost(content, private, desc, anonymous) abort endfunction function! s:GistPostBuffers(private, desc, anonymous) abort - let bufnrs = range(1, bufnr("$")) + let bufnrs = range(1, bufnr('$')) let bn = bufnr('%') let query = [] let gist = { "files" : {}, "description": "","public": function('webapi#json#true') } - if a:desc != ' ' | let gist["description"] = a:desc | endif - if a:private | let gist["public"] = function('webapi#json#false') | endif + if a:desc !=# ' ' | let gist['description'] = a:desc | endif + if a:private | let gist['public'] = function('webapi#json#false') | endif let index = 1 for bufnr in bufnrs if !bufexists(bufnr) || buflisted(bufnr) == 0 continue endif - echo "Creating gist content".index."... " - silent! exec "buffer!" bufnr + echo 'Creating gist content'.index.'... ' + silent! exec 'buffer!' bufnr let content = join(getline(1, line('$')), "\n") let filename = s:get_current_filename(index) let gist.files[filename] = { "content": content, "filename": filename } let index = index + 1 endfor - silent! exec "buffer!" bn + silent! exec 'buffer!' bn let header = {"Content-Type": "application/json"} if !a:anonymous @@ -633,14 +636,14 @@ function! s:GistPostBuffers(private, desc, anonymous) abort echohl ErrorMsg | echomsg v:errmsg | echohl None return endif - let header["Authorization"] = auth + let header['Authorization'] = auth endif redraw | echon 'Posting it to gist... ' let res = webapi#http#post(g:gist_api_url.'gists', webapi#json#encode(gist), header) - if res.status =~ '^2' + if res.status =~# '^2' let obj = webapi#json#decode(res.content) - let loc = obj["html_url"] + let loc = obj['html_url'] redraw | echomsg 'Done: '.loc let b:gist = { \ "filename": filename, @@ -648,7 +651,7 @@ function! s:GistPostBuffers(private, desc, anonymous) abort \ "description": gist['description'], \ "private": a:private, \} - if s:update_GistID(b:gist["id"]) + if s:update_GistID(b:gist['id']) Gist -e endif else @@ -660,7 +663,7 @@ endfunction function! gist#Gist(count, line1, line2, ...) abort redraw - let bufname = bufname("%") + let bufname = bufname('%') " find GistID: in content , then we should just update let gistid = '' let gistls = '' @@ -676,10 +679,10 @@ function! gist#Gist(count, line1, line2, ...) abort 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 - echohl ErrorMsg | echomsg "You don't have github account. read ':help gist-vim-setup'." | echohl None + echohl ErrorMsg | echomsg 'You don''t have github account. read '':help gist-vim-setup''.' | echohl None return endif - if bufname =~ bufnamemx + if bufname =~# bufnamemx let gistidbuf = matchstr(bufname, bufnamemx) elseif exists('b:gist') && has_key(b:gist, 'id') let gistidbuf = b:gist['id'] @@ -689,76 +692,76 @@ function! gist#Gist(count, line1, line2, ...) abort let args = (a:0 > 0) ? s:shellwords(a:1) : [] for arg in args - if arg =~ '^\(-h\|--help\)$\C' + if arg =~# '^\(-h\|--help\)$\C' help :Gist return - elseif arg =~ '^\(-g\|--git\)$\C' && gistidbuf != '' && g:gist_api_url == 'https://api.github.com/' && has_key(b:, 'gist') && has_key(b:gist, 'id') + elseif arg =~# '^\(-g\|--git\)$\C' && gistidbuf !=# '' && g:gist_api_url ==# 'https://api.github.com/' && has_key(b:, 'gist') && has_key(b:gist, 'id') echo printf('git clone git@github.com:%s', b:gist['id']) return - 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']) return - elseif arg =~ '^\(-la\|--listall\)$\C' + elseif arg =~# '^\(-la\|--listall\)$\C' let gistls = '-all' - elseif arg =~ '^\(-ls\|--liststar\)$\C' + elseif arg =~# '^\(-ls\|--liststar\)$\C' let gistls = 'starred' - elseif arg =~ '^\(-l\|--list\)$\C' + elseif arg =~# '^\(-l\|--list\)$\C' if get(g:, 'gist_show_privates') let gistls = 'mine' else let gistls = g:github_user endif - elseif arg =~ '^\(-m\|--multibuffer\)$\C' + elseif arg =~# '^\(-m\|--multibuffer\)$\C' let multibuffer = 1 - elseif arg =~ '^\(-p\|--private\)$\C' + elseif arg =~# '^\(-p\|--private\)$\C' let private = 1 - elseif arg =~ '^\(-P\|--public\)$\C' + elseif arg =~# '^\(-P\|--public\)$\C' let private = 0 - elseif arg =~ '^\(-a\|--anonymous\)$\C' + elseif arg =~# '^\(-a\|--anonymous\)$\C' let anonymous = 1 - elseif arg =~ '^\(-s\|--description\)$\C' + elseif arg =~# '^\(-s\|--description\)$\C' let gistdesc = '' - elseif arg =~ '^\(-c\|--clipboard\)$\C' + elseif arg =~# '^\(-c\|--clipboard\)$\C' let clipboard = 1 - elseif arg =~ '^--rawurl$\C' && gistidbuf != '' && g:gist_api_url == 'https://api.github.com/' + elseif arg =~# '^--rawurl$\C' && gistidbuf !=# '' && g:gist_api_url ==# 'https://api.github.com/' let gistid = gistidbuf echo 'https://gist.github.com/raw/'.gistid return - elseif arg =~ '^\(-d\|--delete\)$\C' && gistidbuf != '' + elseif arg =~# '^\(-d\|--delete\)$\C' && gistidbuf !=# '' let gistid = gistidbuf let deletepost = 1 - elseif arg =~ '^\(-e\|--edit\)$\C' && gistidbuf != '' + elseif arg =~# '^\(-e\|--edit\)$\C' && gistidbuf !=# '' let gistid = gistidbuf let editpost = 1 - elseif arg =~ '^\(+1\|--star\)$\C' && gistidbuf != '' + elseif arg =~# '^\(+1\|--star\)$\C' && gistidbuf !=# '' let auth = s:GistGetAuthHeader() if len(auth) == 0 echohl ErrorMsg | echomsg v:errmsg | echohl None else let gistid = gistidbuf let res = webapi#http#post(g:gist_api_url.'gists/'.gistid.'/star', '', { "Authorization": auth }, 'PUT') - if res.status =~ '^2' - echomsg "Stared" gistid + if res.status =~# '^2' + echomsg 'Stared' gistid else echohl ErrorMsg | echomsg 'Star failed' | echohl None endif endif return - elseif arg =~ '^\(-1\|--unstar\)$\C' && gistidbuf != '' + elseif arg =~# '^\(-1\|--unstar\)$\C' && gistidbuf !=# '' let auth = s:GistGetAuthHeader() if len(auth) == 0 echohl ErrorMsg | echomsg v:errmsg | echohl None else let gistid = gistidbuf let res = webapi#http#post(g:gist_api_url.'gists/'.gistid.'/star', '', { "Authorization": auth }, 'DELETE') - if res.status =~ '^2' - echomsg "Unstared" gistid + if res.status =~# '^2' + echomsg 'Unstared' gistid else echohl ErrorMsg | echomsg 'Unstar failed' | echohl None endif endif return - elseif arg =~ '^\(-f\|--fork\)$\C' && gistidbuf != '' + elseif arg =~# '^\(-f\|--fork\)$\C' && gistidbuf !=# '' let auth = s:GistGetAuthHeader() if len(auth) == 0 echohl ErrorMsg | echomsg v:errmsg | echohl None @@ -766,24 +769,24 @@ function! gist#Gist(count, line1, line2, ...) abort else let gistid = gistidbuf 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 gistid = obj["id"] + let gistid = obj['id'] else echohl ErrorMsg | echomsg 'Fork failed' | echohl None return endif endif - elseif arg =~ '^\(-b\|--browser\)$\C' + elseif arg =~# '^\(-b\|--browser\)$\C' let openbrowser = 1 - elseif arg !~ '^-' && len(gistnm) == 0 - if gistdesc != ' ' + elseif arg !~# '^-' && len(gistnm) == 0 + if gistdesc !=# ' ' let gistdesc = matchstr(arg, '^\s*\zs.*\ze\s*$') elseif editpost == 1 || deletepost == 1 let gistnm = arg - elseif len(gistls) > 0 && arg != '^\w\+$\C' + elseif len(gistls) > 0 && arg !=# '^\w\+$\C' let gistls = arg - elseif arg =~ '^[0-9a-z]\+$\C' + elseif arg =~# '^[0-9a-z]\+$\C' let gistid = arg else echohl ErrorMsg | echomsg 'Invalid arguments: '.arg | echohl None @@ -806,7 +809,7 @@ function! gist#Gist(count, line1, line2, ...) abort "echom "editpost=".editpost "echom "deletepost=".deletepost - if gistidbuf != '' && gistid == '' && editpost == 0 && deletepost == 0 && anonymous == 0 + if gistidbuf !=# '' && gistid ==# '' && editpost == 0 && deletepost == 0 && anonymous == 0 let editpost = 1 let gistid = gistidbuf endif @@ -865,12 +868,12 @@ endfunction function! s:GistGetAuthHeader() abort if get(g:, 'gist_use_password_in_gitconfig', 0) != 0 let password = substitute(system('git config --get github.password'), "\n", '', '') - if password =~ '^!' | let password = system(password[1:]) | endif - return printf("basic %s", webapi#base64#b64encode(g:github_user.":".password)) + if password =~# '^!' | let password = system(password[1:]) | endif + return printf('basic %s', webapi#base64#b64encode(g:github_user.':'.password)) endif - let auth = "" + let auth = '' if filereadable(s:gist_token_file) - let str = join(readfile(s:gist_token_file), "") + let str = join(readfile(s:gist_token_file), '') if type(str) == 1 let auth = str endif @@ -883,14 +886,14 @@ function! s:GistGetAuthHeader() abort echohl WarningMsg echo 'Gist.vim requires authorization to use the GitHub API. These settings are stored in "~/.gist-vim". If you want to revoke, do "rm ~/.gist-vim".' echohl None - let password = inputsecret("GitHub Password for ".g:github_user.":") + let password = inputsecret('GitHub Password for '.g:github_user.':') if len(password) == 0 let v:errmsg = 'Canceled' return '' endif - let note = "Gist.vim on ".hostname()." ".strftime("%Y/%m/%d-%H:%M:%S") - 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 note = 'Gist.vim on '.hostname().' '.strftime('%Y/%m/%d-%H:%M:%S') + 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 res = webapi#http#post(g:gist_api_url.'authorizations', webapi#json#encode({ \ "scopes" : ["gist"], \ "note" : note, @@ -901,7 +904,7 @@ function! s:GistGetAuthHeader() abort \}) let h = filter(res.header, 'stridx(v:val, "X-GitHub-OTP:") == 0') if len(h) - let otp = inputsecret("OTP:") + let otp = inputsecret('OTP:') if len(otp) == 0 let v:errmsg = 'Canceled' return '' @@ -918,10 +921,10 @@ function! s:GistGetAuthHeader() abort endif let authorization = webapi#json#decode(res.content) if has_key(authorization, 'token') - let secret = printf("token %s", authorization.token) + let secret = printf('token %s', authorization.token) call writefile([secret], s:gist_token_file) if !(has('win32') || has('win64')) - call system("chmod go= ".s:gist_token_file) + call system('chmod go= '.s:gist_token_file) endif elseif has_key(authorization, 'message') let secret = '' diff --git a/plugin/gist.vim b/plugin/gist.vim index 63eda8e..8a4ff94 100644 --- a/plugin/gist.vim +++ b/plugin/gist.vim @@ -6,7 +6,7 @@ " GetLatestVimScripts: 2423 1 :AutoInstall: gist.vim " script type: plugin -if &cp || (exists('g:loaded_gist_vim') && g:loaded_gist_vim) +if &compatible || (exists('g:loaded_gist_vim') && g:loaded_gist_vim) finish endif let g:loaded_gist_vim = 1 From 3643fb4192b9773685e935e933e4d4fdedfdf092 Mon Sep 17 00:00:00 2001 From: "Steven G. Harms" Date: Mon, 9 Feb 2015 14:29:40 -0500 Subject: [PATCH 125/170] Update gist-vim.txt --- doc/gist-vim.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 9b1504e..aa4d9bb 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -240,8 +240,8 @@ REQUIREMENTS *gist-vim-requirements* ============================================================================== SETUP *gist-vim-setup* -This plugin uses GitHub API v3. Setting value is stored in `~/.gist-vim`. -gist-vim have two ways to access APIs. +This plugin uses GitHub API v3. The authentication value is stored in `~/.gist-vim`. +gist-vim provides two ways to authenticate against the GitHub APIs. First, you need to set your GitHub username in global git config: > @@ -278,8 +278,8 @@ NOTE: the username is optional if you only send anonymous gists. ============================================================================== FAQ *gist-vim-faq* -Q. :Gist give Forbidden error -A. Try to delete ~/.gist-vim. And authenticate again. +Q. :Gist returns a Forbidden error +A. Try deleting ~/.gist-vim and authenticating again. ============================================================================== THANKS *gist-vim-thanks* From 17cc1b1f532154eb920490b5e355429aeaca2257 Mon Sep 17 00:00:00 2001 From: Jarno Tuovinen Date: Fri, 20 Feb 2015 11:44:55 +0200 Subject: [PATCH 126/170] Fix typos at autoload/gist.vim --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 7810050..916951e 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -741,7 +741,7 @@ function! gist#Gist(count, line1, line2, ...) abort let gistid = gistidbuf let res = webapi#http#post(g:gist_api_url.'gists/'.gistid.'/star', '', { "Authorization": auth }, 'PUT') if res.status =~# '^2' - echomsg 'Stared' gistid + echomsg 'Starred' gistid else echohl ErrorMsg | echomsg 'Star failed' | echohl None endif @@ -755,7 +755,7 @@ function! gist#Gist(count, line1, line2, ...) abort let gistid = gistidbuf let res = webapi#http#post(g:gist_api_url.'gists/'.gistid.'/star', '', { "Authorization": auth }, 'DELETE') if res.status =~# '^2' - echomsg 'Unstared' gistid + echomsg 'Unstarred' gistid else echohl ErrorMsg | echomsg 'Unstar failed' | echohl None endif From 370d0d32caf1187f581c221b07b6d01c4f5ab105 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Tue, 3 Mar 2015 10:13:57 +0900 Subject: [PATCH 127/170] Add gist_edit_with_buffers to keep current editing buffers --- autoload/gist.vim | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 916951e..3e83ca8 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -373,12 +373,39 @@ function! s:GistGet(gistid, clipboard) abort setlocal modifiable else if num_file == 1 - silent only! - endif - if get(g:, 'gist_list_vsplit', 0) - exec 'silent noautocmd rightbelow vnew' + if get(g:, 'gist_edith_with_buffers', 0) + let found = -1 + for wnr in range(1, winnr('$')) + let bnr = winbufnr(wnr) + if bnr != -1 && !empty(getbufvar(bnr, 'gist')) + let found = wnr + break + endif + endfor + if found != -1 + exe found 'wincmd w' + setlocal modifiable + else + if get(g:, 'gist_list_vsplit', 0) + exec 'silent noautocmd rightbelow vnew' + else + exec 'silent noautocmd rightbelow new' + endif + endif + else + silent only! + if get(g:, 'gist_list_vsplit', 0) + exec 'silent noautocmd rightbelow vnew' + else + exec 'silent noautocmd rightbelow new' + endif + endif else - exec 'silent noautocmd rightbelow new' + if get(g:, 'gist_list_vsplit', 0) + exec 'silent noautocmd rightbelow vnew' + else + exec 'silent noautocmd rightbelow new' + endif endif setlocal noswapfile silent exec 'noautocmd file' s:bufprefix.a:gistid.'/'.fnameescape(filename) From afd74f4e400f2040c64f6cd14be0d99a9612ae1a Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 4 Mar 2015 01:03:53 +0900 Subject: [PATCH 128/170] Fix typo --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 3e83ca8..a1275ea 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 19-Oct-2014. +" Last Change: 04-Mar-2015. " Version: 7.2 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -373,7 +373,7 @@ function! s:GistGet(gistid, clipboard) abort setlocal modifiable else if num_file == 1 - if get(g:, 'gist_edith_with_buffers', 0) + if get(g:, 'gist_edit_with_buffers', 0) let found = -1 for wnr in range(1, winnr('$')) let bnr = winbufnr(wnr) From c4aba40b8420ab02901e7065f5f7bcba186a0903 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Tue, 3 Mar 2015 10:16:50 +0900 Subject: [PATCH 129/170] Update doc --- doc/gist-vim.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index aa4d9bb..f038872 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -159,11 +159,21 @@ If you want to edit all files for gists containing more than one: > let g:gist_get_multiplefile = 1 < - If you want to use on GitHub Enterprise: > let g:gist_api_url = 'http://your-github-enterprise-domain/api/v3' < +If you want to open gist with current editing buffers: > + + let g:gist_edit_with_buffers = 1 + +If you want to open gist with current editing buffers: > + + let g:gist_edit_with_buffers = 1 + +If you want to open gist list/buffer as vertical split: > + + let g:gist_list_vsplit = 1 If you want to update a gist, embed > From e16584ac61b43426435fa4253deb6a63266135db Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Tue, 17 Mar 2015 09:05:25 +0900 Subject: [PATCH 130/170] ! should work forcely. Close #175, #180 --- autoload/gist.vim | 6 ++++-- plugin/gist.vim | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index a1275ea..506df66 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -688,7 +688,7 @@ function! s:GistPostBuffers(private, desc, anonymous) abort return loc endfunction -function! gist#Gist(count, line1, line2, ...) abort +function! gist#Gist(count, bang, line1, line2, ...) abort redraw let bufname = bufname('%') " find GistID: in content , then we should just update @@ -709,7 +709,9 @@ function! gist#Gist(count, line1, line2, ...) abort echohl ErrorMsg | echomsg 'You don''t have github account. read '':help gist-vim-setup''.' | echohl None return endif - if bufname =~# bufnamemx + if a:bang == '!' + let gistidbuf = '' + elseif bufname =~# bufnamemx let gistidbuf = matchstr(bufname, bufnamemx) elseif exists('b:gist') && has_key(b:gist, 'id') let gistidbuf = b:gist['id'] diff --git a/plugin/gist.vim b/plugin/gist.vim index 8a4ff94..ab4f456 100644 --- a/plugin/gist.vim +++ b/plugin/gist.vim @@ -18,6 +18,6 @@ function! s:CompleteArgs(arg_lead,cmdline,cursor_pos) \ ] endfunction -command! -nargs=? -range=% -complete=customlist,s:CompleteArgs Gist :call gist#Gist(, , , ) +command! -nargs=? -range=% -bang -complete=customlist,s:CompleteArgs Gist :call gist#Gist(, "", , , ) " vim:set et: From aa16142ce66dabdf40fcb6d6d952f9407ff23942 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Tue, 17 Mar 2015 13:06:33 +0900 Subject: [PATCH 131/170] Update doc --- doc/gist-vim.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index f038872..4ddde26 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -110,6 +110,10 @@ USAGE *:Gist* *gist-vim-usage* > :Gist -b < +- Post as new gist after editing on the buffer. +> + :Gist! +< ============================================================================== TIPS *gist-vim-tips* From 7e6c54a9e6be36d73b0188e89377ce183753cc62 Mon Sep 17 00:00:00 2001 From: mattn Date: Sun, 22 Mar 2015 02:05:40 +0900 Subject: [PATCH 132/170] load webapi to avoid to return 0 by function('webapi#json#true') --- autoload/gist.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index a1275ea..54b76af 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 04-Mar-2015. +" Last Change: 21-Mar-2015. " Version: 7.2 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -28,6 +28,8 @@ endif if globpath(&rtp, 'autoload/webapi/http.vim') ==# '' echohl ErrorMsg | echomsg 'Gist: require ''webapi'', install https://github.com/mattn/webapi-vim' | echohl None finish +else + call webapi#json#true() endif let s:gist_token_file = expand(get(g:, 'gist_token_file', '~/.gist-vim')) From 22eeb3a72f116818dec0e2f9fe3ea46443141b95 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Wed, 25 Mar 2015 03:47:40 +0900 Subject: [PATCH 133/170] Rename with ':Gist -e newname'. Close #177 --- autoload/gist.vim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 683dabb..0cd0c97 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -483,6 +483,10 @@ endfunction function! s:GistUpdate(content, gistid, gistnm, desc) abort let gist = { "id": a:gistid, "files" : {}, "description": "","public": function('webapi#json#true') } if exists('b:gist') + if has_key(b:gist, 'filename') && len(a:gistnm) > 0 + let gist.files[b:gist.filename] = { "content": '', "filename": b:gist.filename } + let b:gist.filename = a:gistnm + endif if has_key(b:gist, 'private') && b:gist.private | let gist['public'] = function('webapi#json#false') | endif if has_key(b:gist, 'description') | let gist['description'] = b:gist.description | endif if has_key(b:gist, 'filename') | let filename = b:gist.filename | endif @@ -761,8 +765,10 @@ function! gist#Gist(count, bang, line1, line2, ...) abort elseif arg =~# '^\(-d\|--delete\)$\C' && gistidbuf !=# '' let gistid = gistidbuf let deletepost = 1 - elseif arg =~# '^\(-e\|--edit\)$\C' && gistidbuf !=# '' - let gistid = gistidbuf + elseif arg =~# '^\(-e\|--edit\)$\C' + if gistidbuf !=# '' + let gistid = gistidbuf + endif let editpost = 1 elseif arg =~# '^\(+1\|--star\)$\C' && gistidbuf !=# '' let auth = s:GistGetAuthHeader() From 7a3572c18fe7418bf97d51eae687c2e1d14bf266 Mon Sep 17 00:00:00 2001 From: tyru Date: Sun, 3 May 2015 20:22:33 +0900 Subject: [PATCH 134/170] check url variable type --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 0cd0c97..3c2be02 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 21-Mar-2015. +" Last Change: 03-May-2015. " Version: 7.2 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -880,7 +880,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort silent! normal! gv endif endif - if len(url) > 0 + if type(url) == 1 && len(url) > 0 if get(g:, 'gist_open_browser_after_post', 0) == 1 || openbrowser call s:open_browser(url) endif From f76987b6244bc77b4a4263dd5e37b7e4c9ea59ff Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Thu, 28 May 2015 13:56:29 +0900 Subject: [PATCH 135/170] customizable extmap --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 3c2be02..69c3a12 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -970,7 +970,7 @@ function! s:GistGetAuthHeader() abort return secret endfunction -let s:extmap = { +let s:extmap = extend({ \".adb": "ada", \".ahk": "ahk", \".arc": "arc", @@ -1102,7 +1102,7 @@ let s:extmap = { \".xq": "xquery", \".xs": "xs", \".yml": "yaml", -\} +\}, get(g:, 'gist_extmap', {})) let &cpo = s:save_cpo unlet s:save_cpo From e09acaf6f94bb778c9fa5b45eed82946438c615c Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 29 May 2015 00:37:52 +0200 Subject: [PATCH 136/170] minor: improve grammar with "no github account" error message --- autoload/gist.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 69c3a12..81fed84 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -712,7 +712,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort 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 - echohl ErrorMsg | echomsg 'You don''t have github account. read '':help gist-vim-setup''.' | echohl None + echohl ErrorMsg | echomsg 'You don''t have configured a Github account. Read '':help gist-vim-setup''.' | echohl None return endif if a:bang == '!' From 9e5fe4e5975587f3017aec45d8a455aaa4745f6e Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Fri, 29 May 2015 09:04:22 +0900 Subject: [PATCH 137/170] add swift. close #185 --- autoload/gist.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/autoload/gist.vim b/autoload/gist.vim index 81fed84..9265f16 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1085,6 +1085,7 @@ let s:extmap = extend({ \".sml": "sml", \".sql": "sql", \".st": "smalltalk", +\".switf": "switf", \".tcl": "tcl", \".tcsh": "tcsh", \".tex": "tex", From ee30dfbb8573f5d88e7454789948d9889183eeb8 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Fri, 29 May 2015 09:05:45 +0900 Subject: [PATCH 138/170] typo --- autoload/gist.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 9265f16..15aa273 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1085,7 +1085,7 @@ let s:extmap = extend({ \".sml": "sml", \".sql": "sql", \".st": "smalltalk", -\".switf": "switf", +\".swift": "swift", \".tcl": "tcl", \".tcsh": "tcsh", \".tex": "tex", From 235955468c2d85e5d0ece46d84948acf2bedeb20 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Fri, 29 May 2015 12:59:25 +0900 Subject: [PATCH 139/170] update doc --- doc/gist-vim.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 4ddde26..9839324 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -179,6 +179,13 @@ If you want to open gist list/buffer as vertical split: > let g:gist_list_vsplit = 1 +If you want to modify filetype for the file on github, or add mapping of +filetype/file-extension: > + + let g:gist_extmap = { ".swift": "swift" } +< + key is file-extension, value is filetype. + If you want to update a gist, embed > GistID: xxxxx From 1985efd9844762b830b4141b72ffbf85d57f6322 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 8 Jun 2015 08:50:52 +0900 Subject: [PATCH 140/170] message Done $url should be displayed at the last of sequences. related issue #188 --- autoload/gist.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 15aa273..dbfad7d 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -526,9 +526,9 @@ function! s:GistUpdate(content, gistid, gistnm, desc) abort if res.status =~# '^2' let obj = webapi#json#decode(res.content) let loc = obj['html_url'] - redraw | echomsg 'Done: '.loc let b:gist = {"id": a:gistid, "filename": filename} setlocal nomodified + redraw | echomsg 'Done: '.loc else let loc = '' echohl ErrorMsg | echomsg 'Post failed: ' . res.message | echohl None @@ -550,10 +550,10 @@ function! s:GistDelete(gistid) abort \ "Content-Type": "application/json", \}, 'DELETE') if res.status =~# '^2' - redraw | echomsg 'Done: ' if exists('b:gist') unlet b:gist endif + redraw | echomsg 'Done: ' else echohl ErrorMsg | echomsg 'Delete failed: ' . res.message | echohl None endif @@ -621,7 +621,6 @@ function! s:GistPost(content, private, desc, anonymous) abort if res.status =~# '^2' let obj = webapi#json#decode(res.content) let loc = obj['html_url'] - redraw | echomsg 'Done: '.loc let b:gist = { \ "filename": filename, \ "id": matchstr(loc, '[^/]\+$'), @@ -631,6 +630,7 @@ function! s:GistPost(content, private, desc, anonymous) abort if s:update_GistID(b:gist['id']) Gist -e endif + redraw | echomsg 'Done: '.loc else let loc = '' echohl ErrorMsg | echomsg 'Post failed: '. res.message | echohl None @@ -677,7 +677,6 @@ function! s:GistPostBuffers(private, desc, anonymous) abort if res.status =~# '^2' let obj = webapi#json#decode(res.content) let loc = obj['html_url'] - redraw | echomsg 'Done: '.loc let b:gist = { \ "filename": filename, \ "id": matchstr(loc, '[^/]\+$'), @@ -687,6 +686,7 @@ function! s:GistPostBuffers(private, desc, anonymous) abort if s:update_GistID(b:gist['id']) Gist -e endif + redraw | echomsg 'Done: '.loc else let loc = '' echohl ErrorMsg | echomsg 'Post failed: ' . res.message | echohl None From 0c21433700348306e898cc241357c871f6b33857 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 8 Jun 2015 00:23:55 -0700 Subject: [PATCH 141/170] Yank the gist url to @+ even if -xterm_clipboard This yanks the URL to the expected register in versions of Vim that have the +clipboard feature but not +xterm_clipboard (such as MacVim). --- autoload/gist.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index dbfad7d..6683cd2 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -891,10 +891,10 @@ function! gist#Gist(count, bang, line1, line2, ...) abort endif if exists('g:gist_clip_command') call system(g:gist_clip_command, url) - elseif has('unix') && !has('xterm_clipboard') - let @" = url - else + elseif has('clipboard') let @+ = url + else + let @" = url endif endif endif From c39e5e317d88da71da338c07af492c7a27efcf0a Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Tue, 9 Jun 2015 18:48:19 +0900 Subject: [PATCH 142/170] fix completion items --- plugin/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/gist.vim b/plugin/gist.vim index ab4f456..4aa674d 100644 --- a/plugin/gist.vim +++ b/plugin/gist.vim @@ -12,10 +12,10 @@ endif let g:loaded_gist_vim = 1 function! s:CompleteArgs(arg_lead,cmdline,cursor_pos) - return ["-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", \ "--listall", "--liststar", "--list", "--multibuffer", "--private", "--public", "--anonymous", "--description", "--clipboard", \ "--rawurl", "--delete", "--edit", "--star", "--unstar", "--fork", "--browser" - \ ] + \ ]), 'stridx(v:val, a:arg_lead)==0') endfunction command! -nargs=? -range=% -bang -complete=customlist,s:CompleteArgs Gist :call gist#Gist(, "", , , ) From 935219dd367bfe22402bf511470ae59505b126e2 Mon Sep 17 00:00:00 2001 From: Dan Church Date: Sun, 21 Jun 2015 12:12:50 -0500 Subject: [PATCH 143/170] Document long options --- doc/gist-vim.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 9839324..c7e48fe 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -27,11 +27,13 @@ USAGE *:Gist* *gist-vim-usage* - Create a private gist. > :Gist -p + :Gist --private < - Create a public gist. (Only relevant if you've set gists to be private by default.) > :Gist -P + :Gist --public < - Post whole text to gist as public. This is only relevant if you've set gists to be private by default. @@ -41,15 +43,18 @@ USAGE *:Gist* *gist-vim-usage* - Create a gist anonymously. > :Gist -a + :Gist --anonymous < - Create a gist with all open buffers. > :Gist -m + :Gist --multibuffer < - Edit the gist (you need to have opened the gist buffer first). You can update the gist with the {:w} command within the gist buffer. > :Gist -e + :Gist --edit < - Edit the gist with name "foo.js" (you need to have opened the gist buffer first). > @@ -60,18 +65,21 @@ USAGE *:Gist* *gist-vim-usage* first). > :Gist -s something + :Gist --description something :Gist -e -s something < - Delete the gist (you need to have opened the gist buffer first). Password authentication is needed. > :Gist -d + :Gist --delete < - Fork the gist (you need to have opened the gist buffer first). Password authentication is needed. > :Gist -f -< + :Gist --fork +< - Star the gist (you need to have opened the gist buffer first). Password authentication is needed. > @@ -93,6 +101,7 @@ USAGE *:Gist* *gist-vim-usage* - List your public gists. > :Gist -l + :Gist --list < - List gists from user "mattn". > @@ -101,14 +110,17 @@ USAGE *:Gist* *gist-vim-usage* - List everyone's gists. > :Gist -la + :Gist --listall < - List gists from your starred gists. > :Gist -ls + :Gist --liststar < - Open the gist on browser after you post or update it. > :Gist -b + :Gist --browser < - Post as new gist after editing on the buffer. > From 75f9d831cee1c489b9ac1987ebb32387cdb56702 Mon Sep 17 00:00:00 2001 From: Matias Date: Tue, 23 Jun 2015 15:17:51 -0300 Subject: [PATCH 144/170] remove duplicated lines gist_edit_with_buffers appears twice on the documentation --- doc/gist-vim.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index c7e48fe..3de7025 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -183,10 +183,6 @@ If you want to open gist with current editing buffers: > let g:gist_edit_with_buffers = 1 -If you want to open gist with current editing buffers: > - - let g:gist_edit_with_buffers = 1 - If you want to open gist list/buffer as vertical split: > let g:gist_list_vsplit = 1 From 52e2d54a038baf548de01c9413a6ebc8860fa111 Mon Sep 17 00:00:00 2001 From: mattn Date: Sat, 4 Jul 2015 20:18:25 +0900 Subject: [PATCH 145/170] fix autocmd to write command. close #193 --- autoload/gist.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 6683cd2..4d2615d 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 03-May-2015. +" Last Change: 04-Jul-2015. " Version: 7.2 " WebPage: http://github.com/mattn/gist-vim " License: BSD @@ -362,6 +362,9 @@ function! s:GistGet(gistid, clipboard) abort echohl ErrorMsg | echomsg 'Gist not found' | echohl None return endif + augroup GistWrite + au! + augroup END for n in range(num_file) try let old_undolevels = &undolevels @@ -450,7 +453,6 @@ function! s:GistGet(gistid, clipboard) abort endif 1 augroup GistWrite - au! au! BufWriteCmd call s:GistWrite(expand("")) augroup END endfor From ea7dc962c5c2ac2a1c4adc94d54cac190d713648 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Thu, 13 Aug 2015 17:36:44 +0900 Subject: [PATCH 146/170] fix #196 --- autoload/gist.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 4d2615d..70d3489 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -98,14 +98,16 @@ function! s:open_browser(url) abort echo a:url return endif + let quote = &shellxquote == '"' ? "'" : '"' if cmd =~# '^!' - let cmd = substitute(cmd, '%URL%', '\=shellescape(a:url)', 'g') + let cmd = substitute(cmd, '%URL%', '\=quote.a:url.quote', 'g') + let g:hoge = cmd silent! exec cmd elseif cmd =~# '^:[A-Z]' let cmd = substitute(cmd, '%URL%', '\=a:url', 'g') exec cmd else - let cmd = substitute(cmd, '%URL%', '\=shellescape(a:url)', 'g') + let cmd = substitute(cmd, '%URL%', '\=quote.a:url.quote', 'g') call system(cmd) endif endfunction From 88c331e2e07765090112a396e5e119b39b5aa754 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Sun, 25 Oct 2015 21:15:52 +0900 Subject: [PATCH 147/170] fix message. close #197 --- autoload/gist.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 70d3489..10ade41 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -716,7 +716,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort 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 - echohl ErrorMsg | echomsg 'You don''t have configured a Github account. Read '':help gist-vim-setup''.' | echohl None + echohl ErrorMsg | echomsg 'You have not configured a Github account. Read '':help gist-vim-setup''.' | echohl None return endif if a:bang == '!' From 3fe6c2d69bece34d59458eef13eb80430f420b5a Mon Sep 17 00:00:00 2001 From: Pablo Cobelli Date: Fri, 30 Sep 2016 20:49:55 -0300 Subject: [PATCH 148/170] First attempt. Added functionalities to GistListing function, see README file for details. Added pasting into current buffer capability. Also enhanced the formatting of the gist listing. Correcting an error in the previous upload. Enhanced visualization of gist listing and added yank and insert capabilities. Updated README to account for changes. Corrected errors on README. Corrected errors on README. Now opening a gist buffer with Enter closes the listing afterwards. Added documentation to doc/gist-vim.txt, code is now clean for a PR. --- README.md | 40 ++++++++++++++++++++++++++++++ autoload/gist.vim | 62 +++++++++++++++++++++++++++++++++++++++++------ doc/gist-vim.txt | 30 +++++++++++++++++++++-- 3 files changed, 122 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5d18bb0..a8c6916 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,43 @@ +### My modifications + +- New mappings on the gist-listing buffer: + - Both `o` or `Enter` open the gist file in a new buffer, and close the + gist-vim listing one. + - `b` opens the gist file in a browser; this is necessary because + `Shift-Enter` (as was originally) only works for GUI vim. + - `y` copies the contents of the selected gist to the clipboard, and + closes the gist-vim buffer. + - `p` pastes the contents of the selected gist to the buffer from where + gist-vim was called, and closes the gist-vim buffer. + - Hitting `Escape` or `Tab` at the gist-vim buffer closes it. +- 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 + description, in that order. Columns are now padded and truncated to offer a + faster browsing, in the following way: + - The gist id string is fixed at 32 characters. + - The length (in characters) of the name of the gist is fixed and + can be set by the user using, for example: + + `let g:gistvim_namelength = 20` + + The default value for `gistvim_namelength` is 30. If the gist (file)name + exceeds that length, it is truncated to the specified length. + - Finally, the gist description is truncated in length to fit the remaining + of the line, avoiding wrapped lines that mess up the table layout. + - Note that the gist listing buffer now does not show the field 'code' + (not sure what that did in the first place). + +- Now the listing is complete (no need to select 'more' to see the following + gists on the list), in this way the user can later perform a search (using vim's `/`, + for instance) for the sought gist by name, description, etc. +- The first line on the gist-listing states the number of gists listed and the + user whose gists are being listed. +- The height of the gist-listing buffer is now determined in the following way. + If the number of gists listed equals or exceeds 10, then the height is fixed at 10. If + it is smaller than 10, then the height is adjusted so that there are no empty + lines displayed on the buffer. Note: right now this value (10) is fixed; I'm + going to change it to a global plugin variable that defaults to 10. + ### Gist.vim This is a vimscript for creating gists (http://gist.github.com). diff --git a/autoload/gist.vim b/autoload/gist.vim index 10ade41..e7f4167 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -132,12 +132,23 @@ function! s:format_gist(gist) abort else let code = '' endif - let desc = type(a:gist.description)==0 || a:gist.description ==# '' ? '' : '('.a:gist.description.')' + let desc = type(a:gist.description)==0 || a:gist.description ==# '' ? '' : a:gist.description let name = substitute(name, '[\r\n\t]', ' ', 'g') let name = substitute(name, ' ', ' ', 'g') let desc = substitute(desc, '[\r\n\t]', ' ', 'g') let desc = substitute(desc, ' ', ' ', 'g') - return printf('gist: %s %s %s%s', a:gist.id, name, desc, code) + " return printf('gist: %-32s %s %s%s', a:gist.id, name, desc, code) + " Display a nice formatted (and truncated if needed) table of gists on screen + " Calculate field lengths for gist-listing formatting on screen + redir =>a |exe "sil sign place buffer=".bufnr('')|redir end + let signlist = split(a, '\n') + let width = winwidth(0) - ((&number||&relativenumber) ? &numberwidth : 0) - &foldcolumn - (len(signlist) > 2 ? 2 : 0) + let s:gistlen = 33 + if !exists("g:gist_namelength") + let g:gist_namelength=30 + endif + let s:desclen = width-(s:gistlen+g:gist_namelength+10) + return printf('gist: %-*s %-*s %-*s', s:gistlen, a:gist.id, g:gist_namelength+1, strpart(name, 0, g:gist_namelength), s:desclen+1, strpart(desc, 0, s:desclen)) endfunction " 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 let lines = map(filter(content, '!empty(v:val.files)'), 's:format_gist(v:val)') call setline(1, split(join(lines, "\n"), "\n")) - $put='more...' + let numlines = line('$') + if numlines > 1 + let plural='s' + else + let plural='' + endif + " $put='more...'.line('$').' gist'.plural.' shown.' + call append(0, ' '.a:gistls.': '.numlines.' gist'.plural) + + if numlines+1 > 11 + let listheight = 11 + else + let listheight = numlines+1 + endif + execute 'resize ' . listheight let b:gistls = a:gistls let b:page = a:page setlocal buftype=nofile bufhidden=hide noswapfile + setlocal cursorline setlocal nomodified setlocal nomodifiable - syntax match SpecialKey /^gist:/he=e-1 + syntax match SpecialKey /^gist:/he=e syntax match Title /^gist: \S\+/hs=s+5 contains=ALL nnoremap :call GistListAction(0) - nnoremap :call GistListAction(1) + nnoremap o :call GistListAction(0) + nnoremap b :call GistListAction(1) + nnoremap y :call GistListAction(2) + nnoremap p :call GistListAction(3) + nnoremap :bw + " Next line (in original code) only works on GUI VIM + nnoremap :call GistListAction(1) cal cursor(1+len(oldlines),1) nohlsearch @@ -401,6 +433,7 @@ function! s:GistGet(gistid, clipboard) abort endif else silent only! + " exec 'silent noautocmd edit' if get(g:, 'gist_list_vsplit', 0) exec 'silent noautocmd rightbelow vnew' else @@ -437,7 +470,8 @@ function! s:GistGet(gistid, clipboard) abort return endtry let &undolevels = old_undolevels - setlocal buftype=acwrite bufhidden=delete noswapfile + " setlocal buftype=acwrite bufhidden=delete noswapfile + setlocal buftype=acwrite bufhidden=hide noswapfile setlocal nomodified doau StdinReadPost,BufRead,BufReadPost let gist_detect_filetype = get(g:, 'gist_detect_filetype', 0) @@ -471,10 +505,22 @@ function! s:GistListAction(shift) abort let mx = '^gist:\s*\zs\(\w\+\)\ze.*' if line =~# mx let gistid = matchstr(line, mx) - if a:shift + if a:shift == 1 call s:open_browser('https://gist.github.com/' . gistid) - else + elseif a:shift == 0 call s:GistGet(gistid, 0) + wincmd w + " bdelete + bw + elseif a:shift == 2 + call s:GistGet(gistid, 1) + bdelete + bdelete + elseif a:shift == 3 + call s:GistGet(gistid, 1) + bdelete + bdelete + normal! "+p endif return endif diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 3de7025..7d19aa6 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -116,7 +116,21 @@ USAGE *:Gist* *gist-vim-usage* > :Gist -ls :Gist --liststar -< + +- While the gist list is visible, the following mappings apply: + + - 'o' or 'Enter' will open the selected gist file in a new buffer + and close the gist-vim listing split. + - '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'. + - 'y' will copy the contents of the selected gist to the clipboard, + and close the gist-vim listing split. + - '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 + listing split. + - 'Esc' will close the gist-vim listing split without performing any + further action. + - Open the gist on browser after you post or update it. > :Gist -b @@ -201,7 +215,19 @@ If you want to update a gist, embed > in your local file, then call > :Gist -> + +The gist-vim listing split lists gists ids, names (filenames) as well as +their description. This is done following a table layout, with fixed space +for each column. For offering quick browsing, gist-vim will truncate all +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 +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: + + let g:gist_namelength = 20 + +Note that the default value for gist_namelength is 30. Again, if the gist +(file)name exceeds the specified number of characters, it will be truncated. If you want to update a gist when only |:w!|: > From 3945a894ba6676679279a2d68d3f50e792b403ad Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 10 Oct 2016 22:15:41 +0900 Subject: [PATCH 149/170] remove trailing spaces --- README.md | 18 +++++++++--------- autoload/gist.vim | 14 +++++++------- doc/gist-vim.txt | 26 +++++++++++++------------- gist.vim.vimup | 4 ++-- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index a8c6916..a3aacf6 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,14 @@ - New mappings on the gist-listing buffer: - Both `o` or `Enter` open the gist file in a new buffer, and close the gist-vim 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. - `y` copies the contents of the selected gist to the clipboard, and closes the gist-vim buffer. - `p` pastes the contents of the selected gist to the buffer from where gist-vim was called, and closes the gist-vim buffer. - Hitting `Escape` or `Tab` at the gist-vim 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 description, in that order. Columns are now padded and truncated to offer a faster browsing, in the following way: @@ -20,23 +20,23 @@ `let g:gistvim_namelength = 20` - The default value for `gistvim_namelength` is 30. If the gist (file)name + The default value for `gistvim_namelength` is 30. If the gist (file)name exceeds that length, it is truncated to the specified length. - - Finally, the gist description is truncated in length to fit the remaining + - Finally, the gist description is truncated in length to fit the remaining of the line, avoiding wrapped lines that mess up the table layout. - - Note that the gist listing buffer now does not show the field 'code' + - Note that the gist listing buffer now does not show the field 'code' (not sure what that did in the first place). - Now the listing is complete (no need to select 'more' to see the following gists on the list), in this way the user can later perform a search (using vim's `/`, - for instance) for the sought gist by name, description, etc. + for instance) for the sought gist by name, description, etc. - The first line on the gist-listing states the number of gists listed and the user whose gists are being listed. - The height of the gist-listing buffer is now determined in the following way. If the number of gists listed equals or exceeds 10, then the height is fixed at 10. If it is smaller than 10, then the height is adjusted so that there are no empty lines displayed on the buffer. Note: right now this value (10) is fixed; I'm - going to change it to a global plugin variable that defaults to 10. + going to change it to a global plugin variable that defaults to 10. ### Gist.vim @@ -241,14 +241,14 @@ You need to install webapi-vim also: If you want to use latest one: https://github.com/mattn/webapi-vim - + ### Install with [Vundle](https://github.com/gmarik/vundle) Add the following lines to your `.vimrc`. Bundle 'mattn/webapi-vim' Bundle 'mattn/gist-vim' - + Now restart Vim and run `:BundleInstall`. ### Install with [NeoBundle](https://github.com/Shougo/neobundle.vim) diff --git a/autoload/gist.vim b/autoload/gist.vim index e7f4167..f045e5e 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -224,14 +224,14 @@ function! s:GistList(gistls, page) abort let plural='' endif " $put='more...'.line('$').' gist'.plural.' shown.' - call append(0, ' '.a:gistls.': '.numlines.' gist'.plural) - + call append(0, ' '.a:gistls.': '.numlines.' gist'.plural) + if numlines+1 > 11 let listheight = 11 else let listheight = numlines+1 endif - execute 'resize ' . listheight + execute 'resize ' . listheight let b:gistls = a:gistls let b:page = a:page @@ -243,12 +243,12 @@ function! s:GistList(gistls, page) abort syntax match Title /^gist: \S\+/hs=s+5 contains=ALL nnoremap :call GistListAction(0) nnoremap o :call GistListAction(0) - nnoremap b :call GistListAction(1) + nnoremap b :call GistListAction(1) nnoremap y :call GistListAction(2) - nnoremap p :call GistListAction(3) + nnoremap p :call GistListAction(3) nnoremap :bw " Next line (in original code) only works on GUI VIM - nnoremap :call GistListAction(1) + nnoremap :call GistListAction(1) cal cursor(1+len(oldlines),1) nohlsearch @@ -512,7 +512,7 @@ function! s:GistListAction(shift) abort wincmd w " bdelete bw - elseif a:shift == 2 + elseif a:shift == 2 call s:GistGet(gistid, 1) bdelete bdelete diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 7d19aa6..c7005a7 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -1,19 +1,19 @@ *Gist.vim* Vimscript for creating gists (http://gist.github.com) -Usage |gist-vim-usage| -Tips |gist-vim-tips| -License |gist-vim-license| -Install |gist-vim-install| -Requirements |gist-vim-requirements| -Setup |gist-vim-setup| -FAQ |gist-vim-faq| +Usage |gist-vim-usage| +Tips |gist-vim-tips| +License |gist-vim-license| +Install |gist-vim-install| +Requirements |gist-vim-requirements| +Setup |gist-vim-setup| +FAQ |gist-vim-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. ============================================================================== -USAGE *:Gist* *gist-vim-usage* +USAGE *:Gist* *gist-vim-usage* - Post current buffer to gist, using default privacy option. > @@ -126,7 +126,7 @@ USAGE *:Gist* *gist-vim-usage* - 'y' will copy the contents of the selected gist to the clipboard, and close the gist-vim listing split. - '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 gist-vim was called, and close the gist-vim listing split. - 'Esc' will close the gist-vim listing split without performing any further action. @@ -246,13 +246,13 @@ LICENSE *gist-vim-license* Copyright 2010 by Yasuhiro Matsumoto modification, are permitted provided that the following conditions are met: - + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -311,7 +311,7 @@ be kept for later use. You can revoke the token at any time from the list of 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 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: > token xxxxx diff --git a/gist.vim.vimup b/gist.vim.vimup index fc7ec74..f6f7ace 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -19,7 +19,7 @@ detailed_description: | :Gist -p post whole text to gist with private. - if you got empty gist list, try :Gist --abandon + if you got empty gist list, try :Gist --abandon :Gist -a post whole text to gist with anonymous. @@ -261,7 +261,7 @@ versions: 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. + 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. From 609097f860d5bfbb2f2760551ea7ae9d110fb375 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 10 Oct 2016 22:16:46 +0900 Subject: [PATCH 150/170] modify README.md --- README.md | 82 +++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index a3aacf6..f67e79e 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,4 @@ -### My modifications - -- New mappings on the gist-listing buffer: - - Both `o` or `Enter` open the gist file in a new buffer, and close the - gist-vim listing one. - - `b` opens the gist file in a browser; this is necessary because - `Shift-Enter` (as was originally) only works for GUI vim. - - `y` copies the contents of the selected gist to the clipboard, and - closes the gist-vim buffer. - - `p` pastes the contents of the selected gist to the buffer from where - gist-vim was called, and closes the gist-vim buffer. - - Hitting `Escape` or `Tab` at the gist-vim buffer closes it. -- 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 - description, in that order. Columns are now padded and truncated to offer a - faster browsing, in the following way: - - The gist id string is fixed at 32 characters. - - The length (in characters) of the name of the gist is fixed and - can be set by the user using, for example: - - `let g:gistvim_namelength = 20` - - The default value for `gistvim_namelength` is 30. If the gist (file)name - exceeds that length, it is truncated to the specified length. - - Finally, the gist description is truncated in length to fit the remaining - of the line, avoiding wrapped lines that mess up the table layout. - - Note that the gist listing buffer now does not show the field 'code' - (not sure what that did in the first place). - -- Now the listing is complete (no need to select 'more' to see the following - gists on the list), in this way the user can later perform a search (using vim's `/`, - for instance) for the sought gist by name, description, etc. -- The first line on the gist-listing states the number of gists listed and the - user whose gists are being listed. -- The height of the gist-listing buffer is now determined in the following way. - If the number of gists listed equals or exceeds 10, then the height is fixed at 10. If - it is smaller than 10, then the height is adjusted so that there are no empty - lines displayed on the buffer. Note: right now this value (10) is fixed; I'm - going to change it to a global plugin variable that defaults to 10. - -### Gist.vim +# Gist.vim This is a vimscript for creating gists (http://gist.github.com). @@ -139,6 +99,46 @@ For the latest version please see https://github.com/mattn/gist-vim. :Gist -b +## List Action + +- New mappings on the gist-listing buffer: + - Both `o` or `Enter` open the gist file in a new buffer, and close the + gist-vim listing one. + - `b` opens the gist file in a browser; this is necessary because + `Shift-Enter` (as was originally) only works for GUI vim. + - `y` copies the contents of the selected gist to the clipboard, and + closes the gist-vim buffer. + - `p` pastes the contents of the selected gist to the buffer from where + gist-vim was called, and closes the gist-vim buffer. + - Hitting `Escape` or `Tab` at the gist-vim buffer closes it. +- 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 + description, in that order. Columns are now padded and truncated to offer a + faster browsing, in the following way: + - The gist id string is fixed at 32 characters. + - The length (in characters) of the name of the gist is fixed and + can be set by the user using, for example: + + `let g:gistvim_namelength = 20` + + The default value for `gistvim_namelength` is 30. If the gist (file)name + exceeds that length, it is truncated to the specified length. + - Finally, the gist description is truncated in length to fit the remaining + of the line, avoiding wrapped lines that mess up the table layout. + - Note that the gist listing buffer now does not show the field 'code' + (not sure what that did in the first place). + +- Now the listing is complete (no need to select 'more' to see the following + gists on the list), in this way the user can later perform a search (using vim's `/`, + for instance) for the sought gist by name, description, etc. +- The first line on the gist-listing states the number of gists listed and the + user whose gists are being listed. +- The height of the gist-listing buffer is now determined in the following way. + If the number of gists listed equals or exceeds 10, then the height is fixed at 10. If + it is smaller than 10, then the height is adjusted so that there are no empty + lines displayed on the buffer. Note: right now this value (10) is fixed; I'm + going to change it to a global plugin variable that defaults to 10. + ## Tips: If you set g:gist_clip_command, gist.vim will copy the gist code with option From 6c06e4a050e8e69fd41072666d1227d694073b0b Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 10 Oct 2016 22:38:35 +0900 Subject: [PATCH 151/170] remove needless comment --- autoload/gist.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index f045e5e..48181f6 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -137,7 +137,6 @@ function! s:format_gist(gist) abort let name = substitute(name, ' ', ' ', 'g') let desc = substitute(desc, '[\r\n\t]', ' ', 'g') let desc = substitute(desc, ' ', ' ', 'g') - " return printf('gist: %-32s %s %s%s', a:gist.id, name, desc, code) " Display a nice formatted (and truncated if needed) table of gists on screen " Calculate field lengths for gist-listing formatting on screen redir =>a |exe "sil sign place buffer=".bufnr('')|redir end From 79333899364f925fa9d5488f1ecc4e371fbc9c5c Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 10 Oct 2016 22:40:45 +0900 Subject: [PATCH 152/170] strpart breaks multi-byte strings --- autoload/gist.vim | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 48181f6..0e30666 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -119,6 +119,28 @@ function! s:shellwords(str) abort return words endfunction +function! s:truncate(str, num) + let mx_first = '^\(.\)\(.*\)$' + let str = a:str + let ret = '' + let width = 0 + while 1 + let char = substitute(str, mx_first, '\1', '') + let cells = strdisplaywidth(char) + if cells == 0 || width + cells > a:num + break + endif + let width = width + cells + let ret .= char + let str = substitute(str, mx_first, '\2', '') + endwhile + while width + 1 <= a:num + let ret .= " " + let width = width + 1 + endwhile + return ret +endfunction + function! s:format_gist(gist) abort let files = sort(keys(a:gist.files)) if empty(files) @@ -142,12 +164,10 @@ function! s:format_gist(gist) abort redir =>a |exe "sil sign place buffer=".bufnr('')|redir end let signlist = split(a, '\n') let width = winwidth(0) - ((&number||&relativenumber) ? &numberwidth : 0) - &foldcolumn - (len(signlist) > 2 ? 2 : 0) - let s:gistlen = 33 - if !exists("g:gist_namelength") - let g:gist_namelength=30 - endif - let s:desclen = width-(s:gistlen+g:gist_namelength+10) - return printf('gist: %-*s %-*s %-*s', s:gistlen, a:gist.id, g:gist_namelength+1, strpart(name, 0, g:gist_namelength), s:desclen+1, strpart(desc, 0, s:desclen)) + let idlen = 33 + let namelen = get(g:, 'gist_namelength', 30) + let desclen = width - (idlen + namelen + 10) + return printf('gist: %s %s %s', s:truncate(a:gist.id, idlen), s:truncate(name, namelen), s:truncate(desc, desclen)) endfunction " Note: A colon in the file name has side effects on Windows due to NTFS Alternate Data Streams; avoid it. From a661e7140d335fb2634c09586b6dcab35c35695e Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 10 Oct 2016 22:44:14 +0900 Subject: [PATCH 153/170] not useful to display count of gists because it have more gists --- autoload/gist.vim | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 0e30666..9cb5fce 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -236,21 +236,7 @@ function! s:GistList(gistls, page) abort let lines = map(filter(content, '!empty(v:val.files)'), 's:format_gist(v:val)') call setline(1, split(join(lines, "\n"), "\n")) - let numlines = line('$') - if numlines > 1 - let plural='s' - else - let plural='' - endif - " $put='more...'.line('$').' gist'.plural.' shown.' - call append(0, ' '.a:gistls.': '.numlines.' gist'.plural) - - if numlines+1 > 11 - let listheight = 11 - else - let listheight = numlines+1 - endif - execute 'resize ' . listheight + $put='more...' let b:gistls = a:gistls let b:page = a:page From b9baa3c497e287516c5cb1d231ae50cfc45745cc Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 10 Oct 2016 22:45:37 +0900 Subject: [PATCH 154/170] prefer highlight before : --- autoload/gist.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 9cb5fce..56ebd29 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -244,7 +244,7 @@ function! s:GistList(gistls, page) abort setlocal cursorline setlocal nomodified setlocal nomodifiable - syntax match SpecialKey /^gist:/he=e + syntax match SpecialKey /^gist:/he=e-1 syntax match Title /^gist: \S\+/hs=s+5 contains=ALL nnoremap :call GistListAction(0) nnoremap o :call GistListAction(0) From 123be362be3ceaf470c2e9df1b253f33ed17cead Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 10 Oct 2016 22:46:30 +0900 Subject: [PATCH 155/170] remove needless comment --- autoload/gist.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 56ebd29..edc48fa 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -475,7 +475,6 @@ function! s:GistGet(gistid, clipboard) abort return endtry let &undolevels = old_undolevels - " setlocal buftype=acwrite bufhidden=delete noswapfile setlocal buftype=acwrite bufhidden=hide noswapfile setlocal nomodified doau StdinReadPost,BufRead,BufReadPost From df12783ad4b99a2083e6de53eaee0960c25c0802 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 10 Oct 2016 22:47:41 +0900 Subject: [PATCH 156/170] remove needless comment --- autoload/gist.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index edc48fa..db9ce7d 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -438,7 +438,6 @@ function! s:GistGet(gistid, clipboard) abort endif else silent only! - " exec 'silent noautocmd edit' if get(g:, 'gist_list_vsplit', 0) exec 'silent noautocmd rightbelow vnew' else From fedb75239a3d7031ea5c4e7421cdfeb0a10891f0 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 10 Oct 2016 22:48:56 +0900 Subject: [PATCH 157/170] s/shift/mode/ --- autoload/gist.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index db9ce7d..0c6a1b5 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -503,23 +503,23 @@ function! s:GistGet(gistid, clipboard) abort endif endfunction -function! s:GistListAction(shift) abort +function! s:GistListAction(mode) abort let line = getline('.') let mx = '^gist:\s*\zs\(\w\+\)\ze.*' if line =~# mx let gistid = matchstr(line, mx) - if a:shift == 1 + if a:mode == 1 call s:open_browser('https://gist.github.com/' . gistid) - elseif a:shift == 0 + elseif a:mode == 0 call s:GistGet(gistid, 0) wincmd w " bdelete bw - elseif a:shift == 2 + elseif a:mode == 2 call s:GistGet(gistid, 1) bdelete bdelete - elseif a:shift == 3 + elseif a:mode == 3 call s:GistGet(gistid, 1) bdelete bdelete From 73abc1e668380d0012e2938a5f3afef541bdf438 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 10 Oct 2016 22:51:30 +0900 Subject: [PATCH 158/170] remove needless comment, put TODO(s) --- autoload/gist.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 0c6a1b5..094111a 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -513,14 +513,15 @@ function! s:GistListAction(mode) abort elseif a:mode == 0 call s:GistGet(gistid, 0) wincmd w - " bdelete bw elseif a:mode == 2 call s:GistGet(gistid, 1) + " TODO close with buffe rname bdelete bdelete elseif a:mode == 3 call s:GistGet(gistid, 1) + " TODO close with buffe rname bdelete bdelete normal! "+p From 1f3bb970b35e1fcc286364a3a5ef75e539e81e60 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 10 Oct 2016 22:54:12 +0900 Subject: [PATCH 159/170] update README.md --- README.md | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index f67e79e..95e3e23 100644 --- a/README.md +++ b/README.md @@ -99,9 +99,9 @@ For the latest version please see https://github.com/mattn/gist-vim. :Gist -b -## List Action +## List Feature -- New 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 gist-vim listing one. - `b` opens the gist file in a browser; this is necessary because @@ -111,6 +111,7 @@ For the latest version please see https://github.com/mattn/gist-vim. - `p` pastes the contents of the selected gist to the buffer from where gist-vim was called, and closes the gist-vim buffer. - Hitting `Escape` or `Tab` at the gist-vim buffer closes it. + - 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 description, in that order. Columns are now padded and truncated to offer a @@ -128,17 +129,6 @@ For the latest version please see https://github.com/mattn/gist-vim. - Note that the gist listing buffer now does not show the field 'code' (not sure what that did in the first place). -- Now the listing is complete (no need to select 'more' to see the following - gists on the list), in this way the user can later perform a search (using vim's `/`, - for instance) for the sought gist by name, description, etc. -- The first line on the gist-listing states the number of gists listed and the - user whose gists are being listed. -- The height of the gist-listing buffer is now determined in the following way. - If the number of gists listed equals or exceeds 10, then the height is fixed at 10. If - it is smaller than 10, then the height is adjusted so that there are no empty - lines displayed on the buffer. Note: right now this value (10) is fixed; I'm - going to change it to a global plugin variable that defaults to 10. - ## Tips: If you set g:gist_clip_command, gist.vim will copy the gist code with option From 5f0fd287d427061a93ca3a3adf59dd08a9871664 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 10 Oct 2016 22:56:41 +0900 Subject: [PATCH 160/170] remove needless comment --- autoload/gist.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 094111a..6fbfc85 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -252,7 +252,6 @@ function! s:GistList(gistls, page) abort nnoremap y :call GistListAction(2) nnoremap p :call GistListAction(3) nnoremap :bw - " Next line (in original code) only works on GUI VIM nnoremap :call GistListAction(1) cal cursor(1+len(oldlines),1) From dd345b0a6ef91969fd3800ec99c4caec19bf7791 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 10 Oct 2016 22:57:50 +0900 Subject: [PATCH 161/170] bump version --- autoload/gist.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 6fbfc85..6727bc0 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -1,8 +1,8 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" Last Change: 04-Jul-2015. -" Version: 7.2 +" Last Change: 10-Oct-2016. +" Version: 7.3 " WebPage: http://github.com/mattn/gist-vim " License: BSD From f0d63579eab7548cf12f979dc52ef5a370ecbe63 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 10 Oct 2016 22:59:08 +0900 Subject: [PATCH 162/170] update vimup --- gist.vim.vimup | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gist.vim.vimup b/gist.vim.vimup index f6f7ace..fa85320 100644 --- a/gist.vim.vimup +++ b/gist.vim.vimup @@ -2,7 +2,7 @@ script_name: Gist.vim script_id: '2423' script_type: utility script_package: gist-vim.zip -script_version: '7.2' +script_version: '7.3' required_vim_version: '7.0' summary: vimscript for gist @@ -101,6 +101,9 @@ install_details: | 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. From 3abf2444bb6a7744a64b4a2c2b02d6761a7de072 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Fri, 9 Nov 2018 18:36:53 +0900 Subject: [PATCH 163/170] remove debug code --- autoload/gist.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 6727bc0..50d8842 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -101,7 +101,6 @@ function! s:open_browser(url) abort let quote = &shellxquote == '"' ? "'" : '"' if cmd =~# '^!' let cmd = substitute(cmd, '%URL%', '\=quote.a:url.quote', 'g') - let g:hoge = cmd silent! exec cmd elseif cmd =~# '^:[A-Z]' let cmd = substitute(cmd, '%URL%', '\=a:url', 'g') From e485c6c24a62b378a2a4c8687e36e7f54ceca18c Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 8 Jul 2019 14:44:33 +0900 Subject: [PATCH 164/170] Create FUNDING.yml --- .github/FUNDING.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..351ae11 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: mattn # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] From c1e6b342b06e86ec9c0eba1b23807b8712df5fb6 Mon Sep 17 00:00:00 2001 From: Tsuyoshi CHO Date: Sat, 30 Nov 2019 08:56:26 +0900 Subject: [PATCH 165/170] gist_token support for direct token set --- autoload/gist.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 50d8842..afe797e 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -961,7 +961,9 @@ function! s:GistGetAuthHeader() abort return printf('basic %s', webapi#base64#b64encode(g:github_user.':'.password)) endif let auth = '' - if filereadable(s:gist_token_file) + if !empty(get(g:, 'gist_token', $GITHUB_TOKEN)) + let auth = 'token ' . get(g:, 'gist_token', $GITHUB_TOKEN) + elseif filereadable(s:gist_token_file) let str = join(readfile(s:gist_token_file), '') if type(str) == 1 let auth = str From eee7d14517d061589014522355fe06cc033142aa Mon Sep 17 00:00:00 2001 From: Tsuyoshi CHO Date: Sat, 30 Nov 2019 09:26:31 +0900 Subject: [PATCH 166/170] README update : direct setting --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 95e3e23..e91463f 100644 --- a/README.md +++ b/README.md @@ -266,6 +266,9 @@ Then gist-vim will ask for your password in order to create an access token. If you have two-factor authentication enabled, gist-vim will also prompt you to enter the two-factor key you receive. +NOTE: +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 stored, only a OAuth access token produced specifically for gist-vim. The token is stored in `~/.gist-vim`. If you stop using the plugin, you can From 2158eceb210b0a354bc17aa4144554e5d8bb6c79 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Wed, 29 Jan 2020 13:09:59 +0900 Subject: [PATCH 167/170] Rename --- Makefile | 11 -- README.md | 20 +-- autoload/gist.vim | 4 +- doc/gist-vim.txt | 56 ++++----- gist.vim.vimup | 303 ---------------------------------------------- plugin/gist.vim | 2 +- 6 files changed, 41 insertions(+), 355 deletions(-) delete mode 100644 Makefile delete mode 100644 gist.vim.vimup diff --git a/Makefile b/Makefile deleted file mode 100644 index 81370a8..0000000 --- a/Makefile +++ /dev/null @@ -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 diff --git a/README.md b/README.md index e91463f..f2df1bb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ 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: @@ -103,14 +103,14 @@ For the latest version please see https://github.com/mattn/gist-vim. - Useful mappings on the gist-listing buffer: - 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 `Shift-Enter` (as was originally) only works for GUI vim. - `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 - gist-vim was called, and closes the gist-vim buffer. - - Hitting `Escape` or `Tab` at the gist-vim buffer closes it. + vim-gist was called, and closes the vim-gist buffer. + - Hitting `Escape` or `Tab` at the vim-gist buffer closes it. - 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 @@ -237,7 +237,7 @@ If you want to use latest one: Add the following lines to your `.vimrc`. Bundle 'mattn/webapi-vim' - Bundle 'mattn/gist-vim' + Bundle 'mattn/vim-gist' Now restart Vim and run `:BundleInstall`. @@ -245,7 +245,7 @@ Now restart Vim and run `:BundleInstall`. Add the following line to your `.vimrc`. - NeoBundle 'mattn/gist-vim', {'depends': 'mattn/webapi-vim'} + NeoBundle 'mattn/vim-gist', {'depends': 'mattn/webapi-vim'} ## Requirements: @@ -262,15 +262,15 @@ First, you need to set your GitHub username in git's global configuration: $ git config --global github.user -Then gist-vim will ask for your password in order to create an access -token. If you have two-factor authentication enabled, gist-vim will also +Then vim-gist will ask for your password in order to create an access +token. If you have two-factor authentication enabled, vim-gist will also prompt you to enter the two-factor key you receive. NOTE: 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 -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 easily remove this file. To revoke the associated GitHub token, go to the list of ["Authorized applications" on GitHub's "Account Settings" diff --git a/autoload/gist.vim b/autoload/gist.vim index afe797e..7f803c6 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -3,7 +3,7 @@ " Author: Yasuhiro Matsumoto " Last Change: 10-Oct-2016. " Version: 7.3 -" WebPage: http://github.com/mattn/gist-vim +" WebPage: http://github.com/mattn/vim-gist " License: BSD let s:save_cpo = &cpoptions @@ -764,7 +764,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort 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 - 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 endif if a:bang == '!' diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index c7005a7..88c46d1 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -1,19 +1,19 @@ *Gist.vim* Vimscript for creating gists (http://gist.github.com) -Usage |gist-vim-usage| -Tips |gist-vim-tips| -License |gist-vim-license| -Install |gist-vim-install| -Requirements |gist-vim-requirements| -Setup |gist-vim-setup| -FAQ |gist-vim-faq| +Usage |vim-gist-usage| +Tips |vim-gist-tips| +License |vim-gist-license| +Install |vim-gist-install| +Requirements |vim-gist-requirements| +Setup |vim-gist-setup| +FAQ |vim-gist-faq| 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. > @@ -120,15 +120,15 @@ USAGE *:Gist* *gist-vim-usage* - While the gist list is visible, the following mappings apply: - '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 GUI vim you can also achieve this by pressing 'Shift-Enter'. - '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 - 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. - - 'Esc' will close the gist-vim listing split without performing any + - 'Esc' will close the vim-gist listing split without performing any further action. - Open the gist on browser after you post or update it. @@ -141,7 +141,7 @@ USAGE *:Gist* *gist-vim-usage* :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 "-c". @@ -216,13 +216,13 @@ in your local file, then call > :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 -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 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 -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 @@ -241,7 +241,7 @@ All other values are treated as 1. This variable's value is 1 by default. ============================================================================== -LICENSE *gist-vim-license* +LICENSE *vim-gist-license* Copyright 2010 by Yasuhiro Matsumoto @@ -267,7 +267,7 @@ LICENSE *gist-vim-license* OF THE POSSIBILITY OF SUCH DAMAGE. ============================================================================== -INSTALL *gist-vim-install* +INSTALL *vim-gist-install* Copy following files into your plugin directory. @@ -275,7 +275,7 @@ rtp: - autoload/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: @@ -286,17 +286,17 @@ If you want to use latest one: https://github.com/mattn/webapi-vim ============================================================================== -REQUIREMENTS *gist-vim-requirements* +REQUIREMENTS *vim-gist-requirements* - curl command (http://curl.haxx.se/) - webapi-vim (https://github.com/mattn/webapi-vim) - 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`. -gist-vim provides two ways to authenticate against the GitHub APIs. +This plugin uses GitHub API v3. The authentication value is stored in `~/.vim-gist`. +vim-gist provides two ways to authenticate against the GitHub APIs. First, you need to set your GitHub username in global git config: > @@ -312,7 +312,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 create a "Personal Access Token" on GitHub's "Account Settings" page (https://github.com/settings/applications) and place it in a file -named ~/.gist-vim like this: +named ~/.vim-gist like this: > token xxxxx < @@ -331,13 +331,13 @@ This is not secure at all, so strongly discouraged. 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 -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 Bruno Bigras diff --git a/gist.vim.vimup b/gist.vim.vimup deleted file mode 100644 index fa85320..0000000 --- a/gist.vim.vimup +++ /dev/null @@ -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 diff --git a/plugin/gist.vim b/plugin/gist.vim index 4aa674d..4d4efe6 100644 --- a/plugin/gist.vim +++ b/plugin/gist.vim @@ -1,7 +1,7 @@ "============================================================================= " File: gist.vim " Author: Yasuhiro Matsumoto -" WebPage: http://github.com/mattn/gist-vim +" WebPage: http://github.com/mattn/vim-gist " License: BSD " GetLatestVimScripts: 2423 1 :AutoInstall: gist.vim " script type: plugin From 4a210316550577c1b6a5cb13b09ce79fba602b9c Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Sun, 4 Oct 2020 22:01:57 +0900 Subject: [PATCH 168/170] Fixes with vint report --- autoload/gist.vim | 360 +++++++++++++++++++++++----------------------- 1 file changed, 180 insertions(+), 180 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 7f803c6..bfe84a0 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -134,7 +134,7 @@ function! s:truncate(str, num) let str = substitute(str, mx_first, '\2', '') endwhile while width + 1 <= a:num - let ret .= " " + let ret .= ' ' let width = width + 1 endwhile return ret @@ -160,7 +160,7 @@ function! s:format_gist(gist) abort let desc = substitute(desc, ' ', ' ', 'g') " Display a nice formatted (and truncated if needed) table of gists 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 width = winwidth(0) - ((&number||&relativenumber) ? &numberwidth : 0) - &foldcolumn - (len(signlist) > 2 ? 2 : 0) let idlen = 33 @@ -214,7 +214,7 @@ function! s:GistList(gistls, page) abort echohl ErrorMsg | echomsg v:errmsg | echohl None return endif - let res = webapi#http#get(url, '', { "Authorization": auth }) + let res = webapi#http#get(url, '', { 'Authorization': auth }) if v:shell_error != 0 bw! redraw @@ -330,7 +330,7 @@ function! gist#list(user, ...) abort if len(auth) == 0 return [] endif - let res = webapi#http#get(url, '', { "Authorization": auth }) + let res = webapi#http#get(url, '', { 'Authorization': auth }) return webapi#json#decode(res.content) endfunction @@ -339,7 +339,7 @@ function! s:GistGetFileName(gistid) abort if len(auth) == 0 return '' 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) if has_key(gist, 'files') return sort(keys(gist.files))[0] @@ -352,7 +352,7 @@ function! s:GistDetectFiletype(gistid) abort if len(auth) == 0 return '' 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 filename = sort(keys(gist.files))[0] let ext = fnamemodify(filename, ':e') @@ -380,7 +380,7 @@ endfunction function! s:GistGet(gistid, clipboard) abort 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' try let gist = webapi#json#decode(res.content) @@ -459,10 +459,10 @@ function! s:GistGet(gistid, clipboard) abort let content = gist.files[filename].content call setline(1, split(content, "\n")) let b:gist = { - \ "filename": filename, - \ "id": gist.id, - \ "description": gist.description, - \ "private": gist.public =~ 'true', + \ 'filename': filename, + \ 'id': gist.id, + \ 'description': gist.description, + \ 'private': gist.public =~# 'true', \} catch let &undolevels = old_undolevels @@ -533,10 +533,10 @@ function! s:GistListAction(mode) abort endfunction 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 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 endif if has_key(b:gist, 'private') && b:gist.private | let gist['public'] = function('webapi#json#false') | endif @@ -560,25 +560,25 @@ function! s:GistUpdate(content, gistid, gistnm, desc) abort if a:desc !=# ' ' let gist['description'] = a:desc 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' let old_gist = webapi#json#decode(res.content) let gist['description'] = old_gist.description endif endif - let gist.files[filename] = { "content": a:content, "filename": filename } + let gist.files[filename] = { 'content': a:content, 'filename': filename } redraw | echon 'Updating gist... ' let res = webapi#http#post(g:gist_api_url.'gists/' . a:gistid, \ webapi#json#encode(gist), { - \ "Authorization": auth, - \ "Content-Type": "application/json", + \ 'Authorization': auth, + \ 'Content-Type': 'application/json', \}) if res.status =~# '^2' let obj = webapi#json#decode(res.content) let loc = obj['html_url'] - let b:gist = {"id": a:gistid, "filename": filename} + let b:gist = {'id': a:gistid, 'filename': filename} setlocal nomodified redraw | echomsg 'Done: '.loc else @@ -598,8 +598,8 @@ function! s:GistDelete(gistid) abort redraw | echon 'Deleting gist... ' let res = webapi#http#post(g:gist_api_url.'gists/'.a:gistid, '', { - \ "Authorization": auth, - \ "Content-Type": "application/json", + \ 'Authorization': auth, + \ 'Content-Type': 'application/json', \}, 'DELETE') if res.status =~# '^2' if exists('b:gist') @@ -651,13 +651,13 @@ endfunction " GistID: 123123 " 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:private | let gist['public'] = function('webapi#json#false') | endif 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 let auth = s:GistGetAuthHeader() if len(auth) == 0 @@ -674,10 +674,10 @@ function! s:GistPost(content, private, desc, anonymous) abort let obj = webapi#json#decode(res.content) let loc = obj['html_url'] let b:gist = { - \ "filename": filename, - \ "id": matchstr(loc, '[^/]\+$'), - \ "description": gist['description'], - \ "private": a:private, + \ 'filename': filename, + \ 'id': matchstr(loc, '[^/]\+$'), + \ 'description': gist['description'], + \ 'private': a:private, \} if s:update_GistID(b:gist['id']) Gist -e @@ -695,7 +695,7 @@ function! s:GistPostBuffers(private, desc, anonymous) abort let bn = bufnr('%') 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:private | let gist['public'] = function('webapi#json#false') | endif @@ -708,12 +708,12 @@ function! s:GistPostBuffers(private, desc, anonymous) abort silent! exec 'buffer!' bufnr let content = join(getline(1, line('$')), "\n") 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 endfor silent! exec 'buffer!' bn - let header = {"Content-Type": "application/json"} + let header = {'Content-Type': 'application/json'} if !a:anonymous let auth = s:GistGetAuthHeader() if len(auth) == 0 @@ -730,10 +730,10 @@ function! s:GistPostBuffers(private, desc, anonymous) abort let obj = webapi#json#decode(res.content) let loc = obj['html_url'] let b:gist = { - \ "filename": filename, - \ "id": matchstr(loc, '[^/]\+$'), - \ "description": gist['description'], - \ "private": a:private, + \ 'filename': filename, + \ 'id': matchstr(loc, '[^/]\+$'), + \ 'description': gist['description'], + \ 'private': a:private, \} if s:update_GistID(b:gist['id']) Gist -e @@ -828,7 +828,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort echohl ErrorMsg | echomsg v:errmsg | echohl None else 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' echomsg 'Starred' gistid else @@ -842,7 +842,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort echohl ErrorMsg | echomsg v:errmsg | echohl None else 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' echomsg 'Unstarred' gistid else @@ -857,7 +857,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort return else 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' let obj = webapi#json#decode(res.content) let gistid = obj['id'] @@ -986,12 +986,12 @@ function! s:GistGetAuthHeader() abort 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 res = webapi#http#post(g:gist_api_url.'authorizations', webapi#json#encode({ - \ "scopes" : ["gist"], - \ "note" : note, - \ "note_url" : note_url, + \ 'scopes' : ['gist'], + \ 'note' : note, + \ 'note_url' : note_url, \}), { - \ "Content-Type" : "application/json", - \ "Authorization" : insecureSecret, + \ 'Content-Type' : 'application/json', + \ 'Authorization' : insecureSecret, \}) let h = filter(res.header, 'stridx(v:val, "X-GitHub-OTP:") == 0') if len(h) @@ -1001,13 +1001,13 @@ function! s:GistGetAuthHeader() abort return '' endif let res = webapi#http#post(g:gist_api_url.'authorizations', webapi#json#encode({ - \ "scopes" : ["gist"], - \ "note" : note, - \ "note_url" : note_url, + \ 'scopes' : ['gist'], + \ 'note' : note, + \ 'note_url' : note_url, \}), { - \ "Content-Type" : "application/json", - \ "Authorization" : insecureSecret, - \ "X-GitHub-OTP" : otp, + \ 'Content-Type' : 'application/json', + \ 'Authorization' : insecureSecret, + \ 'X-GitHub-OTP' : otp, \}) endif let authorization = webapi#json#decode(res.content) @@ -1025,138 +1025,138 @@ function! s:GistGetAuthHeader() abort endfunction let s:extmap = extend({ -\".adb": "ada", -\".ahk": "ahk", -\".arc": "arc", -\".as": "actionscript", -\".asm": "asm", -\".asp": "asp", -\".aw": "php", -\".b": "b", -\".bat": "bat", -\".befunge": "befunge", -\".bmx": "bmx", -\".boo": "boo", -\".c-objdump": "c-objdump", -\".c": "c", -\".cfg": "cfg", -\".cfm": "cfm", -\".ck": "ck", -\".cl": "cl", -\".clj": "clj", -\".cmake": "cmake", -\".coffee": "coffee", -\".cpp": "cpp", -\".cppobjdump": "cppobjdump", -\".cs": "csharp", -\".css": "css", -\".cw": "cw", -\".d-objdump": "d-objdump", -\".d": "d", -\".darcspatch": "darcspatch", -\".diff": "diff", -\".duby": "duby", -\".dylan": "dylan", -\".e": "e", -\".ebuild": "ebuild", -\".eclass": "eclass", -\".el": "lisp", -\".erb": "erb", -\".erl": "erlang", -\".f90": "f90", -\".factor": "factor", -\".feature": "feature", -\".fs": "fs", -\".fy": "fy", -\".go": "go", -\".groovy": "groovy", -\".gs": "gs", -\".gsp": "gsp", -\".haml": "haml", -\".hs": "haskell", -\".html": "html", -\".hx": "hx", -\".ik": "ik", -\".ino": "ino", -\".io": "io", -\".j": "j", -\".java": "java", -\".js": "javascript", -\".json": "json", -\".jsp": "jsp", -\".kid": "kid", -\".lhs": "lhs", -\".lisp": "lisp", -\".ll": "ll", -\".lua": "lua", -\".ly": "ly", -\".m": "objc", -\".mak": "mak", -\".man": "man", -\".mao": "mao", -\".matlab": "matlab", -\".md": "markdown", -\".minid": "minid", -\".ml": "ml", -\".moo": "moo", -\".mu": "mu", -\".mustache": "mustache", -\".mxt": "mxt", -\".myt": "myt", -\".n": "n", -\".nim": "nim", -\".nu": "nu", -\".numpy": "numpy", -\".objdump": "objdump", -\".ooc": "ooc", -\".parrot": "parrot", -\".pas": "pas", -\".pasm": "pasm", -\".pd": "pd", -\".phtml": "phtml", -\".pir": "pir", -\".pl": "perl", -\".po": "po", -\".py": "python", -\".pytb": "pytb", -\".pyx": "pyx", -\".r": "r", -\".raw": "raw", -\".rb": "ruby", -\".rhtml": "rhtml", -\".rkt": "rkt", -\".rs": "rs", -\".rst": "rst", -\".s": "s", -\".sass": "sass", -\".sc": "sc", -\".scala": "scala", -\".scm": "scheme", -\".scpt": "scpt", -\".scss": "scss", -\".self": "self", -\".sh": "sh", -\".sml": "sml", -\".sql": "sql", -\".st": "smalltalk", -\".swift": "swift", -\".tcl": "tcl", -\".tcsh": "tcsh", -\".tex": "tex", -\".textile": "textile", -\".tpl": "smarty", -\".twig": "twig", -\".txt" : "text", -\".v": "verilog", -\".vala": "vala", -\".vb": "vbnet", -\".vhd": "vhdl", -\".vim": "vim", -\".weechatlog": "weechatlog", -\".xml": "xml", -\".xq": "xquery", -\".xs": "xs", -\".yml": "yaml", +\'.adb': 'ada', +\'.ahk': 'ahk', +\'.arc': 'arc', +\'.as': 'actionscript', +\'.asm': 'asm', +\'.asp': 'asp', +\'.aw': 'php', +\'.b': 'b', +\'.bat': 'bat', +\'.befunge': 'befunge', +\'.bmx': 'bmx', +\'.boo': 'boo', +\'.c-objdump': 'c-objdump', +\'.c': 'c', +\'.cfg': 'cfg', +\'.cfm': 'cfm', +\'.ck': 'ck', +\'.cl': 'cl', +\'.clj': 'clj', +\'.cmake': 'cmake', +\'.coffee': 'coffee', +\'.cpp': 'cpp', +\'.cppobjdump': 'cppobjdump', +\'.cs': 'csharp', +\'.css': 'css', +\'.cw': 'cw', +\'.d-objdump': 'd-objdump', +\'.d': 'd', +\'.darcspatch': 'darcspatch', +\'.diff': 'diff', +\'.duby': 'duby', +\'.dylan': 'dylan', +\'.e': 'e', +\'.ebuild': 'ebuild', +\'.eclass': 'eclass', +\'.el': 'lisp', +\'.erb': 'erb', +\'.erl': 'erlang', +\'.f90': 'f90', +\'.factor': 'factor', +\'.feature': 'feature', +\'.fs': 'fs', +\'.fy': 'fy', +\'.go': 'go', +\'.groovy': 'groovy', +\'.gs': 'gs', +\'.gsp': 'gsp', +\'.haml': 'haml', +\'.hs': 'haskell', +\'.html': 'html', +\'.hx': 'hx', +\'.ik': 'ik', +\'.ino': 'ino', +\'.io': 'io', +\'.j': 'j', +\'.java': 'java', +\'.js': 'javascript', +\'.json': 'json', +\'.jsp': 'jsp', +\'.kid': 'kid', +\'.lhs': 'lhs', +\'.lisp': 'lisp', +\'.ll': 'll', +\'.lua': 'lua', +\'.ly': 'ly', +\'.m': 'objc', +\'.mak': 'mak', +\'.man': 'man', +\'.mao': 'mao', +\'.matlab': 'matlab', +\'.md': 'markdown', +\'.minid': 'minid', +\'.ml': 'ml', +\'.moo': 'moo', +\'.mu': 'mu', +\'.mustache': 'mustache', +\'.mxt': 'mxt', +\'.myt': 'myt', +\'.n': 'n', +\'.nim': 'nim', +\'.nu': 'nu', +\'.numpy': 'numpy', +\'.objdump': 'objdump', +\'.ooc': 'ooc', +\'.parrot': 'parrot', +\'.pas': 'pas', +\'.pasm': 'pasm', +\'.pd': 'pd', +\'.phtml': 'phtml', +\'.pir': 'pir', +\'.pl': 'perl', +\'.po': 'po', +\'.py': 'python', +\'.pytb': 'pytb', +\'.pyx': 'pyx', +\'.r': 'r', +\'.raw': 'raw', +\'.rb': 'ruby', +\'.rhtml': 'rhtml', +\'.rkt': 'rkt', +\'.rs': 'rs', +\'.rst': 'rst', +\'.s': 's', +\'.sass': 'sass', +\'.sc': 'sc', +\'.scala': 'scala', +\'.scm': 'scheme', +\'.scpt': 'scpt', +\'.scss': 'scss', +\'.self': 'self', +\'.sh': 'sh', +\'.sml': 'sml', +\'.sql': 'sql', +\'.st': 'smalltalk', +\'.swift': 'swift', +\'.tcl': 'tcl', +\'.tcsh': 'tcsh', +\'.tex': 'tex', +\'.textile': 'textile', +\'.tpl': 'smarty', +\'.twig': 'twig', +\'.txt' : 'text', +\'.v': 'verilog', +\'.vala': 'vala', +\'.vb': 'vbnet', +\'.vhd': 'vhdl', +\'.vim': 'vim', +\'.weechatlog': 'weechatlog', +\'.xml': 'xml', +\'.xq': 'xquery', +\'.xs': 'xs', +\'.yml': 'yaml', \}, get(g:, 'gist_extmap', {})) let &cpo = s:save_cpo From 07bfa2cb4fce0a5cd0287dfb5e8db7a087abd3ab Mon Sep 17 00:00:00 2001 From: John Maguire Date: Sun, 21 Feb 2021 15:48:12 -0500 Subject: [PATCH 169/170] Fix token creation URL and file path in docs Similar to #226 though I made these changes before finding the pull request. In addition to the changes in #226, it updates the URL for the Personal Access Token to the correct one. --- doc/gist-vim.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/gist-vim.txt b/doc/gist-vim.txt index 88c46d1..2445d4c 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -275,7 +275,7 @@ rtp: - autoload/gist.vim - plugin/gist.vim -If you want to uninstall gist.vim, remember to also remove `~/.vim-gist`. +If you want to uninstall gist.vim, remember to also remove `~/.gist-vim`. You need to install webapi-vim also: @@ -295,7 +295,7 @@ REQUIREMENTS *vim-gist-requirements* ============================================================================== SETUP *vim-gist-setup* -This plugin uses GitHub API v3. The authentication value is stored in `~/.vim-gist`. +This plugin uses GitHub API v3. The authentication value is stored in `~/.gist-vim`. vim-gist provides two ways to authenticate against the GitHub APIs. First, you need to set your GitHub username in global git config: @@ -310,9 +310,9 @@ be kept for later use. You can revoke the token at any time from the list of 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 -create a "Personal Access Token" on GitHub's "Account Settings" page -(https://github.com/settings/applications) and place it in a file -named ~/.vim-gist like this: +create a "Personal Access Token" on GitHub's "Developer settings" page +(https://github.com/settings/tokens) with the gist scope and place it in a file +named ~/.gist-vim like this: > token xxxxx < @@ -334,7 +334,7 @@ NOTE: the username is optional if you only send anonymous gists. FAQ *vim-gist-faq* Q. :Gist returns a Forbidden error -A. Try deleting ~/.vim-gist and authenticating again. +A. Try deleting ~/.gist-vim and authenticating again. ============================================================================== THANKS *vim-gist-thanks* From 3bc3f58301d09e71ce90cc28865158fde9507725 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 170/170] 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 bfe84a0..1b9f04a 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 @@ -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 @@ -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' @@ -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*$') @@ -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 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: