My dotfiles. Period.

event.vim 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. "=============================================================================
  2. " $Id: event.vim 520 2012-03-19 18:09:15Z luc.hermitte $
  3. " File: autoload/lh/event.vim {{{1
  4. " Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
  5. " <URL:http://code.google.com/p/lh-vim/>
  6. " License: GPLv3 with exceptions
  7. " <URL:http://code.google.com/p/lh-vim/wiki/License>
  8. " Version: 3.0.0
  9. " Created: 15th Feb 2008
  10. " Last Update: $Date: 2012-03-19 19:09:15 +0100 (Mon, 19 Mar 2012) $
  11. "------------------------------------------------------------------------
  12. " Description:
  13. " Function to help manage vim |autocommand-events|
  14. "
  15. "------------------------------------------------------------------------
  16. " Installation:
  17. " Drop it into {rtp}/autoload/lh/
  18. " Vim 7+ required.
  19. " History:
  20. " v2.0.6: Creation
  21. " v3.0.0: GPLv3
  22. " TODO:
  23. " }}}1
  24. "=============================================================================
  25. let s:cpo_save=&cpo
  26. set cpo&vim
  27. "------------------------------------------------------------------------
  28. " ## Functions {{{1
  29. " # Debug {{{2
  30. function! lh#event#verbose(level)
  31. let s:verbose = a:level
  32. endfunction
  33. function! s:Verbose(expr)
  34. if exists('s:verbose') && s:verbose
  35. echomsg a:expr
  36. endif
  37. endfunction
  38. function! lh#event#debug(expr)
  39. return eval(a:expr)
  40. endfunction
  41. "------------------------------------------------------------------------
  42. " # Event Registration {{{2
  43. function! s:RegisteredOnce(cmd, group)
  44. " We can't delete the current augroup autocommand => increment a counter
  45. if !exists('s:'.a:group) || s:{a:group} == 0
  46. let s:{a:group} = 1
  47. exe a:cmd
  48. endif
  49. endfunction
  50. function! lh#event#register_for_one_execution_at(event, cmd, group)
  51. let group = a:group.'_once'
  52. let s:{group} = 0
  53. exe 'augroup '.group
  54. au!
  55. exe 'au '.a:event.' '.expand('%:p').' call s:RegisteredOnce('.string(a:cmd).','.string(group).')'
  56. augroup END
  57. endfunction
  58. function! lh#event#RegisterForOneExecutionAt(event, cmd, group)
  59. return lh#event#register_for_one_execution_at(a:event, a:cmd, a:group)
  60. endfunction
  61. "------------------------------------------------------------------------
  62. let &cpo=s:cpo_save
  63. "=============================================================================
  64. " vim600: set fdm=marker: