summaryrefslogtreecommitdiff
path: root/plugin/l9.vim
blob: 03613e40dc41e8d381577def45a5ff26dc6762fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"=============================================================================
" Copyright (C) 2009-2010 Takeshi NISHIDA
"
" GetLatestVimScripts: 3252 1 :AutoInstall: L9
"=============================================================================
" LOAD GUARD {{{1

if !l9#guardScriptLoading(expand('<sfile>:p'), 702, 0, [])
  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: