Skip to content

Instantly share code, notes, and snippets.

@bootleq
Created August 24, 2010 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bootleq/546828 to your computer and use it in GitHub Desktop.
Save bootleq/546828 to your computer and use it in GitHub Desktop.
command! -nargs=* Bookmarklet call Bookmarklet(<f-args>)
fun! Bookmarklet(...)
let result = JsCompress(0, 0, '--compilation_level=WHITESPACE_ONLY')
if len(getqflist()) == 0 && strlen(result) > 0
let reuse_win = 0
for winnr in tabpagebuflist(tabpagenr())
if bufname(winnr) == '[Bookmarklet]'
exec winnr . 'wincmd w'
let reuse_win = winnr
endif
endfor
if ! reuse_win
exec 'belowright 5new [Bookmarklet]'
setlocal noswapfile bufhidden=wipe winfixheight filetype=javascript
endif
let result = substitute(result, '[\n]', '', '')
setlocal buftype=
call setline(1, 'javascript:(function(){' . result . '})();')
if has('ruby')
ruby require("uri"); VIM::Buffer.current.line = URI.escape(VIM::Buffer.current.line);
else
echohl WarningMsg | echomsg "No ruby support. Can't do URI encoding." | echohl None
endif
setlocal buftype=nofile
endif
endf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment