commit f43554597fc1b9bce35f15b53934c25c618b79a5 Author: ViViDboarder Date: Wed Jul 9 11:51:41 2014 -0700 Initial Commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..4d3b638 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +force-vim +=================== +Plugin for "compiling" Salesforce.com code with [force cli](http://github.com/heroku/force) + +Installation +------------ +* Install the [force cli](http://github.com/heroku/force) +* Use Vundle or something similar + +Usage +----- + + * `ForceDeploy`: executes `force push` to deploy file to server + * `ForceDeployTest`: executes `force test` to run tests in current class + * `ForceTarget`: Displays currently active target + * `ForceTarget ?`: List all orgs + * `ForceTarget orgName`: Activate specified org + +Based on plugin [vim-abuse-the-force](http://github.com/ViViDboarder/vim-abuse-the-force) diff --git a/compiler/ForceCli.vim b/compiler/ForceCli.vim new file mode 100644 index 0000000..5799e8f --- /dev/null +++ b/compiler/ForceCli.vim @@ -0,0 +1,16 @@ +" Vim compiler file +" Compiler: Salesforce Deploy +" Maintainer: Ian (ViViDboarder@gmail.com) +" Last Change: 2014 Jun 13 + +if exists("current_compiler") + finish +endif +let current_compiler = "ForceCli" + +if exists(":CompilerSet") != 2 " older Vim always used :setlocal + command -nargs=* CompilerSet setlocal +endif + +set errorformat+=%*[\"]%f%*[\"]\\,\ line\ %l:\ %m +CompilerSet makeprg=force\ push\ % diff --git a/plugin/ForceCli.vim b/plugin/ForceCli.vim new file mode 100644 index 0000000..61c04ed --- /dev/null +++ b/plugin/ForceCli.vim @@ -0,0 +1,83 @@ + +if !exists("g:force_dispatch_background") + let g:force_dispatch_background = 0 +end + +function! ForceDeploy() + let filePath = expand("%") + + let command = "force push \"" . filePath . "\"" + call ForceTryStart(command) + +endfunction + +function! ForceDeployTest() + let fileName = expand("%:t:r") + + let command = "force test \"" . fileName ."\"" + call ForceTryStart(command) + +endfunction + +" function! ForceRetrieve() +" let filePath = expand("%") +" +" let command = +" call ForceTryStart(command) +" +" endfunction + +function! ForceTarget(...) + if a:0 > 0 + + if a:1 == "?" + let command = "force logins" + else + let target = a:1 + + let command = "force active \"" . target . "\"" + end + else + let command = "force active" + end + + if exists("l:command") + call ForceTryStart(command) + end + +endfunction + +" Try to run the command using vim-dispatch +" (https://github.com/tpope/vim-dispatch) +function! ForceTryStart(...) + + " Make sure we have a parameter + if a:0 > 0 + let command = a:1 + + if exists(":Dispatch") + " Determine foreground or background + if g:force_dispatch_background == 1 + let fgbg = "! " + else + let fgbg = " " + end + + let command = "Dispatch" . fgbg . command + else + let command = "!" . command + end + + execute command + end + +endfunction + +command! -nargs=0 ForceDeploy call ForceDeploy() " Deploy current file +command! -nargs=0 ForceDeployTest call ForceDeployTest() " Deploy current file and run test +"command! -nargs=0 ForceRetrieve call ForceRetrieve() " Retrieve current file +command! -nargs=? ForceTarget call ForceTarget() " Change deploy target + +" Set SF Compiler +autocmd BufNewFile,BufRead *.cls,*.trigger,*.page,*.component compiler ForceCli + diff --git a/plugin/FormatApex.vim b/plugin/FormatApex.vim new file mode 100644 index 0000000..34e9da6 --- /dev/null +++ b/plugin/FormatApex.vim @@ -0,0 +1,33 @@ +function! FormatApex() + " Mark current location + normal mz + + " Delete extra lines + :%s/\s\+$//e + :%s/\n\{3,}/\r\r/e + + " Delete blank lines before } after ; or } + :%s/;\s*\n\s*\n\s*}/;\r}/ge + :%s/}\s*\n\s*\n\s*}/}\r}/ge + + " Delete blank lines before catch and else + :%s/}\s*\n\s*\n\s*catch/}\rcatch/ge + :%s/}\s*\n\s*\n\s*else/}\relse/ge + + " Put space after if/for/while/catch + :%s/if(/if (/ge + :%s/for(/for (/ge + :%s/while(/while (/ge + :%s/catch(/catch (/ge + + " Put space between ){ + :%s/){/) {/ge + + " Fix indentations + normal gg=G + + " return to starting point + normal `z +endfunction +command! FormatApex call FormatApex() +command! FixApex call FormatApex() \ No newline at end of file diff --git a/plugin/SfdcEol.vim b/plugin/SfdcEol.vim new file mode 100644 index 0000000..aa9c248 --- /dev/null +++ b/plugin/SfdcEol.vim @@ -0,0 +1,56 @@ +" Copied from: http://vim.wikia.com/wiki/Preserve_missing_end-of-line_at_end_of_text_files + +" Preserve noeol (missing trailing eol) when saving file. In order +" to do this we need to temporarily 'set binary' for the duration of +" file writing, and for DOS line endings, add the CRs manually. +" For Mac line endings, also must join everything to one line since it doesn't +" use a LF character anywhere and 'binary' writes everything as if it were Unix. + +" This works because 'eol' is set properly no matter what file format is used, +" even if it is only used when 'binary' is set. + +augroup automatic_noeol + au! + au BufWritePre * call TempSetBinaryForNoeol() + au BufWritePost * call TempRestoreBinaryForNoeol() +augroup END + +function! s:TempSetBinaryForNoeol() + let s:save_binary = &binary + if ! &eol && ! &binary + let s:save_view = winsaveview() + setlocal binary + if &ff == "dos" || &ff == "mac" + if line('$') > 1 + undojoin | exec "silent 1,$-1normal! A\\" + endif + endif + if &ff == "mac" + undojoin | %join! + " mac format does not use a \n anywhere, so we don't add one when writing + " in binary (which uses unix format always). However, inside the outer + " if statement, we already know that 'noeol' is set, so no special logic + " is needed. + endif + endif +endfunction + +function! s:TempRestoreBinaryForNoeol() + if ! &eol && ! s:save_binary + if &ff == "dos" + if line('$') > 1 + " Sometimes undojoin gives errors here, even when it shouldn't. + " Suppress them for now...if you can figure out and fix them instead, + " please update http://vim.wikia.com/wiki/VimTip1369 + silent! undojoin | silent 1,$-1s/\r$//e + endif + elseif &ff == "mac" + " Sometimes undojoin gives errors here, even when it shouldn't. + " Suppress them for now...if you can figure out and fix them instead, + " please update http://vim.wikia.com/wiki/VimTip1369 + silent! undojoin | silent %s/\r/\r/ge + endif + setlocal nobinary + call winrestview(s:save_view) + endif +endfunction \ No newline at end of file