From 8a33cf198513cab8b5f75cadaa588804b0ff47d6 Mon Sep 17 00:00:00 2001 From: Allex Wang Date: Fri, 12 Jun 2015 11:12:51 +0800 Subject: [PATCH 1/4] Support GistURL --- autoload/gist.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/autoload/gist.vim b/autoload/gist.vim index 6683cd2..4c4cc1f 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -583,6 +583,12 @@ function! s:update_GistID(id) abort call setline('.', line . ' ' . a:id) let ret = 1 endif + if search('\:\s*$') + let line = getline('.') + let line = substitute(line, '\s\+$', '', 'g') + call setline('.', line . ' https://gist.github.com/' . a:id) + let ret = 1 + endif call winrestview(view) return ret endfunction From c666f7d10fce017a0481a624ccd78ce75d9870d6 Mon Sep 17 00:00:00 2001 From: Allex Wang Date: Wed, 18 May 2022 19:46:15 +0800 Subject: [PATCH 2/4] fix: ensure gist with EOL --- autoload/gist.vim | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 67f2234..0b954ec 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -534,6 +534,15 @@ function! s:GistListAction(mode) abort endif endfunction +func s:fix_eol(content) abort + let s = a:content + let lastchar=char2nr(s[-1:]) + if lastchar != 10 + let s.="\n" + endif + return s +endfunc + function! s:GistUpdate(content, gistid, gistnm, desc) abort let gist = { 'id': a:gistid, 'files' : {}, 'description': '','public': function('webapi#json#true') } if exists('b:gist') @@ -569,7 +578,8 @@ function! s:GistUpdate(content, gistid, gistnm, desc) abort endif endif - let gist.files[filename] = { 'content': a:content, 'filename': filename } + let content = s:fix_eol(a:content) + let gist.files[filename] = { 'content': content, 'filename': filename } redraw | echon 'Updating gist... ' let res = webapi#http#post(g:gist_api_url.'gists/' . a:gistid, @@ -663,7 +673,7 @@ function! s:GistPost(content, private, desc, anonymous) abort 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': s:fix_eol(a:content), 'filename': filename } let header = {'Content-Type': 'application/json'} if !a:anonymous @@ -714,7 +724,7 @@ function! s:GistPostBuffers(private, desc, anonymous) abort endif echo 'Creating gist content'.index.'... ' silent! exec 'buffer!' bufnr - let content = join(getline(1, line('$')), "\n") + let content = s:fix_eol(join(getline(1, line('$')), "\n")) let filename = s:get_current_filename(index) let gist.files[filename] = { 'content': content, 'filename': filename } let index = index + 1 From c894fb8f5710bec2397645e892cb30c4abcbc216 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Sun, 21 Feb 2021 15:48:12 -0500 Subject: [PATCH 3/4] 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 2810b96..6074aba 100644 --- a/doc/gist-vim.txt +++ b/doc/gist-vim.txt @@ -281,7 +281,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: @@ -301,7 +301,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: @@ -316,9 +316,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 < @@ -340,7 +340,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 44eb504f1b1ee447f53937664a050a24e09b231a Mon Sep 17 00:00:00 2001 From: Allex Wang Date: Tue, 27 Jun 2023 19:07:09 +0800 Subject: [PATCH 4/4] fix: show full error content and add fixes for latest api spec (remove public and id) --- autoload/gist.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/autoload/gist.vim b/autoload/gist.vim index 0b954ec..e8b4c92 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -544,13 +544,12 @@ func s:fix_eol(content) abort endfunc function! s:GistUpdate(content, gistid, gistnm, desc) abort - let gist = { 'id': a:gistid, 'files' : {}, 'description': '','public': function('webapi#json#true') } + let gist = { 'files' : {}, 'description': '' } 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 else @@ -595,6 +594,9 @@ function! s:GistUpdate(content, gistid, gistnm, desc) abort redraw | echomsg 'Done: '.loc else let loc = '' + if len(res.message) == 0 + let res.message = res.content + endif echohl ErrorMsg | echomsg 'Post failed: ' . res.message | echohl None endif return loc