Source

vim-l9 / plugin / l9.vim

"=============================================================================
" Copyright (C) 2009-2010 Takeshi NISHIDA
"
" TODO: GetLatestVimScripts
"=============================================================================
" LOAD GUARD {{{1

if !l9#guardScriptLoading(expand('<sfile>:p'), 702, l9#getVersion())
  finish
endif

" }}}1
"=============================================================================
" OPTIONS: {{{1

call l9#defineVariableDefault('g:l9_balloonly', 'balloonly.exe')

" }}}1
"=============================================================================
" ASSERTION: {{{1

" This command has effect only if $L9_DEBUG is non-zero.
" Used as follows:
"   L9Assert a:i > 0
" This command can't interpret script-local variables directly.
"   NG: L9Assert s:a == 1
"   OK: execute 'L9Assert ' . s:a . ' == 1'
"
if $L9_DEBUG
  command -nargs=* L9Assert call eval((<args>) ? 0 : s:handleFailedAssersion(<q-args>))

  function s:handleFailedAssersion(expr)
    echoerr '[L9Assert] Assersion failure: ' . a:expr
    if input('[L9Assert] Continue? (Y/N) ', 'Y') !=? 'Y'
      throw 'L9Assert ' . a:expr
    endif
  endfunction

else
  command -nargs=* L9Assert :
endif

" }}}1
"=============================================================================
" TIMER: {{{1

" These commands have effect only if $L9_TIMER is non-zero.
" Used as follows:
"   L9Timer foo
"     ... (1)
"   L9Timer bar
"     ... (2)
"   L9TimerStop
"     ...
"   L9TimerDump  <- shows each elapsed time of (1) and (2)
"
if $L9_TIMER
  command -nargs=1 L9Timer call s:timerBegin(<q-args>)
  command -nargs=0 L9TimerStop call s:timerStop()
  command -nargs=0 L9TimerDump call s:timerDump()

  let s:timerData = []
  let s:timerTagMaxLen = 0

  function s:timerBegin(tag)
    L9TimerStop
    let s:timerCurrent = {'tag': strftime('%c ') . a:tag . ' ', 'time': reltime()}
    let s:timerTagMaxLen = max([len(s:timerCurrent.tag), s:timerTagMaxLen])
  endfunction

  function s:timerStop()
    if !exists('s:timerCurrent')
      return
    endif
    let s:timerCurrent.time = reltimestr(reltime(s:timerCurrent.time))
    call add(s:timerData, s:timerCurrent)
    unlet s:timerCurrent
  endfunction

  function s:timerDump()
    L9TimerStop
    let lines = map(s:timerData, 'v:val.tag . repeat(" ", s:timerTagMaxLen - len(v:val.tag)) . v:val.time')
    call l9#tempbuffer#openReadOnly('[l9-timer]', '', lines, 0, 0, 0, {})
    let s:timerData = []
    let s:timerTagMaxLen = 0
  endfunction

else
  command -nargs=1 L9Timer :
  command -nargs=0 L9TimerStop :
  command -nargs=0 L9TimerDump :
endif

" }}}1
"=============================================================================
" GREP BUFFER: {{{1

" Grep for current buffer by l9#grepBuffers()
" Used as :L9GrepBuffer/pattern
command -nargs=? L9GrepBuffer    call l9#grepBuffers(<q-args>, [bufnr('%')])

" Grep for all buffers by l9#grepBuffers()
" Used as :L9GrepBufferAll/pattern
command -nargs=? L9GrepBufferAll call l9#grepBuffers(<q-args>, range(1, bufnr('$')))

" }}}1
"=============================================================================
" vim: set fdm=marker:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.