My dotfiles. Period.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. "=============================================================================
  2. " $Id: askvim.vim 520 2012-03-19 18:09:15Z luc.hermitte $
  3. " File: autoload/lh/askvim.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: 17th Apr 2007
  10. " Last Update: $Date: 2012-03-19 19:09:15 +0100 (Mon, 19 Mar 2012) $ (17th Apr 2007)
  11. "------------------------------------------------------------------------
  12. " Description:
  13. " Defines functions that asks vim what it is relinquish to tell us
  14. " - menu
  15. "
  16. "------------------------------------------------------------------------
  17. " Installation:
  18. " Drop it into {rtp}/autoload/lh/
  19. " Vim 7+ required.
  20. " History:
  21. " v2.0.0:
  22. " v3.0.0: GPLv3
  23. " TODO: «missing features»
  24. " }}}1
  25. "=============================================================================
  26. "=============================================================================
  27. let s:cpo_save=&cpo
  28. set cpo&vim
  29. "------------------------------------------------------------------------
  30. " ## Functions {{{1
  31. " # Debug {{{2
  32. function! lh#askvim#verbose(level)
  33. let s:verbose = a:level
  34. endfunction
  35. function! s:Verbose(expr)
  36. if exists('s:verbose') && s:verbose
  37. echomsg a:expr
  38. endif
  39. endfunction
  40. function! lh#askvim#debug(expr)
  41. return eval(a:expr)
  42. endfunction
  43. "------------------------------------------------------------------------
  44. " # Public {{{2
  45. " Function: lh#askvim#exe(command) {{{3
  46. function! lh#askvim#Exe(command)
  47. echomsg 'lh#askvim#Exe() is deprecated, use lh#askvim#exe()'
  48. return lh#askvim#exe(a:command)
  49. endfunction
  50. function! lh#askvim#exe(command)
  51. let save_a = @a
  52. try
  53. silent! redir @a
  54. silent! exe a:command
  55. redir END
  56. finally
  57. " Always restore everything
  58. let res = @a
  59. let @a = save_a
  60. return res
  61. endtry
  62. endfunction
  63. " Function: lh#askvim#menu(menuid) {{{3
  64. function! s:AskOneMenu(menuact, res)
  65. let sKnown_menus = lh#askvim#exe(a:menuact)
  66. let lKnown_menus = split(sKnown_menus, '\n')
  67. " echo string(lKnown_menus)
  68. " 1- search for the menuid
  69. " todo: fix the next line to correctly interpret "stuff\.stuff" and
  70. " "stuff\\.stuff".
  71. let menuid_parts = split(a:menuact, '\.')
  72. let simplifiedKnown_menus = deepcopy(lKnown_menus)
  73. call map(simplifiedKnown_menus, 'substitute(v:val, "&", "", "g")')
  74. " let idx = lh#list#match(simplifiedKnown_menus, '^\d\+\s\+'.menuid_parts[-1])
  75. let idx = match(simplifiedKnown_menus, '^\d\+\s\+'.menuid_parts[-1])
  76. if idx == -1
  77. " echo "not found"
  78. return
  79. endif
  80. " echo "l[".idx."]=".lKnown_menus[idx]
  81. if empty(a:res)
  82. let a:res.priority = matchstr(lKnown_menus[idx], '\d\+\ze\s\+.*')
  83. let a:res.name = matchstr(lKnown_menus[idx], '\d\+\s\+\zs.*')
  84. let a:res.actions = {}
  85. " else
  86. " what if the priority isn't the same?
  87. endif
  88. " 2- search for the menu definition
  89. let idx += 1
  90. while idx != len(lKnown_menus)
  91. echo "l[".idx."]=".lKnown_menus[idx]
  92. " should not happen
  93. if lKnown_menus[idx] =~ '^\d\+' | break | endif
  94. " :h showing-menus
  95. " -> The format of the result of the call to Exe() seems to be:
  96. " ^ssssMns-sACTION$
  97. " s == 1 whitespace
  98. " M == mode (inrvcs)
  99. " n == noremap(*)/script(&)
  100. " - == disable(-)/of not
  101. let act = {}
  102. let menu_def = matchlist(lKnown_menus[idx],
  103. \ '^\s*\([invocs]\)\([&* ]\) \([- ]\) \(.*\)$')
  104. if len(menu_def) > 4
  105. let act.mode = menu_def[1]
  106. let act.nore_script = menu_def[2]
  107. let act.disabled = menu_def[3]
  108. let act.action = menu_def[4]
  109. else
  110. echomsg string(menu_def)
  111. echoerr "lh#askvim#menu(): Cannot decode ``".lKnown_menus[idx]."''"
  112. endif
  113. let a:res.actions["mode_" . act.mode] = act
  114. let idx += 1
  115. endwhile
  116. " n- Return the result
  117. return a:res
  118. endfunction
  119. function! lh#askvim#menu(menuid, modes)
  120. let res = {}
  121. let i = 0
  122. while i != strlen(a:modes)
  123. call s:AskOneMenu(a:modes[i].'menu '.a:menuid, res)
  124. let i += 1
  125. endwhile
  126. return res
  127. endfunction
  128. " Functions }}}1
  129. "------------------------------------------------------------------------
  130. let &cpo=s:cpo_save
  131. "=============================================================================
  132. " vim600: set fdm=marker: