My dotfiles. Period.

icomplete.vim 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. "=============================================================================
  2. " $Id$
  3. " File: autoload/lh/icomplete.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: 03rd Jan 2011
  10. " Last Update: $Date$
  11. "------------------------------------------------------------------------
  12. " Description:
  13. " Helpers functions to build |ins-completion-menu|
  14. "
  15. "------------------------------------------------------------------------
  16. " Installation:
  17. " Drop this file into {rtp}/autoload/lh
  18. " Requires Vim7+
  19. " History:
  20. " v3.0.0: GPLv3
  21. " v2.2.4: first version
  22. " TODO:
  23. " - We are not able to detect the end of the completion mode. As a
  24. " consequence we can't prevent c/for<space> to trigger an abbreviation
  25. " instead of the right template file.
  26. " In an ideal world, there would exist an event post |complete()|
  27. " }}}1
  28. "=============================================================================
  29. let s:cpo_save=&cpo
  30. set cpo&vim
  31. "------------------------------------------------------------------------
  32. " ## Misc Functions {{{1
  33. " # Version {{{2
  34. let s:k_version = 300
  35. function! lh#icomplete#version()
  36. return s:k_version
  37. endfunction
  38. " # Debug {{{2
  39. let s:verbose = 0
  40. function! lh#icomplete#verbose(...)
  41. if a:0 > 0 | let s:verbose = a:1 | endif
  42. return s:verbose
  43. endfunction
  44. function! s:Verbose(expr)
  45. if s:verbose
  46. echomsg a:expr
  47. endif
  48. endfunction
  49. function! lh#icomplete#debug(expr)
  50. return eval(a:expr)
  51. endfunction
  52. "------------------------------------------------------------------------
  53. " ## Exported functions {{{1
  54. " Function: lh#icomplete#run(startcol, matches, Hook) {{{2
  55. function! lh#icomplete#run(startcol, matches, Hook)
  56. call lh#icomplete#_register_hook(a:Hook)
  57. call complete(a:startcol, a:matches)
  58. return ''
  59. endfunction
  60. "------------------------------------------------------------------------
  61. " ## Internal functions {{{1
  62. " Function: lh#icomplete#_clear_key_bindings() {{{2
  63. function! lh#icomplete#_clear_key_bindings()
  64. iunmap <cr>
  65. iunmap <c-y>
  66. iunmap <esc>
  67. " iunmap <space>
  68. " iunmap <tab>
  69. endfunction
  70. " Function: lh#icomplete#_register_hook(Hook) {{{2
  71. function! lh#icomplete#_register_hook(Hook)
  72. exe 'inoremap <silent> <cr> <cr><c-\><c-n>:call' .a:Hook . '()<cr>'
  73. exe 'inoremap <silent> <c-y> <c-y><c-\><c-n>:call' .a:Hook . '()<cr>'
  74. " <c-o><Nop> doesn't work as expected...
  75. " To stay in INSERT-mode:
  76. " inoremap <silent> <esc> <c-e><c-o>:<cr>
  77. " To return into NORMAL-mode:
  78. inoremap <silent> <esc> <c-e><esc>
  79. call lh#event#register_for_one_execution_at('InsertLeave',
  80. \ ':call lh#icomplete#_clear_key_bindings()', 'CompleteGroup')
  81. endfunction
  82. "------------------------------------------------------------------------
  83. let &cpo=s:cpo_save
  84. "=============================================================================
  85. " vim600: set fdm=marker: