Skip to content

Commit

Permalink
add g:sprunge_flush_left option, attempt to fix issue #12
Browse files Browse the repository at this point in the history
  • Loading branch information
javier-lopez committed Apr 6, 2016
1 parent 2a9c976 commit 78b610f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
29 changes: 26 additions & 3 deletions autoload/sprunge.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
" Description: vim global plugin to paste to http://sprunge.us/
" Maintainer: Javier Lopez <m@javier.io>
" License: WTFPL
" Notes: Much of this code was thiefed from gundo.vim
" ============================================================================

function! sprunge#CopyToClipboard(clip) "{{{
Expand All @@ -24,12 +23,32 @@ function! sprunge#CopyToClipboard(clip) "{{{
call setreg('*', a:clip)
endif
endif

if exists('g:sprunge_clipboard_cmd')
call system('printf "' . a:clip . '"' . ' | ' . g:sprunge_clipboard_cmd)
endif
endfunction

function! sprunge#FlushLeft(line1, line2) "{{{1
let l:current_line = a:line1
let l:min_white_spaces = 9999
while l:current_line <= a:line2
if getline(l:current_line) =~# '^$'
let l:current_line = l:current_line + 1
continue
else
let l:white_spaces = indent(l:current_line)
let l:current_line = l:current_line + 1
if l:white_spaces < l:min_white_spaces
let l:min_white_spaces = l:white_spaces
endif
endif
endw
let l:buffer = '' | for line in getline(a:line1, a:line2)
let l:buffer .= strpart(line, l:min_white_spaces) . "\n"
endfor
return l:buffer
endfunction

function! sprunge#OpenBrowser(url) "{{{1
if has("win32")
exe "!start cmd /cstart /b ".a:url.""
Expand All @@ -46,7 +65,11 @@ function! sprunge#Post(line1, line2) "{{{
echoerr "Sprunge: requires 'curl'"
return
endif
let buffer = join(getline(a:line1, a:line2), "\n") . "\n"
if !exists('g:sprunge_flush_left')
let buffer = join(getline(a:line1, a:line2), "\n") . "\n"
else
let buffer = sprunge#FlushLeft(a:line1, a:line2)
endif
redraw | echon 'Posting to sprunge ... '
let l:url = system(g:sprunge_cmd, buffer)[0:-2]
if empty(l:url)
Expand Down
34 changes: 21 additions & 13 deletions doc/sprunge.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ CONTENTS *Sprunge-contents*
==============================================================================
INTRO *SprungeIntro*

There are several pastebin sites on Internet, and there exist even a vim
plugin for Gist: https://github.com/mattn/gist-vim. So why yet another
pastebin plugin?, well, all previous vim plugins uses providers who require to
open a browser to fetch the content, not cool.
Sprunge.us is a suckless pastebin service, unless others you're able to
upload|retrieve content without a web browser.

http://sprunge.us/ does not!, try this:
Quickstart
----------

Upload

$ ls | curl -F 'sprunge=<-' http://sprunge.us

now this:
Retrieve

$ curl <url-sprunge-generated>

Expand All @@ -38,8 +39,8 @@ USAGE *SprungeUsage*
After pressing <Enter>, you'll get a url with the content of your file. You
can also invoke this in visual mode to sprunge only the visual selection.

Alternatively you may also use the '<Leader>s' mapping, you can override this
mapping by setting 'g:sprunge_map' in your .vimrc
Alternatively you may also use the '<Leader>s' mapping, or any other by
setting 'g:sprunge_map' in your .vimrc

Wondering how to make sprunge.us to colorize your paste?, go to
|SprungeContributing|.
Expand All @@ -52,13 +53,15 @@ These options should be set in your .vimrc file.
g:sprunge_cmd *SprungeConfig-cmd*
User defined sprunge command

Use this option to customize the sprunge command >
Use this option to customize the sprunge command. >
let g:sprunge_cmd = 'curl -s -F "sprunge=<-" http://sprunge.us'
<

g:sprunge_clipboard *SprungeConfig-clipboard*
Default clipboard

Use this option to specify the target clipboard. Default to 'all'

Acceptable Values: "none", "vim", "external", "all". >
let g:sprunge_clipboard = 'all'
<
Expand All @@ -73,21 +76,26 @@ g:sprunge_clipboard *SprungeConfig-clipboard*
g:sprunge_clipboard_cmd *SprungeConfig-clipboard-cmd*
User defined clipboard

Use this option to configure any other third party clipboard application >
Use this option to configure third party clipboard application. >
let g:sprunge_clipboard_cmd = 'clipboard_app --option'
<

g:sprunge_open_browser *SprungeConfig-open-browser*
Use this option to enable opening the sprunge link in your default
browser. >
Use this option to open the sprunge link automatically in your default
browser. Disabled by default. >
let g:sprunge_open_browser = 0
<

g:sprunge_flush_left *SprungeConfig-flush-left*
Use this option to aligned along the left margin before pasting. Disabled
by default. >
let g:sprunge_flush_left = 0
<

g:sprunge_map *SprungeConfig-map*
Use this option to configure the default mapping >
let g:sprunge_map = '<Leader>s'
<

Alternatively the mapping can be assigned directly to the <Plug> action >
map <Leader>s <Plug>Sprunge
<
Expand Down

0 comments on commit 78b610f

Please sign in to comment.