Skip to content

Commit

Permalink
new config variable - 'g:apex_OnCommandComplete'
Browse files Browse the repository at this point in the history
execute a shell command upon completion of long running Apex command
  • Loading branch information
neowit committed May 15, 2015
1 parent a8de2d6 commit 7980a88
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
47 changes: 45 additions & 2 deletions apex-plugin/apexTooling.vim
Expand Up @@ -632,11 +632,20 @@ endfunction
" returns:
" 0 - if RESULT=SUCCESS
" any value > 0 - if RESULT <> SUCCESS
function! s:parseErrorLog(logFilePath, projectPath, displayMessageTypes, isSilent)
function! s:parseErrorLog(logFilePath, projectPath, displayMessageTypes, isSilent, disableMorePrompt)
"clear quickfix
call setqflist([])
call CloseEmptyQuickfixes()

"temporarily disable more if enabled
"also see :help hit-enter
let disableMore = a:disableMorePrompt
let reEnableMore = 0
if disableMore
let reEnableMore = &more
set nomore
endif

let fileName = a:logFilePath
if bufexists(fileName)
" kill buffer with ant log file, otherwise vimgrep uses its buffer instead
Expand All @@ -653,6 +662,9 @@ function! s:parseErrorLog(logFilePath, projectPath, displayMessageTypes, isSilen
if s:displayMessages(a:logFilePath, a:projectPath, a:displayMessageTypes) < 1 && !a:isSilent
call apexUtil#info("No errors found")
endif
if disableMore && reEnableMore
set more
endif
return 0
endif

Expand All @@ -661,6 +673,9 @@ function! s:parseErrorLog(logFilePath, projectPath, displayMessageTypes, isSilen
call s:displayMessages(a:logFilePath, a:projectPath, a:displayMessageTypes)

call s:fillQuickfix(a:logFilePath, a:projectPath)
if disableMore && reEnableMore
set more
endif
return 1

endfunction
Expand Down Expand Up @@ -954,6 +969,7 @@ function! apexTooling#execute(action, projectName, projectPath, extraParams, dis
" make sure we do not accidentally reuse old responseFile
call delete(responseFilePath)

let l:startTime = reltime()
"call apexOs#exe(l:command, 'M') "disable --more--
call s:runCommand(l:java_command, l:command, isSilent)

Expand All @@ -968,10 +984,37 @@ function! apexTooling#execute(action, projectName, projectPath, extraParams, dis
elseif exists("s:apex_last_log")
unlet s:apex_last_log
endif
let errCount = s:parseErrorLog(responseFilePath, a:projectPath, a:displayMessageTypes, isSilent)
let l:disableMorePrompt = s:hasOnCommandComplete()

let errCount = s:parseErrorLog(responseFilePath, a:projectPath, a:displayMessageTypes, isSilent, l:disableMorePrompt)
"echo "l:startTime=" . string(l:startTime)
call s:onCommandComplete(reltime(l:startTime))
return {"success": 0 == errCount? "true": "false", "responseFilePath": responseFilePath}
endfunction

" check if user has defined g:apex_OnCommandComplete
function! s:hasOnCommandComplete()
return exists('g:apex_OnCommandComplete') && type({}) == type(g:apex_OnCommandComplete)
endfunction

" if user defined custom function to run on command complete then run it
function! s:onCommandComplete(timeElapsed)
if s:hasOnCommandComplete()
let l:command = g:apex_OnCommandComplete['script']
if len(l:command) > 0
let l:flags = 's' " silent
"echo "a:timeElapsed=" . string(a:timeElapsed)
if has_key(g:apex_OnCommandComplete, 'timeoutSec')
if a:timeElapsed[0] > str2nr(g:apex_OnCommandComplete['timeoutSec'])
call apexOs#exe(l:command, l:flags)
endif
else
call apexOs#exe(l:command, l:flags)
endif
endif

endif
endfunction
"================= server mode commands ==========================

" send server 'shutdown' command to stop it
Expand Down
28 changes: 27 additions & 1 deletion doc/force.com.txt
Expand Up @@ -747,10 +747,12 @@ Optional
|'g:apex_workspace_path'| root folder to use when creating new project
with :|ApexInitProject|

|'g:apex_OnCommandComplete'| script to execute at the end of long running
command

|'g:apex_server'| enable/disable server mode
|'g:apex_server_timeoutSec'| automatic server shutdown timeout


*'g:apex_backup_folder'*

/path/to/folder where current project source is backed up before refresh from SFDC
Expand Down Expand Up @@ -932,6 +934,30 @@ e.g. >
<
see also |zipped-resources|

*'g:apex_OnCommandComplete'*
Optional.
Can be used to execute a shell command upon completion of long running
Apex command.
'g:apex_OnCommandComplete' is a dictionary which accepts two values:
- script: full command line
- timeoutSec: how long command needs to run for script to be executed

Example 1: (OSX, MacVim) >
let g:apex_OnCommandComplete = {'script': 'osascript -e "tell application \"MacVim\" to activate"', 'timeoutSec': 10}
<
if Apex command (e.g. :|ApexTest|) runs for more than 10 seconds then upon
completion MacVim window will be brought back to focus. May be useful if you
want to switch to another application while vim is working, but want to go back
to vim as soon as command execution is done.

Example 2: (OSX) if you want to announce completion of long running :|ApexDeploy|
then g:apex_OnCommandComplete can be configured like so: >
let g:apex_OnCommandComplete = {'script': 'say "Job finished"', 'timeoutSec': 10}
<
if command runs for more than 10 seconds then upon completion you will hear
"Job finished" from computer speaker.


*'g:apex_workspace_path'*
Optional.
root folder to use when creating new project with :|ApexInitProject|
Expand Down

0 comments on commit 7980a88

Please sign in to comment.