if exists('g:carbon_now_sh_loaded') finish endif let g:carbon_now_sh_loaded = 1 let g:carbon_now_sh_options = get(g:, 'carbon_now_sh_options', {}) let g:carbon_now_sh_browser = get(g:, 'carbon_now_sh_browser', '') let g:carbon_now_sh_base_url = get(g:, 'carbon_now_sh_base_url', 'https://carbon.now.sh') let g:carbon_now_sh_trace = get(g:, 'carbon_now_sh_trace', 0) command! -range=% CarbonNowSh ,call s:carbonNowSh() function! s:carbonNowSh() range let l:text = s:urlEncode(s:getVisualSelection()) let l:browser = s:getBrowser() let l:options = type(g:carbon_now_sh_options) == v:t_dict ? s:getOptions() : g:carbon_now_sh_options let l:filetype = &filetype let l:url = g:carbon_now_sh_base_url .. '/?l=' .. l:filetype .. '&code=' .. l:text .. '&' .. l:options if g:carbon_now_sh_trace echom 'navigate to: ' . l:url endif if has('win32') && l:browser ==? 'start' && &shell =~? '\= 48 && l:ascii_code <= 57 return 0 elseif l:ascii_code >= 65 && l:ascii_code <= 90 return 0 elseif l:ascii_code >= 97 && l:ascii_code <= 122 return 0 elseif a:character ==? '-' || a:character ==? '_' || a:character ==? '.' || a:character ==? '~' return 0 endif return 1 endfunction "}}} function! s:getVisualSelection() "{{{ let [l:line_start, l:column_start] = getpos("'<")[1:2] let [l:line_end, l:column_end] = getpos("'>")[1:2] let l:lines = getline(l:line_start, l:line_end) if len(l:lines) == 0 return '' endif let l:lines[-1] = l:lines[-1][:l:column_end - (&selection ==? 'inclusive' ? 1 : 2)] let l:lines[0] = l:lines[0][l:column_start - 1:] return join(l:lines, "\n") endfunction "}}} " vim:foldenable:foldmethod=marker:sw=2