ada.vim 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. "------------------------------------------------------------------------------
  2. " Description: Perform Ada specific completion & tagging.
  3. " Language: Ada (2005)
  4. " $Id: ada.vim 887 2008-07-08 14:29:01Z krischik $
  5. " Maintainer: Mathias Brousset <mathiasb17@gmail.com>
  6. " Martin Krischik <krischik@users.sourceforge.net>
  7. " Taylor Venable <taylor@metasyntax.net>
  8. " Neil Bird <neil@fnxweb.com>
  9. " Ned Okie <nokie@radford.edu>
  10. " $Author: krischik $
  11. " $Date: 2017-01-31 20:20:05 +0200 (Mon, 01 Jan 2017) $
  12. " Version: 4.6
  13. " $Revision: 887 $
  14. " $HeadURL: https://gnuada.svn.sourceforge.net/svnroot/gnuada/trunk/tools/vim/autoload/ada.vim $
  15. " History: 24.05.2006 MK Unified Headers
  16. " 26.05.2006 MK ' should not be in iskeyword.
  17. " 16.07.2006 MK Ada-Mode as vim-ball
  18. " 02.10.2006 MK Better folding.
  19. " 15.10.2006 MK Bram's suggestion for runtime integration
  20. " 05.11.2006 MK Bram suggested not to use include protection for
  21. " autoload
  22. " 05.11.2006 MK Bram suggested to save on spaces
  23. " 08.07.2007 TV fix mapleader problems.
  24. " 09.05.2007 MK Session just won't work no matter how much
  25. " tweaking is done
  26. " 19.09.2007 NO still some mapleader problems
  27. " 31.01.2017 MB fix more mapleader problems
  28. " Help Page: ft-ada-functions
  29. "------------------------------------------------------------------------------
  30. if version < 700
  31. finish
  32. endif
  33. let s:keepcpo= &cpo
  34. set cpo&vim
  35. " Section: Constants {{{1
  36. "
  37. let g:ada#DotWordRegex = '\a\w*\(\_s*\.\_s*\a\w*\)*'
  38. let g:ada#WordRegex = '\a\w*'
  39. let g:ada#Comment = "\\v^(\"[^\"]*\"|'.'|[^\"']){-}\\zs\\s*--.*"
  40. let g:ada#Keywords = []
  41. " Section: g:ada#Keywords {{{1
  42. "
  43. " Section: add Ada keywords {{{2
  44. "
  45. for Item in ['abort', 'else', 'new', 'return', 'abs', 'elsif', 'not', 'reverse', 'abstract', 'end', 'null', 'accept', 'entry', 'select', 'access', 'exception', 'of', 'separate', 'aliased', 'exit', 'or', 'subtype', 'all', 'others', 'synchronized', 'and', 'for', 'out', 'array', 'function', 'overriding', 'tagged', 'at', 'task', 'generic', 'package', 'terminate', 'begin', 'goto', 'pragma', 'then', 'body', 'private', 'type', 'if', 'procedure', 'case', 'in', 'protected', 'until', 'constant', 'interface', 'use', 'is', 'raise', 'declare', 'range', 'when', 'delay', 'limited', 'record', 'while', 'delta', 'loop', 'rem', 'with', 'digits', 'renames', 'do', 'mod', 'requeue', 'xor']
  46. let g:ada#Keywords += [{
  47. \ 'word': Item,
  48. \ 'menu': 'keyword',
  49. \ 'info': 'Ada keyword.',
  50. \ 'kind': 'k',
  51. \ 'icase': 1}]
  52. endfor
  53. " Section: GNAT Project Files {{{3
  54. "
  55. if exists ('g:ada_with_gnat_project_files')
  56. for Item in ['project']
  57. let g:ada#Keywords += [{
  58. \ 'word': Item,
  59. \ 'menu': 'keyword',
  60. \ 'info': 'GNAT projectfile keyword.',
  61. \ 'kind': 'k',
  62. \ 'icase': 1}]
  63. endfor
  64. endif
  65. " Section: add standard exception {{{2
  66. "
  67. for Item in ['Constraint_Error', 'Program_Error', 'Storage_Error', 'Tasking_Error', 'Status_Error', 'Mode_Error', 'Name_Error', 'Use_Error', 'Device_Error', 'End_Error', 'Data_Error', 'Layout_Error', 'Length_Error', 'Pattern_Error', 'Index_Error', 'Translation_Error', 'Time_Error', 'Argument_Error', 'Tag_Error', 'Picture_Error', 'Terminator_Error', 'Conversion_Error', 'Pointer_Error', 'Dereference_Error', 'Update_Error']
  68. let g:ada#Keywords += [{
  69. \ 'word': Item,
  70. \ 'menu': 'exception',
  71. \ 'info': 'Ada standard exception.',
  72. \ 'kind': 'x',
  73. \ 'icase': 1}]
  74. endfor
  75. " Section: add GNAT exception {{{3
  76. "
  77. if exists ('g:ada_gnat_extensions')
  78. for Item in ['Assert_Failure']
  79. let g:ada#Keywords += [{
  80. \ 'word': Item,
  81. \ 'menu': 'exception',
  82. \ 'info': 'GNAT exception.',
  83. \ 'kind': 'x',
  84. \ 'icase': 1}]
  85. endfor
  86. endif
  87. " Section: add Ada buildin types {{{2
  88. "
  89. for Item in ['Boolean', 'Integer', 'Natural', 'Positive', 'Float', 'Character', 'Wide_Character', 'Wide_Wide_Character', 'String', 'Wide_String', 'Wide_Wide_String', 'Duration']
  90. let g:ada#Keywords += [{
  91. \ 'word': Item,
  92. \ 'menu': 'type',
  93. \ 'info': 'Ada buildin type.',
  94. \ 'kind': 't',
  95. \ 'icase': 1}]
  96. endfor
  97. " Section: add GNAT buildin types {{{3
  98. "
  99. if exists ('g:ada_gnat_extensions')
  100. for Item in ['Short_Integer', 'Short_Short_Integer', 'Long_Integer', 'Long_Long_Integer', 'Short_Float', 'Short_Short_Float', 'Long_Float', 'Long_Long_Float']
  101. let g:ada#Keywords += [{
  102. \ 'word': Item,
  103. \ 'menu': 'type',
  104. \ 'info': 'GNAT buildin type.',
  105. \ 'kind': 't',
  106. \ 'icase': 1}]
  107. endfor
  108. endif
  109. " Section: add Ada Attributes {{{2
  110. "
  111. for Item in ['''Access', '''Address', '''Adjacent', '''Aft', '''Alignment', '''Base', '''Bit_Order', '''Body_Version', '''Callable', '''Caller', '''Ceiling', '''Class', '''Component_Size', '''Compose', '''Constrained', '''Copy_Sign', '''Count', '''Definite', '''Delta', '''Denorm', '''Digits', '''Emax', '''Exponent', '''External_Tag', '''Epsilon', '''First', '''First_Bit', '''Floor', '''Fore', '''Fraction', '''Identity', '''Image', '''Input', '''Large', '''Last', '''Last_Bit', '''Leading_Part', '''Length', '''Machine', '''Machine_Emax', '''Machine_Emin', '''Machine_Mantissa', '''Machine_Overflows', '''Machine_Radix', '''Machine_Rounding', '''Machine_Rounds', '''Mantissa', '''Max', '''Max_Size_In_Storage_Elements', '''Min', '''Mod', '''Model', '''Model_Emin', '''Model_Epsilon', '''Model_Mantissa', '''Model_Small', '''Modulus', '''Output', '''Partition_ID', '''Pos', '''Position', '''Pred', '''Priority', '''Range', '''Read', '''Remainder', '''Round', '''Rounding', '''Safe_Emax', '''Safe_First', '''Safe_Large', '''Safe_Last', '''Safe_Small', '''Scale', '''Scaling', '''Signed_Zeros', '''Size', '''Small', '''Storage_Pool', '''Storage_Size', '''Stream_Size', '''Succ', '''Tag', '''Terminated', '''Truncation', '''Unbiased_Rounding', '''Unchecked_Access', '''Val', '''Valid', '''Value', '''Version', '''Wide_Image', '''Wide_Value', '''Wide_Wide_Image', '''Wide_Wide_Value', '''Wide_Wide_Width', '''Wide_Width', '''Width', '''Write']
  112. let g:ada#Keywords += [{
  113. \ 'word': Item,
  114. \ 'menu': 'attribute',
  115. \ 'info': 'Ada attribute.',
  116. \ 'kind': 'a',
  117. \ 'icase': 1}]
  118. endfor
  119. " Section: add GNAT Attributes {{{3
  120. "
  121. if exists ('g:ada_gnat_extensions')
  122. for Item in ['''Abort_Signal', '''Address_Size', '''Asm_Input', '''Asm_Output', '''AST_Entry', '''Bit', '''Bit_Position', '''Code_Address', '''Default_Bit_Order', '''Elaborated', '''Elab_Body', '''Elab_Spec', '''Emax', '''Enum_Rep', '''Epsilon', '''Fixed_Value', '''Has_Access_Values', '''Has_Discriminants', '''Img', '''Integer_Value', '''Machine_Size', '''Max_Interrupt_Priority', '''Max_Priority', '''Maximum_Alignment', '''Mechanism_Code', '''Null_Parameter', '''Object_Size', '''Passed_By_Reference', '''Range_Length', '''Storage_Unit', '''Target_Name', '''Tick', '''To_Address', '''Type_Class', '''UET_Address', '''Unconstrained_Array', '''Universal_Literal_String', '''Unrestricted_Access', '''VADS_Size', '''Value_Size', '''Wchar_T_Size', '''Word_Size']
  123. let g:ada#Keywords += [{
  124. \ 'word': Item,
  125. \ 'menu': 'attribute',
  126. \ 'info': 'GNAT attribute.',
  127. \ 'kind': 'a',
  128. \ 'icase': 1}]
  129. endfor
  130. endif
  131. " Section: add Ada Pragmas {{{2
  132. "
  133. for Item in ['All_Calls_Remote', 'Assert', 'Assertion_Policy', 'Asynchronous', 'Atomic', 'Atomic_Components', 'Attach_Handler', 'Controlled', 'Convention', 'Detect_Blocking', 'Discard_Names', 'Elaborate', 'Elaborate_All', 'Elaborate_Body', 'Export', 'Import', 'Inline', 'Inspection_Point', 'Interface (Obsolescent)', 'Interrupt_Handler', 'Interrupt_Priority', 'Linker_Options', 'List', 'Locking_Policy', 'Memory_Size (Obsolescent)', 'No_Return', 'Normalize_Scalars', 'Optimize', 'Pack', 'Page', 'Partition_Elaboration_Policy', 'Preelaborable_Initialization', 'Preelaborate', 'Priority', 'Priority_Specific_Dispatching', 'Profile', 'Pure', 'Queueing_Policy', 'Relative_Deadline', 'Remote_Call_Interface', 'Remote_Types', 'Restrictions', 'Reviewable', 'Shared (Obsolescent)', 'Shared_Passive', 'Storage_Size', 'Storage_Unit (Obsolescent)', 'Suppress', 'System_Name (Obsolescent)', 'Task_Dispatching_Policy', 'Unchecked_Union', 'Unsuppress', 'Volatile', 'Volatile_Components']
  134. let g:ada#Keywords += [{
  135. \ 'word': Item,
  136. \ 'menu': 'pragma',
  137. \ 'info': 'Ada pragma.',
  138. \ 'kind': 'p',
  139. \ 'icase': 1}]
  140. endfor
  141. " Section: add GNAT Pragmas {{{3
  142. "
  143. if exists ('g:ada_gnat_extensions')
  144. for Item in ['Abort_Defer', 'Ada_83', 'Ada_95', 'Ada_05', 'Annotate', 'Ast_Entry', 'C_Pass_By_Copy', 'Comment', 'Common_Object', 'Compile_Time_Warning', 'Complex_Representation', 'Component_Alignment', 'Convention_Identifier', 'CPP_Class', 'CPP_Constructor', 'CPP_Virtual', 'CPP_Vtable', 'Debug', 'Elaboration_Checks', 'Eliminate', 'Export_Exception', 'Export_Function', 'Export_Object', 'Export_Procedure', 'Export_Value', 'Export_Valued_Procedure', 'Extend_System', 'External', 'External_Name_Casing', 'Finalize_Storage_Only', 'Float_Representation', 'Ident', 'Import_Exception', 'Import_Function', 'Import_Object', 'Import_Procedure', 'Import_Valued_Procedure', 'Initialize_Scalars', 'Inline_Always', 'Inline_Generic', 'Interface_Name', 'Interrupt_State', 'Keep_Names', 'License', 'Link_With', 'Linker_Alias', 'Linker_Section', 'Long_Float', 'Machine_Attribute', 'Main_Storage', 'Obsolescent', 'Passive', 'Polling', 'Profile_Warnings', 'Propagate_Exceptions', 'Psect_Object', 'Pure_Function', 'Restriction_Warnings', 'Source_File_Name', 'Source_File_Name_Project', 'Source_Reference', 'Stream_Convert', 'Style_Checks', 'Subtitle', 'Suppress_All', 'Suppress_Exception_Locations', 'Suppress_Initialization', 'Task_Info', 'Task_Name', 'Task_Storage', 'Thread_Body', 'Time_Slice', 'Title', 'Unimplemented_Unit', 'Universal_Data', 'Unreferenced', 'Unreserve_All_Interrupts', 'Use_VADS_Size', 'Validity_Checks', 'Warnings', 'Weak_External']
  145. let g:ada#Keywords += [{
  146. \ 'word': Item,
  147. \ 'menu': 'pragma',
  148. \ 'info': 'GNAT pragma.',
  149. \ 'kind': 'p',
  150. \ 'icase': 1}]
  151. endfor
  152. endif
  153. " 1}}}
  154. " Section: g:ada#Ctags_Kinds {{{1
  155. "
  156. let g:ada#Ctags_Kinds = {
  157. \ 'P': ["packspec", "package specifications"],
  158. \ 'p': ["package", "packages"],
  159. \ 'T': ["typespec", "type specifications"],
  160. \ 't': ["type", "types"],
  161. \ 'U': ["subspec", "subtype specifications"],
  162. \ 'u': ["subtype", "subtypes"],
  163. \ 'c': ["component", "record type components"],
  164. \ 'l': ["literal", "enum type literals"],
  165. \ 'V': ["varspec", "variable specifications"],
  166. \ 'v': ["variable", "variables"],
  167. \ 'f': ["formal", "generic formal parameters"],
  168. \ 'n': ["constant", "constants"],
  169. \ 'x': ["exception", "user defined exceptions"],
  170. \ 'R': ["subprogspec", "subprogram specifications"],
  171. \ 'r': ["subprogram", "subprograms"],
  172. \ 'K': ["taskspec", "task specifications"],
  173. \ 'k': ["task", "tasks"],
  174. \ 'O': ["protectspec", "protected data specifications"],
  175. \ 'o': ["protected", "protected data"],
  176. \ 'E': ["entryspec", "task/protected data entry specifications"],
  177. \ 'e': ["entry", "task/protected data entries"],
  178. \ 'b': ["label", "labels"],
  179. \ 'i': ["identifier", "loop/declare identifiers"],
  180. \ 'a': ["autovar", "automatic variables"],
  181. \ 'y': ["annon", "loops and blocks with no identifier"]}
  182. " Section: ada#Word (...) {{{1
  183. "
  184. " Extract current Ada word across multiple lines
  185. " AdaWord ([line, column])\
  186. "
  187. function ada#Word (...)
  188. if a:0 > 1
  189. let l:Line_Nr = a:1
  190. let l:Column_Nr = a:2 - 1
  191. else
  192. let l:Line_Nr = line('.')
  193. let l:Column_Nr = col('.') - 1
  194. endif
  195. let l:Line = substitute (getline (l:Line_Nr), g:ada#Comment, '', '' )
  196. " Cope with tag searching for items in comments; if we are, don't loop
  197. " backwards looking for previous lines
  198. if l:Column_Nr > strlen(l:Line)
  199. " We were in a comment
  200. let l:Line = getline(l:Line_Nr)
  201. let l:Search_Prev_Lines = 0
  202. else
  203. let l:Search_Prev_Lines = 1
  204. endif
  205. " Go backwards until we find a match (Ada ID) that *doesn't* include our
  206. " location - i.e., the previous ID. This is because the current 'correct'
  207. " match will toggle matching/not matching as we traverse characters
  208. " backwards. Thus, we have to find the previous unrelated match, exclude
  209. " it, then use the next full match (ours).
  210. " Remember to convert vim column 'l:Column_Nr' [1..n] to string offset [0..(n-1)]
  211. " ... but start, here, one after the required char.
  212. let l:New_Column = l:Column_Nr + 1
  213. while 1
  214. let l:New_Column = l:New_Column - 1
  215. if l:New_Column < 0
  216. " Have to include previous l:Line from file
  217. let l:Line_Nr = l:Line_Nr - 1
  218. if l:Line_Nr < 1 || !l:Search_Prev_Lines
  219. " Start of file or matching in a comment
  220. let l:Line_Nr = 1
  221. let l:New_Column = 0
  222. let l:Our_Match = match (l:Line, g:ada#WordRegex )
  223. break
  224. endif
  225. " Get previous l:Line, and prepend it to our search string
  226. let l:New_Line = substitute (getline (l:Line_Nr), g:ada#Comment, '', '' )
  227. let l:New_Column = strlen (l:New_Line) - 1
  228. let l:Column_Nr = l:Column_Nr + l:New_Column
  229. let l:Line = l:New_Line . l:Line
  230. endif
  231. " Check to see if this is a match excluding 'us'
  232. let l:Match_End = l:New_Column +
  233. \ matchend (strpart (l:Line,l:New_Column), g:ada#WordRegex ) - 1
  234. if l:Match_End >= l:New_Column &&
  235. \ l:Match_End < l:Column_Nr
  236. " Yes
  237. let l:Our_Match = l:Match_End+1 +
  238. \ match (strpart (l:Line,l:Match_End+1), g:ada#WordRegex )
  239. break
  240. endif
  241. endwhile
  242. " Got anything?
  243. if l:Our_Match < 0
  244. return ''
  245. else
  246. let l:Line = strpart (l:Line, l:Our_Match)
  247. endif
  248. " Now simply add further lines until the match gets no bigger
  249. let l:Match_String = matchstr (l:Line, g:ada#WordRegex)
  250. let l:Last_Line = line ('$')
  251. let l:Line_Nr = line ('.') + 1
  252. while l:Line_Nr <= l:Last_Line
  253. let l:Last_Match = l:Match_String
  254. let l:Line = l:Line .
  255. \ substitute (getline (l:Line_Nr), g:ada#Comment, '', '')
  256. let l:Match_String = matchstr (l:Line, g:ada#WordRegex)
  257. if l:Match_String == l:Last_Match
  258. break
  259. endif
  260. endwhile
  261. " Strip whitespace & return
  262. return substitute (l:Match_String, '\s\+', '', 'g')
  263. endfunction ada#Word
  264. " Section: ada#List_Tag (...) {{{1
  265. "
  266. " List tags in quickfix window
  267. "
  268. function ada#List_Tag (...)
  269. if a:0 > 1
  270. let l:Tag_Word = ada#Word (a:1, a:2)
  271. elseif a:0 > 0
  272. let l:Tag_Word = a:1
  273. else
  274. let l:Tag_Word = ada#Word ()
  275. endif
  276. echo "Searching for" l:Tag_Word
  277. let l:Pattern = '^' . l:Tag_Word . '$'
  278. let l:Tag_List = taglist (l:Pattern)
  279. let l:Error_List = []
  280. "
  281. " add symbols
  282. "
  283. for Tag_Item in l:Tag_List
  284. if l:Tag_Item['kind'] == ''
  285. let l:Tag_Item['kind'] = 's'
  286. endif
  287. let l:Error_List += [
  288. \ l:Tag_Item['filename'] . '|' .
  289. \ l:Tag_Item['cmd'] . '|' .
  290. \ l:Tag_Item['kind'] . "\t" .
  291. \ l:Tag_Item['name'] ]
  292. endfor
  293. set errorformat=%f\|%l\|%m
  294. cexpr l:Error_List
  295. cwindow
  296. endfunction ada#List_Tag
  297. " Section: ada#Jump_Tag (Word, Mode) {{{1
  298. "
  299. " Word tag - include '.' and if Ada make uppercase
  300. "
  301. function ada#Jump_Tag (Word, Mode)
  302. if a:Word == ''
  303. " Get current word
  304. let l:Word = ada#Word()
  305. if l:Word == ''
  306. throw "NOT_FOUND: no identifier found."
  307. endif
  308. else
  309. let l:Word = a:Word
  310. endif
  311. echo "Searching for " . l:Word
  312. try
  313. execute a:Mode l:Word
  314. catch /.*:E426:.*/
  315. let ignorecase = &ignorecase
  316. set ignorecase
  317. execute a:Mode l:Word
  318. let &ignorecase = ignorecase
  319. endtry
  320. return
  321. endfunction ada#Jump_Tag
  322. " Section: ada#Insert_Backspace () {{{1
  323. "
  324. " Backspace at end of line after auto-inserted commentstring '-- ' wipes it
  325. "
  326. function ada#Insert_Backspace ()
  327. let l:Line = getline ('.')
  328. if col ('.') > strlen (l:Line) &&
  329. \ match (l:Line, '-- $') != -1 &&
  330. \ match (&comments,'--') != -1
  331. return "\<bs>\<bs>\<bs>"
  332. else
  333. return "\<bs>"
  334. endif
  335. return
  336. endfunction ada#InsertBackspace
  337. " Section: Insert Completions {{{1
  338. "
  339. " Section: ada#User_Complete(findstart, base) {{{2
  340. "
  341. " This function is used for the 'complete' option.
  342. "
  343. function! ada#User_Complete(findstart, base)
  344. if a:findstart == 1
  345. "
  346. " locate the start of the word
  347. "
  348. let line = getline ('.')
  349. let start = col ('.') - 1
  350. while start > 0 && line[start - 1] =~ '\i\|'''
  351. let start -= 1
  352. endwhile
  353. return start
  354. else
  355. "
  356. " look up matches
  357. "
  358. let l:Pattern = '^' . a:base . '.*$'
  359. "
  360. " add keywords
  361. "
  362. for Tag_Item in g:ada#Keywords
  363. if l:Tag_Item['word'] =~? l:Pattern
  364. if complete_add (l:Tag_Item) == 0
  365. return []
  366. endif
  367. if complete_check ()
  368. return []
  369. endif
  370. endif
  371. endfor
  372. return []
  373. endif
  374. endfunction ada#User_Complete
  375. " Section: ada#Completion (cmd) {{{2
  376. "
  377. " Word completion (^N/^R/^X^]) - force '.' inclusion
  378. function ada#Completion (cmd)
  379. set iskeyword+=46
  380. return a:cmd . "\<C-R>=ada#Completion_End ()\<CR>"
  381. endfunction ada#Completion
  382. " Section: ada#Completion_End () {{{2
  383. "
  384. function ada#Completion_End ()
  385. set iskeyword-=46
  386. return ''
  387. endfunction ada#Completion_End
  388. " Section: ada#Create_Tags {{{1
  389. "
  390. function ada#Create_Tags (option)
  391. if a:option == 'file'
  392. let l:Filename = fnamemodify (bufname ('%'), ':p')
  393. elseif a:option == 'dir'
  394. let l:Filename =
  395. \ fnamemodify (bufname ('%'), ':p:h') . "*.ada " .
  396. \ fnamemodify (bufname ('%'), ':p:h') . "*.adb " .
  397. \ fnamemodify (bufname ('%'), ':p:h') . "*.ads"
  398. else
  399. let l:Filename = a:option
  400. endif
  401. execute '!ctags --excmd=number ' . l:Filename
  402. endfunction ada#Create_Tags
  403. " Section: ada#Switch_Session {{{1
  404. "
  405. function ada#Switch_Session (New_Session)
  406. "
  407. " you should not save to much date into the seession since they will
  408. " be sourced
  409. "
  410. let l:sessionoptions=&sessionoptions
  411. try
  412. set sessionoptions=buffers,curdir,folds,globals,resize,slash,tabpages,tabpages,unix,winpos,winsize
  413. if a:New_Session != v:this_session
  414. "
  415. " We actually got a new session - otherwise there
  416. " is nothing to do.
  417. "
  418. if strlen (v:this_session) > 0
  419. execute 'mksession! ' . v:this_session
  420. endif
  421. let v:this_session = a:New_Session
  422. "if filereadable (v:this_session)
  423. "execute 'source ' . v:this_session
  424. "endif
  425. augroup ada_session
  426. autocmd!
  427. autocmd VimLeavePre * execute 'mksession! ' . v:this_session
  428. augroup END
  429. "if exists ("g:Tlist_Auto_Open") && g:Tlist_Auto_Open
  430. "TlistOpen
  431. "endif
  432. endif
  433. finally
  434. let &sessionoptions=l:sessionoptions
  435. endtry
  436. return
  437. endfunction ada#Switch_Session
  438. " Section: GNAT Pretty Printer folding {{{1
  439. "
  440. if exists('g:ada_folding') && g:ada_folding[0] == 'g'
  441. "
  442. " Lines consisting only of ')' ';' are due to a gnat pretty bug and
  443. " have the same level as the line above (can't happen in the first
  444. " line).
  445. "
  446. let s:Fold_Collate = '^\([;)]*$\|'
  447. "
  448. " some lone statements are folded with the line above
  449. "
  450. if stridx (g:ada_folding, 'i') >= 0
  451. let s:Fold_Collate .= '\s\+\<is\>$\|'
  452. endif
  453. if stridx (g:ada_folding, 'b') >= 0
  454. let s:Fold_Collate .= '\s\+\<begin\>$\|'
  455. endif
  456. if stridx (g:ada_folding, 'p') >= 0
  457. let s:Fold_Collate .= '\s\+\<private\>$\|'
  458. endif
  459. if stridx (g:ada_folding, 'x') >= 0
  460. let s:Fold_Collate .= '\s\+\<exception\>$\|'
  461. endif
  462. " We also handle empty lines and
  463. " comments here.
  464. let s:Fold_Collate .= '--\)'
  465. function ada#Pretty_Print_Folding (Line) " {{{2
  466. let l:Text = getline (a:Line)
  467. if l:Text =~ s:Fold_Collate
  468. "
  469. " fold with line above
  470. "
  471. let l:Level = "="
  472. elseif l:Text =~ '^\s\+('
  473. "
  474. " gnat outdents a line which stards with a ( by one characters so
  475. " that parameters which follow are aligned.
  476. "
  477. let l:Level = (indent (a:Line) + 1) / &shiftwidth
  478. else
  479. let l:Level = indent (a:Line) / &shiftwidth
  480. endif
  481. return l:Level
  482. endfunction ada#Pretty_Print_Folding " }}}2
  483. endif
  484. " Section: Options and Menus {{{1
  485. "
  486. " Section: ada#Switch_Syntax_Options {{{2
  487. "
  488. function ada#Switch_Syntax_Option (option)
  489. syntax off
  490. if exists ('g:ada_' . a:option)
  491. unlet g:ada_{a:option}
  492. echo a:option . 'now off'
  493. else
  494. let g:ada_{a:option}=1
  495. echo a:option . 'now on'
  496. endif
  497. syntax on
  498. endfunction ada#Switch_Syntax_Option
  499. " Section: ada#Map_Menu {{{2
  500. "
  501. function ada#Map_Menu (Text, Keys, Command)
  502. if a:Keys[0] == ':'
  503. execute
  504. \ "50amenu " .
  505. \ "Ada." . escape(a:Text, ' ') .
  506. \ "<Tab>" . a:Keys .
  507. \ " :" . a:Command . "<CR>"
  508. execute
  509. \ "command -buffer " .
  510. \ a:Keys[1:] .
  511. \" :" . a:Command . "<CR>"
  512. elseif a:Keys[0] == '<'
  513. execute
  514. \ "50amenu " .
  515. \ "Ada." . escape(a:Text, ' ') .
  516. \ "<Tab>" . a:Keys .
  517. \ " :" . a:Command . "<CR>"
  518. execute
  519. \ "nnoremap <buffer> " .
  520. \ a:Keys .
  521. \" :" . a:Command . "<CR>"
  522. execute
  523. \ "inoremap <buffer> " .
  524. \ a:Keys .
  525. \" <C-O>:" . a:Command . "<CR>"
  526. else
  527. if exists("g:mapleader")
  528. let l:leader = g:mapleader
  529. else
  530. let l:leader = '\'
  531. endif
  532. execute
  533. \ "50amenu " .
  534. \ "Ada." . escape(a:Text, ' ') .
  535. \ "<Tab>" . escape(l:leader . "a" . a:Keys , '\') .
  536. \ " :" . a:Command . "<CR>"
  537. execute
  538. \ "nnoremap <buffer>" .
  539. \ " <Leader>a" . a:Keys .
  540. \" :" . a:Command
  541. execute
  542. \ "inoremap <buffer>" .
  543. \ " <Leader>a" . a:Keys .
  544. \" <C-O>:" . a:Command
  545. endif
  546. return
  547. endfunction
  548. " Section: ada#Map_Popup {{{2
  549. "
  550. function ada#Map_Popup (Text, Keys, Command)
  551. if exists("g:mapleader")
  552. let l:leader = g:mapleader
  553. else
  554. let l:leader = '\'
  555. endif
  556. execute
  557. \ "50amenu " .
  558. \ "PopUp." . escape(a:Text, ' ') .
  559. \ "<Tab>" . escape(l:leader . "a" . a:Keys , '\') .
  560. \ " :" . a:Command . "<CR>"
  561. call ada#Map_Menu (a:Text, a:Keys, a:Command)
  562. return
  563. endfunction ada#Map_Popup
  564. " }}}1
  565. lockvar g:ada#WordRegex
  566. lockvar g:ada#DotWordRegex
  567. lockvar g:ada#Comment
  568. lockvar! g:ada#Keywords
  569. lockvar! g:ada#Ctags_Kinds
  570. let &cpo = s:keepcpo
  571. unlet s:keepcpo
  572. finish " 1}}}
  573. "------------------------------------------------------------------------------
  574. " Copyright (C) 2006 Martin Krischik
  575. "
  576. " Vim is Charityware - see ":help license" or uganda.txt for licence details.
  577. "------------------------------------------------------------------------------
  578. " vim: textwidth=78 wrap tabstop=8 shiftwidth=3 softtabstop=3 noexpandtab
  579. " vim: foldmethod=marker