robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:3fa4da4: runtime: add missing fnameescape()/shellescape() in a few runtime files (#40486)d3509eac6a

master
22.1 KiB639 linesraw
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"		29.06.2026 Vim add fnameescpe/shellescape
29"    Help Page: ft-ada-functions
30"------------------------------------------------------------------------------
31
32if version < 700
33   finish
34endif 
35let s:keepcpo= &cpo
36set cpo&vim
37
38" Section: Constants {{{1
39"
40let g:ada#DotWordRegex	   = '\a\w*\(\_s*\.\_s*\a\w*\)*'
41let g:ada#WordRegex	   = '\a\w*'
42let g:ada#Comment	   = "\\v^(\"[^\"]*\"|'.'|[^\"']){-}\\zs\\s*--.*"
43let g:ada#Keywords	   = []
44
45" Section: g:ada#Keywords {{{1
46"
47" Section: add Ada keywords {{{2
48"
49for 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']
50    let g:ada#Keywords += [{
51	    \ 'word':  Item,
52	    \ 'menu':  'keyword',
53	    \ 'info':  'Ada keyword.',
54	    \ 'kind':  'k',
55	    \ 'icase': 1}]
56endfor
57
58" Section: GNAT Project Files {{{3
59"
60if exists ('g:ada_with_gnat_project_files')
61    for Item in ['project']
62       let g:ada#Keywords += [{
63	       \ 'word':  Item,
64	       \ 'menu':  'keyword',
65	       \ 'info':  'GNAT projectfile keyword.',
66	       \ 'kind':  'k',
67	       \ 'icase': 1}]
68    endfor
69endif
70
71" Section: add	standard exception {{{2
72"
73for 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']
74    let g:ada#Keywords += [{
75	    \ 'word':  Item,
76	    \ 'menu':  'exception',
77	    \ 'info':  'Ada standard exception.',
78	    \ 'kind':  'x',
79	    \ 'icase': 1}]
80endfor
81
82" Section: add	GNAT exception {{{3
83"
84if exists ('g:ada_gnat_extensions')
85    for Item in ['Assert_Failure']
86	let g:ada#Keywords += [{
87		\ 'word':  Item,
88		\ 'menu':  'exception',
89		\ 'info':  'GNAT exception.',
90		\ 'kind':  'x',
91		\ 'icase': 1}]
92    endfor
93endif
94
95" Section: add Ada buildin types {{{2
96"
97for Item in ['Boolean', 'Integer', 'Natural', 'Positive', 'Float', 'Character', 'Wide_Character', 'Wide_Wide_Character', 'String', 'Wide_String', 'Wide_Wide_String', 'Duration']
98    let g:ada#Keywords += [{
99	    \ 'word':  Item,
100	    \ 'menu':  'type',
101	    \ 'info':  'Ada buildin type.',
102	    \ 'kind':  't',
103	    \ 'icase': 1}]
104endfor
105
106" Section: add GNAT buildin types {{{3
107"
108if exists ('g:ada_gnat_extensions')
109    for Item in ['Short_Integer', 'Short_Short_Integer', 'Long_Integer', 'Long_Long_Integer', 'Short_Float', 'Short_Short_Float', 'Long_Float', 'Long_Long_Float']
110	let g:ada#Keywords += [{
111		\ 'word':  Item,
112		\ 'menu':  'type',
113		\ 'info':  'GNAT buildin type.',
114		\ 'kind':  't',
115		\ 'icase': 1}]
116    endfor
117endif
118
119" Section: add Ada Attributes {{{2
120"
121for 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']
122    let g:ada#Keywords += [{
123	    \ 'word':  Item,
124	    \ 'menu':  'attribute',
125	    \ 'info':  'Ada attribute.',
126	    \ 'kind':  'a',
127	    \ 'icase': 1}]
128endfor
129
130" Section: add GNAT Attributes {{{3
131"
132if exists ('g:ada_gnat_extensions')
133    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']
134    let g:ada#Keywords += [{
135	    \ 'word':  Item,
136	    \ 'menu':  'attribute',
137	    \ 'info':  'GNAT attribute.',
138	    \ 'kind':  'a',
139	    \ 'icase': 1}]
140    endfor
141endif
142
143" Section: add Ada Pragmas {{{2
144"
145for 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']
146    let g:ada#Keywords += [{
147	    \ 'word':  Item,
148	    \ 'menu':  'pragma',
149	    \ 'info':  'Ada pragma.',
150	    \ 'kind':  'p',
151	    \ 'icase': 1}]
152endfor
153
154" Section: add GNAT Pragmas {{{3
155"
156if exists ('g:ada_gnat_extensions')
157    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']
158	let g:ada#Keywords += [{
159		\ 'word':  Item,
160		\ 'menu':  'pragma',
161		\ 'info':  'GNAT pragma.',
162		\ 'kind':  'p',
163		\ 'icase': 1}]
164    endfor
165endif
166" 1}}}
167
168" Section: g:ada#Ctags_Kinds {{{1
169"
170let g:ada#Ctags_Kinds = {
171   \ 'P': ["packspec",	  "package specifications"],
172   \ 'p': ["package",	  "packages"],
173   \ 'T': ["typespec",	  "type specifications"],
174   \ 't': ["type",	  "types"],
175   \ 'U': ["subspec",	  "subtype specifications"],
176   \ 'u': ["subtype",	  "subtypes"],
177   \ 'c': ["component",   "record type components"],
178   \ 'l': ["literal",	  "enum type literals"],
179   \ 'V': ["varspec",	  "variable specifications"],
180   \ 'v': ["variable",	  "variables"],
181   \ 'f': ["formal",	  "generic formal parameters"],
182   \ 'n': ["constant",	  "constants"],
183   \ 'x': ["exception",   "user defined exceptions"],
184   \ 'R': ["subprogspec", "subprogram specifications"],
185   \ 'r': ["subprogram",  "subprograms"],
186   \ 'K': ["taskspec",	  "task specifications"],
187   \ 'k': ["task",	  "tasks"],
188   \ 'O': ["protectspec", "protected data specifications"],
189   \ 'o': ["protected",   "protected data"],
190   \ 'E': ["entryspec",   "task/protected data entry specifications"],
191   \ 'e': ["entry",	  "task/protected data entries"],
192   \ 'b': ["label",	  "labels"],
193   \ 'i': ["identifier",  "loop/declare identifiers"],
194   \ 'a': ["autovar",	  "automatic variables"],
195   \ 'y': ["annon",	  "loops and blocks with no identifier"]}
196
197" Section: ada#Word (...) {{{1
198"
199" Extract current Ada word across multiple lines
200" AdaWord ([line, column])\
201"
202function ada#Word (...)
203   if a:0 > 1
204      let l:Line_Nr    = a:1
205      let l:Column_Nr  = a:2 - 1
206   else
207      let l:Line_Nr    = line('.')
208      let l:Column_Nr  = col('.') - 1
209   endif
210
211   let l:Line = substitute (getline (l:Line_Nr), g:ada#Comment, '', '' )
212
213   " Cope with tag searching for items in comments; if we are, don't loop
214   " backwards looking for previous lines
215   if l:Column_Nr > strlen(l:Line)
216      " We were in a comment
217      let l:Line = getline(l:Line_Nr)
218      let l:Search_Prev_Lines = 0
219   else
220      let l:Search_Prev_Lines = 1
221   endif
222
223   " Go backwards until we find a match (Ada ID) that *doesn't* include our
224   " location - i.e., the previous ID. This is because the current 'correct'
225   " match will toggle matching/not matching as we traverse characters
226   " backwards. Thus, we have to find the previous unrelated match, exclude
227   " it, then use the next full match (ours).
228   " Remember to convert vim column 'l:Column_Nr' [1..n] to string offset [0..(n-1)]
229   " ... but start, here, one after the required char.
230   let l:New_Column = l:Column_Nr + 1
231   while 1
232      let l:New_Column = l:New_Column - 1
233      if l:New_Column < 0
234	 " Have to include previous l:Line from file
235	 let l:Line_Nr = l:Line_Nr - 1
236	 if l:Line_Nr < 1  ||  !l:Search_Prev_Lines
237	    " Start of file or matching in a comment
238	    let l:Line_Nr     = 1
239	    let l:New_Column  = 0
240	    let l:Our_Match   = match (l:Line, g:ada#WordRegex )
241	    break
242	 endif
243	 " Get previous l:Line, and prepend it to our search string
244	 let l:New_Line    = substitute (getline (l:Line_Nr), g:ada#Comment, '', '' )
245	 let l:New_Column  = strlen (l:New_Line) - 1
246	 let l:Column_Nr   = l:Column_Nr + l:New_Column
247	 let l:Line	   = l:New_Line . l:Line
248      endif
249      " Check to see if this is a match excluding 'us'
250      let l:Match_End = l:New_Column +
251		      \ matchend (strpart (l:Line,l:New_Column), g:ada#WordRegex ) - 1
252      if l:Match_End >= l:New_Column  &&
253       \ l:Match_End < l:Column_Nr
254	 " Yes
255	 let l:Our_Match = l:Match_End+1 +
256			 \ match (strpart (l:Line,l:Match_End+1), g:ada#WordRegex )
257	 break
258      endif
259   endwhile
260
261   " Got anything?
262   if l:Our_Match < 0
263      return ''
264   else
265      let l:Line = strpart (l:Line, l:Our_Match)
266   endif
267
268   " Now simply add further lines until the match gets no bigger
269   let l:Match_String = matchstr (l:Line, g:ada#WordRegex)
270   let l:Last_Line    = line ('$')
271   let l:Line_Nr      = line ('.') + 1
272   while l:Line_Nr <= l:Last_Line
273      let l:Last_Match = l:Match_String
274      let l:Line = l:Line .
275	 \ substitute (getline (l:Line_Nr), g:ada#Comment, '', '')
276      let l:Match_String = matchstr (l:Line, g:ada#WordRegex)
277      if l:Match_String == l:Last_Match
278	 break
279      endif
280   endwhile
281
282   " Strip whitespace & return
283   return substitute (l:Match_String, '\s\+', '', 'g')
284endfunction ada#Word
285
286" Section: ada#List_Tag (...) {{{1
287"
288"  List tags in quickfix window
289"
290function ada#List_Tag (...)
291   if a:0 > 1
292      let l:Tag_Word = ada#Word (a:1, a:2)
293   elseif a:0 > 0
294      let l:Tag_Word = a:1
295   else
296      let l:Tag_Word = ada#Word ()
297   endif
298
299   echo "Searching for" l:Tag_Word
300
301   let l:Pattern = '^' . l:Tag_Word . '$'
302   let l:Tag_List = taglist (l:Pattern)
303   let l:Error_List = []
304   "
305   " add symbols
306   "
307   for Tag_Item in l:Tag_List
308      if l:Tag_Item['kind'] == ''
309	 let l:Tag_Item['kind'] = 's'
310      endif
311
312      let l:Error_List += [
313	 \ l:Tag_Item['filename'] . '|' .
314	 \ l:Tag_Item['cmd']	  . '|' .
315	 \ l:Tag_Item['kind']	  . "\t" .
316	 \ l:Tag_Item['name'] ]
317   endfor
318   set errorformat=%f\|%l\|%m
319   cexpr l:Error_List
320   cwindow
321endfunction ada#List_Tag
322
323" Section: ada#Jump_Tag (Word, Mode) {{{1
324"
325" Word tag - include '.' and if Ada make uppercase
326"
327function ada#Jump_Tag (Word, Mode)
328   if a:Word == ''
329      " Get current word
330      let l:Word = ada#Word()
331      if l:Word == ''
332	 throw "NOT_FOUND: no identifier found."
333      endif
334   else
335      let l:Word = a:Word
336   endif
337
338   echo "Searching for " . l:Word
339
340   try
341      execute a:Mode l:Word
342   catch /.*:E426:.*/
343      let ignorecase = &ignorecase
344      set ignorecase
345      execute a:Mode l:Word
346      let &ignorecase = ignorecase
347   endtry
348
349   return
350endfunction ada#Jump_Tag
351
352" Section: ada#Insert_Backspace () {{{1
353"
354" Backspace at end of line after auto-inserted commentstring '-- ' wipes it
355"
356function ada#Insert_Backspace ()
357   let l:Line = getline ('.')
358   if col ('.') > strlen (l:Line) &&
359    \ match (l:Line, '-- $') != -1 &&
360    \ match (&comments,'--') != -1
361      return "\<bs>\<bs>\<bs>"
362   else
363      return "\<bs>"
364   endif
365
366   return
367endfunction ada#InsertBackspace
368
369" Section: Insert Completions {{{1
370"
371" Section: ada#User_Complete(findstart, base) {{{2
372"
373" This function is used for the 'complete' option.
374"
375function! ada#User_Complete(findstart, base)
376   if a:findstart == 1
377      "
378      " locate the start of the word
379      "
380      let line = getline ('.')
381      let start = col ('.') - 1
382      while start > 0 && line[start - 1] =~ '\i\|'''
383	 let start -= 1
384      endwhile
385      return start
386   else
387      "
388      " look up matches
389      "
390      let l:Pattern = '^' . a:base . '.*$'
391      "
392      " add keywords
393      "
394      for Tag_Item in g:ada#Keywords
395	 if l:Tag_Item['word'] =~? l:Pattern
396	    if complete_add (l:Tag_Item) == 0
397	       return []
398	    endif
399	    if complete_check ()
400	       return []
401	    endif
402	 endif
403      endfor
404      return []
405   endif
406endfunction ada#User_Complete
407
408" Section: ada#Completion (cmd) {{{2
409"
410" Word completion (^N/^R/^X^]) - force '.' inclusion
411function ada#Completion (cmd)
412   set iskeyword+=46
413   return a:cmd . "\<C-R>=ada#Completion_End ()\<CR>"
414endfunction ada#Completion
415
416" Section: ada#Completion_End () {{{2
417"
418function ada#Completion_End ()
419   set iskeyword-=46
420   return ''
421endfunction ada#Completion_End
422
423" Section: ada#Create_Tags {{{1
424"
425function ada#Create_Tags (option)
426   if a:option == 'file'
427      let l:Filename = shellescape (fnamemodify (bufname ('%'), ':p'))
428   elseif a:option == 'dir'
429      let l:Dir = fnamemodify (bufname ('%'), ':p:h')
430      let l:Filename =
431	 \ shellescape (l:Dir) . "*.ada " .
432	 \ shellescape (l:Dir) . "*.adb " .
433	 \ shellescape (l:Dir) . "*.ads"
434   else
435      let l:Filename = shellescape (a:option)
436   endif
437   execute '!ctags --excmd=number ' . l:Filename
438endfunction ada#Create_Tags
439
440" Section: ada#Switch_Session {{{1
441"
442function ada#Switch_Session (New_Session)
443   " 
444   " you should not save to much date into the seession since they will
445   " be sourced
446   "
447   let l:sessionoptions=&sessionoptions
448
449   try
450      set sessionoptions=buffers,curdir,folds,globals,resize,slash,tabpages,tabpages,unix,winpos,winsize
451
452      if a:New_Session != v:this_session
453	 "
454	 "  We actually got a new session - otherwise there
455	 "  is nothing to do.
456	 "
457	 if strlen (v:this_session) > 0
458	    execute 'mksession! ' . v:this_session
459	 endif
460
461	 let v:this_session = a:New_Session
462
463	 "if filereadable (v:this_session)
464	    "execute 'source ' . v:this_session
465	 "endif
466
467	 augroup ada_session
468	    autocmd!
469	    autocmd VimLeavePre * execute 'mksession! ' . v:this_session
470	 augroup END
471	 
472	 "if exists ("g:Tlist_Auto_Open") && g:Tlist_Auto_Open
473	    "TlistOpen
474	 "endif
475
476      endif
477   finally
478      let &sessionoptions=l:sessionoptions
479   endtry
480
481   return
482endfunction ada#Switch_Session	
483
484" Section: GNAT Pretty Printer folding {{{1
485"
486if exists('g:ada_folding') && g:ada_folding[0] == 'g'
487   "
488   " Lines consisting only of ')' ';' are due to a gnat pretty bug and
489   " have the same level as the line above (can't happen in the first
490   " line).
491   "
492   let s:Fold_Collate = '^\([;)]*$\|'
493
494   "
495   " some lone statements are folded with the line above
496   "
497   if stridx (g:ada_folding, 'i') >= 0
498      let s:Fold_Collate .= '\s\+\<is\>$\|'
499   endif
500   if stridx (g:ada_folding, 'b') >= 0
501      let s:Fold_Collate .= '\s\+\<begin\>$\|'
502   endif
503   if stridx (g:ada_folding, 'p') >= 0
504      let s:Fold_Collate .= '\s\+\<private\>$\|'
505   endif
506   if stridx (g:ada_folding, 'x') >= 0
507      let s:Fold_Collate .= '\s\+\<exception\>$\|'
508   endif
509
510   " We also handle empty lines and
511   " comments here.
512   let s:Fold_Collate .= '--\)'
513
514   function ada#Pretty_Print_Folding (Line)			     " {{{2
515      let l:Text = getline (a:Line)
516
517      if l:Text =~ s:Fold_Collate
518	 "
519	 "  fold with line above
520	 "
521	 let l:Level = "="
522      elseif l:Text =~ '^\s\+('
523	 "
524	 " gnat outdents a line which stards with a ( by one characters so
525	 " that parameters which follow are aligned.
526	 "
527	 let l:Level = (indent (a:Line) + 1) / &shiftwidth
528      else
529	 let l:Level = indent (a:Line) / &shiftwidth
530      endif
531
532      return l:Level
533   endfunction ada#Pretty_Print_Folding				     " }}}2
534endif
535
536" Section: Options and Menus {{{1
537"
538" Section: ada#Switch_Syntax_Options {{{2
539"
540function ada#Switch_Syntax_Option (option)
541   syntax off
542   if exists ('g:ada_' . a:option)
543      unlet g:ada_{a:option}
544      echo  a:option . 'now off'
545   else
546      let g:ada_{a:option}=1
547      echo  a:option . 'now on'
548   endif
549   syntax on
550endfunction ada#Switch_Syntax_Option
551
552" Section: ada#Map_Menu {{{2
553"
554function ada#Map_Menu (Text, Keys, Command)
555   if a:Keys[0] == ':'
556      execute
557	\ "50amenu " .
558	\ "Ada."     . escape(a:Text, ' ') .
559	\ "<Tab>"    . a:Keys .
560	\ " :"	     . a:Command . "<CR>"
561      execute
562	\ "command -buffer " .
563	\ a:Keys[1:] .
564	\" :" . a:Command . "<CR>"
565   elseif a:Keys[0] == '<'
566      execute
567	\ "50amenu " .
568	\ "Ada."     . escape(a:Text, ' ') .
569	\ "<Tab>"    . a:Keys .
570	\ " :"	     . a:Command . "<CR>"
571      execute
572	\ "nnoremap <buffer> "	 .
573	\ a:Keys		 .
574	\" :" . a:Command . "<CR>"
575      execute
576	\ "inoremap <buffer> "	 .
577	\ a:Keys		 .
578	\" <C-O>:" . a:Command . "<CR>"
579   else
580      if exists("g:mapleader")
581         let l:leader = g:mapleader
582      else
583         let l:leader = '\'
584      endif
585      execute
586	\ "50amenu " .
587	\ "Ada."  . escape(a:Text, ' ') .
588	\ "<Tab>" . escape(l:leader . "a" . a:Keys , '\') .
589	\ " :"	  . a:Command . "<CR>"
590      execute
591	\ "nnoremap <buffer>" .
592	\ " <Leader>a" . a:Keys .
593	\" :" . a:Command
594      execute
595	\ "inoremap <buffer>" .
596	\ " <Leader>a" . a:Keys .
597	\" <C-O>:" . a:Command
598   endif
599   return
600endfunction
601
602" Section: ada#Map_Popup {{{2
603"
604function ada#Map_Popup (Text, Keys, Command)
605   if exists("g:mapleader")
606      let l:leader = g:mapleader
607   else
608      let l:leader = '\'
609   endif
610   execute
611     \ "50amenu " .
612     \ "PopUp."   . escape(a:Text, ' ') .
613     \ "<Tab>"	  . escape(l:leader . "a" . a:Keys , '\') .
614     \ " :"	  . a:Command . "<CR>"
615
616   call ada#Map_Menu (a:Text, a:Keys, a:Command)
617   return
618endfunction ada#Map_Popup
619
620" }}}1
621
622lockvar  g:ada#WordRegex
623lockvar  g:ada#DotWordRegex
624lockvar  g:ada#Comment
625lockvar! g:ada#Keywords
626lockvar! g:ada#Ctags_Kinds
627
628let &cpo = s:keepcpo
629unlet s:keepcpo
630
631finish " 1}}}
632
633"------------------------------------------------------------------------------
634"   Copyright (C) 2006	Martin Krischik
635"
636"   Vim is Charityware - see ":help license" or uganda.txt for licence details.
637"------------------------------------------------------------------------------
638" vim: textwidth=78 wrap tabstop=8 shiftwidth=3 softtabstop=3 noexpandtab
639" vim: foldmethod=marker