PageRenderTime 59ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/vim/bundle/vim-signature/plugin/signature.vim

https://github.com/Lubomir-Russia/dotfiles
Vim Script | 320 lines | 91 code | 19 blank | 210 comment | 23 complexity | dd05afe01378b81921a9267668e24487 MD5 | raw file
  1. " README: {{{1
  2. " vim-signature, version 1.3
  3. "
  4. " Description: {{{2
  5. " vim-signature is a plugin to toggle, display and navigate marks.
  6. " What are marks you say... Read [this](http://vim.wikia.com/wiki/Using_marks)
  7. "
  8. " Wait a minute...isn't this done not only well but excellently so by vim-showmarks
  9. " and mark-tools; why another plugin you say?
  10. " Well, you are right. However, I got a little impatient with the delay between
  11. " setting and display of marks in vim-showmarks and
  12. " I liked the navigation options which mark-tools provided and I didn't want to
  13. " use two plugins where one would do and
  14. " I was bored and felt like writing my own...
  15. "
  16. " Are you convinced yet or do you want me to go on? Anyway, that's how vim-signature was born.
  17. " Oh, and I also added some touches of my own such as
  18. " * Displaying multiple marks (upto 2, limited by the signs feature)
  19. " * Placing custom signs !@#$%^&*() as visual markers
  20. "
  21. " ### Screenshots
  22. " [Click](http://imgur.com/a/bPp3m#0)
  23. "
  24. " ### Vim.org mirror
  25. " http://www.vim.org/scripts/script.php?script_id=4118
  26. "
  27. " Requirements: {{{2
  28. " Requires Vim to be compiled with +signs to display marks.
  29. "
  30. "
  31. " Installation: {{{2
  32. " I highly recommend using Pathogen or Vundler to do the dirty work for you. If
  33. " for some reason, you do not want to use any of these excellent plugins, then
  34. " unzip it to your ~/.vim directory. You know how it goes...
  35. "
  36. " So, once that's done, out of the box, the followings mappings are defined by
  37. " default
  38. "
  39. " ````
  40. " m[a-zA-Z] : Toggle mark
  41. " m<Space> : Delete all marks
  42. " m, : Place the next available mark
  43. " ]` : Jump to next mark
  44. " [` : Jump to prev mark
  45. " ]' : Jump to start of next line containing a mark
  46. " [' : Jump to start of prev line containing a mark
  47. " `] : Jump by alphabetical order to next mark
  48. " `[ : Jump by alphabetical order to prev mark
  49. " '] : Jump by alphabetical order to start of next line containing a mark
  50. " '[ : Jump by alphabetical order to start of prev line containing a mark
  51. "
  52. " m[0-9] : Toggle the corresponding marker !@#$%^&*()
  53. " m<S-[0-9]> : Remove all markers of the same type
  54. " ]= : Jump to next line having same marker
  55. " ]- : Jump to prev line having same marker
  56. " m<BackSpace> : Remove all markers
  57. " ````
  58. "
  59. " This will allow the use of default behavior of m to set marks and, if the line
  60. " already contains the mark, it'll be unset.
  61. " The default behavior of `]'`, `['`, ``]` `` and ``[` `` is supported and enhanced by
  62. " wrapping around when beginning or end of file is reached.
  63. "
  64. " The command `SignatureToggleDisplay` can be used to show/hide the signs. Note that this does not delete any of the marks but only hides them.
  65. "
  66. "
  67. " Customisation: {{{2
  68. " The defaults not to your liking bub? Have no fear; use the following
  69. " variables to set things just the way you want it
  70. "
  71. " * `g:SignatureDefaultMappings` ( Default : 1 )
  72. " Will use the default mappings specified below.
  73. "
  74. " * `g:SignatureIncludeMarks` ( Default : 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' )
  75. " Specify the marks that can be controlled by this plugin.
  76. " Only supports Alphabetical marks at the moment.
  77. " `b:SignatureIncludeMarks` can be set separately to specify buffer-specific settings.
  78. "
  79. " * `g:SignatureWrapJumps` ( Default : 1 )
  80. " Specify if jumping to marks should wrap-around.
  81. " `b:SignatureWrapJumps` can be set to specify buffer-specific settings.
  82. "
  83. " * `g:SignatureMarkLeader` ( Default: m )
  84. " Set the key used to toggle marks. If this key is set to `<leader>m`,
  85. " `<leader>ma` will toggle the mark 'a'
  86. " `<leader>m,` will place the next available mark
  87. " `<leader>m<Space>` will delete all marks
  88. "
  89. " ````
  90. " <Plug>SIG_PlaceNextMark : Place next available mark
  91. " <Plug>SIG_PurgeMarks : Remove all marks
  92. " <Plug>SIG_NextSpotByPos : Jump to next mark
  93. " <Plug>SIG_PrevSpotByPos : Jump to prev mark
  94. " <Plug>SIG_NextLineByPos : Jump to start of next line containing a mark
  95. " <Plug>SIG_PrevLineByPos : Jump to start of prev line containing a mark
  96. " <Plug>SIG_NextSpotByAlpha : Jump by alphabetical order to next mark
  97. " <Plug>SIG_PrevSpotByAlpha : Jump by alphabetical order to prev mark
  98. " <Plug>SIG_NextLineByAlpha : Jump by alphabetical order to start of next line containing a mark
  99. " <Plug>SIG_PrevLineByAlpha : Jump by alphabetical order to start of prev line containing a mark
  100. " ````
  101. "
  102. " * `g:SignatureLcMarkStr` ( Default : "\p\m" )
  103. " Set the manner in which local (lowercase) marks are displayed.
  104. " `g:SignatureUcMarkStr` ( Default : "\p\m" )
  105. " Set the manner in which global (uppercase) marks are displayed. Similar to above.
  106. " `b:SignatureLcMarkStr` and `b:SignatureUcMarkStr`can be set separately to specify buffer-specific settings.
  107. "
  108. " `\m` represents the latest mark added and `\p`, the one previous to it.
  109. " ````
  110. " g:SignatureLcMarkStr = "\m." : Display last mark with '.' suffixed
  111. " g:SignatureLcMarkStr = "_\m" : Display last mark with '_' prefixed
  112. " g:SignatureLcMarkStr = ">" : Display ">" for a line containing a mark. The mark is not displayed
  113. " g:SignatureLcMarkStr = "\m\p" : Display last two marks placed
  114. " ````
  115. "
  116. " You can display upto 2 characters. That's a limitation imposed by the signs
  117. " feature; nothing I can do about it : / .
  118. " Setting the MarkStr to a single character will not suffix the mark.
  119. " Don't be lazy people, if you want to see the mark, set it accordingly.
  120. " Oh, and see in all the above strings, I've used double-quotes and not
  121. " single-quotes. That's not cause I love 'em but things go haywire if
  122. " double-quotes aren't used. Also, `\m` and `\p` cannot be set to _Space_
  123. "
  124. " * `g:SignatureMarkerLeader` ( Default: m )
  125. " Set the key used to toggle markers. If this key is set to `<leader>m`
  126. " `<leader>m1` will toggle the marker '!'
  127. " `<leader>m!` will remove all the '!' markers
  128. "
  129. " * `g:SignatureIncludeMarkers` ( Default : '!@#$%^&*()' )
  130. " Specify the markers that can be used by the plugin.
  131. " `b:SignatureIncludeMarkers` can be specified separately for buffer-specific settings
  132. "
  133. " ````
  134. " <Plug>SIG_NextMarkerByType : Jump to next line having same marker
  135. " <Plug>SIG_PrevMarkerByType : Jump to prev line having same marker
  136. " <Plug>SIG_PurgeMarkers : Remove all markers
  137. " ````
  138. "
  139. " * `g:SignaturePurgeConfirmation` ( Default: 0 )
  140. " An option for the more clumsy-fingered. Asks for confirmation before deleting all marks
  141. " * `g:SignatureDisableMenu` ( Default: 0 )
  142. " Hides the menu if set to 1
  143. "
  144. " * `g:SignatureMenuStruct` ( Default: "P&lugins.&Signature" )
  145. " Set where the menu options are to be displayed. For more details type,
  146. " ````
  147. " :h usr_42.txt
  148. " ````
  149. "
  150. "
  151. " Thanks To: {{{2
  152. " Restecp to (no, that's a reference and not a typo :P )
  153. " * Sergey Khorev for [mark-tools](http://www.vim.org/scripts/script.php?script_id=2929)
  154. " * Zak Johnson for [vim-showmarks](https://github.com/zakj/vim-showmarks)
  155. "
  156. " I feel obligated to mention that as some portions were coded so well by
  157. " them, I could think of no way to improve them and I've just used it as is.
  158. " Well, you know what they say... _"Good coders use; great coders reuse"_ ;)
  159. "
  160. "
  161. " ToDo: {{{2
  162. " * Add custom color support for signs
  163. " * Add support for non-Alphabetical marks
  164. "
  165. "
  166. " Maintainer: {{{2
  167. " Kartik Shenoy
  168. "
  169. " Changelist:
  170. " 2012-09-22:
  171. " - vim-signature is now initialised ( mappings, sign display etc. ) upon entering the buffer
  172. " - Checks buffer type before setting up vim-signature
  173. " ( in response to: https://github.com/kshenoy/vim-signature/issues/3 )
  174. " - SignatureToggle command now also removes all mappings
  175. "
  176. " 2012-08-15:
  177. " - Added option to ask for confirmation before deleting all marks
  178. "
  179. " 2012-07-23:
  180. " - Enabled non-default mappings for m, m<Space> and m<BS> which had been left out
  181. " - Display mark options in menu
  182. " - Modified marker navigation mappings to be consistent with others
  183. " in the use of [ and ] to go to the prev and next respectively
  184. "
  185. " 2012-07-05:
  186. " - Added support to toggle sign display
  187. " - Added support for buffer-specific settings
  188. "
  189. " 2012-06-30:
  190. " - Added support to change display style of marks
  191. " - Added support to remove all markers of a certain type
  192. " - Added support to display !@#$%^&*() as signs
  193. " - Added support to navigate markers
  194. " - Added support to display multiple marks
  195. "
  196. " 2012-06-22:
  197. " - First release
  198. "
  199. " vim: fdm=marker:et:ts=4:sw=2:sts=2 }}}1
  200. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  201. " Exit when app has already been loaded (or "compatible" mode set)
  202. if exists("g:loaded_Signature") || &cp
  203. finish
  204. endif
  205. let g:loaded_Signature = "1.3" " Version Number
  206. let s:save_cpo = &cpo
  207. set cpo&vim
  208. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  209. "" Global variables {{{1
  210. "
  211. if !exists('g:SignatureIncludeMarks')
  212. let g:SignatureIncludeMarks = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
  213. endif
  214. if !exists('g:SignatureIncludeMarkers')
  215. let g:SignatureIncludeMarkers = ")!@#$%^&*("
  216. endif
  217. if !exists('g:SignatureWrapJumps')
  218. let g:SignatureWrapJumps = 1
  219. endif
  220. if !exists('g:SignatureMarkLeader')
  221. let g:SignatureMarkLeader = "m"
  222. endif
  223. if !exists('g:SignatureMarkerLeader')
  224. let g:SignatureMarkerLeader = g:SignatureMarkLeader
  225. endif
  226. if !exists('g:SignatureDefaultMappings')
  227. let g:SignatureDefaultMappings = 1
  228. endif
  229. if !exists('g:SignatureLcMarkStr')
  230. let g:SignatureLcMarkStr = "\p\m"
  231. endif
  232. if !exists('g:SignatureUcMarkStr')
  233. let g:SignatureUcMarkStr = g:SignatureLcMarkStr
  234. endif
  235. if !exists('g:SignaturePurgeConfirmation')
  236. let g:SignaturePurgeConfirmation = 0
  237. endif
  238. if !exists('g:SignatureDisableMenu')
  239. let g:SignatureDisableMenu = 0
  240. endif
  241. if !exists('g:SignatureMenuStruct')
  242. let g:SignatureMenuStruct = 'P&lugin.&Signature'
  243. endif
  244. if !exists('g:SignaturePeriodicRefresh')
  245. let g:SignaturePeriodicRefresh = 1
  246. endif
  247. " }}}1
  248. call signature#Init()
  249. if has('autocmd')
  250. augroup sig_autocmds
  251. autocmd!
  252. autocmd FileType nerdtree call signature#BufferRefresh(1)
  253. autocmd BufEnter * call signature#BufferRefresh(1)
  254. autocmd CursorHold * if g:SignaturePeriodicRefresh | call signature#BufferRefresh(1) | endif
  255. augroup END
  256. endif
  257. command! -nargs=0 SignatureToggle call signature#BufferRefresh(0)
  258. command! -nargs=0 SignatureRefreshDisplay call signature#BufferRefresh(1)
  259. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  260. "" Create Menu {{{1
  261. "
  262. if !g:SignatureDisableMenu && has('gui_running')
  263. exec 'menu <silent> ' . g:SignatureMenuStruct . '.Pl&ace\ next\ mark<Tab>' . g:SignatureMarkLeader . ', :call signature#ToggleMark(",")<CR>'
  264. exec 'menu <silent> ' . g:SignatureMenuStruct . '.Re&move\ all\ marks\ \ \ \ <Tab>' . g:SignatureMarkLeader . '<Space> :call signature#PurgeMarks()<CR>'
  265. if hasmapto('<Plug>SIG_NextSpotByPos')
  266. exec 'menu <silent> ' . g:SignatureMenuStruct . '.Goto\ &next\ mark\ (pos)<Tab>' . signature#MapKey('<Plug>SIG_NextSpotByPos', 'n') . ' :call signature#GotoMark("pos", "next", "spot")'
  267. else
  268. exec 'menu <silent> ' . g:SignatureMenuStruct . '.Goto\ &next\ mark\ (pos) :call signature#GotoMark("pos", "next", "spot")'
  269. endif
  270. if hasmapto('<Plug>SIG_PrevSpotByPos')
  271. exec 'menu <silent> ' . g:SignatureMenuStruct . '.Goto\ p&rev\ mark\ (pos)<Tab>' . signature#MapKey('<Plug>SIG_PrevSpotByPos', 'n') . ' :call signature#GotoMark("pos", "prev", "spot")'
  272. else
  273. exec 'menu <silent> ' . g:SignatureMenuStruct . '.Goto\ p&rev\ mark\ (pos) :call signature#GotoMark("pos", "prev", "spot")'
  274. endif
  275. if hasmapto('<Plug>SIG_NextSpotByAlpha')
  276. exec 'menu <silent> ' . g:SignatureMenuStruct . '.Goto\ next\ mark\ (a&lpha)<Tab>' . signature#MapKey('<Plug>SIG_NextSpotByAlpha', 'n') . ' :call signature#GotoMark("alpha", "next", "spot")'
  277. else
  278. exec 'menu <silent> ' . g:SignatureMenuStruct . '.Goto\ next\ mark\ (a&lpha) :call signature#GotoMark("alpha", "next", "spot")'
  279. endif
  280. if hasmapto('<Plug>SIG_PrevSpotByAlpha')
  281. exec 'menu <silent> ' . g:SignatureMenuStruct . '.Goto\ prev\ mark\ (alp&ha)<Tab>' . signature#MapKey('<Plug>SIG_PrevSpotByAlpha', 'n') . ' :call signature#GotoMark("alpha", "prev", "spot")'
  282. else
  283. exec 'menu <silent> ' . g:SignatureMenuStruct . '.Goto\ prev\ mark\ (alp&ha)<Tab> :call signature#GotoMark("alpha", "prev", "spot")'
  284. endif
  285. exec 'amenu <silent> ' . g:SignatureMenuStruct . '.-s1- :'
  286. exec 'menu <silent> ' . g:SignatureMenuStruct . '.Rem&ove\ all\ markers<Tab>' . g:SignatureMarkerLeader . '<BS> :call signature#PurgeMarkers()<CR>'
  287. if hasmapto('<Plug>SIG_NextMarkerByType')
  288. exec 'menu <silent> ' . g:SignatureMenuStruct . '.Goto\ nex&t\ marker<Tab>' . signature#MapKey('<Plug>SIG_NextMarkerByType', 'n') . ' :call signature#GotoMarker("next")'
  289. else
  290. exec 'menu <silent> ' . g:SignatureMenuStruct . '.Goto\ nex&t\ marker :call signature#GotoMarker("next")'
  291. endif
  292. if hasmapto('<Plug>SIG_PrevMarkerByType')
  293. exec 'menu <silent> ' . g:SignatureMenuStruct . '.Goto\ pre&v\ marker<Tab>' . signature#MapKey('<Plug>SIG_PrevMarkerByType', 'n') . ' :call signature#GotoMarker("prev")'
  294. else
  295. exec 'menu <silent> ' . g:SignatureMenuStruct . '.Goto\ pre&v\ marker :call signature#GotoMarker("prev")'
  296. endif
  297. endif
  298. " }}}1
  299. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  300. let &cpo = s:save_cpo
  301. unlet s:save_cpo