1 "------------------------------------------------------------------------------
2 " Description: Perform Ada specific completion & tagging.
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>
11 " $Date: 2017-01-31 20:20:05 +0200 (Mon, 01 Jan 2017) $
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
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
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 "------------------------------------------------------------------------------
37 " Section: Constants {{{1
39 let g:ada#DotWordRegex = '\a\w*\(\_s*\.\_s*\a\w*\)*'
40 let g:ada#WordRegex = '\a\w*'
41 let g:ada#Comment = "\\v^(\"[^\"]*\"|'.'|[^\"']){-}\\zs\\s*--.*"
42 let g:ada#Keywords = []
44 " Section: g:ada#Keywords {{{1
46 " Section: add Ada keywords {{{2
48 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']
49 let g:ada#Keywords += [{
52 \ 'info': 'Ada keyword.',
57 " Section: GNAT Project Files {{{3
59 if exists ('g:ada_with_gnat_project_files')
60 for Item in ['project']
61 let g:ada#Keywords += [{
64 \ 'info': 'GNAT projectfile keyword.',
70 " Section: add standart exception {{{2
72 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']
73 let g:ada#Keywords += [{
75 \ 'menu': 'exception',
76 \ 'info': 'Ada standart exception.',
81 " Section: add GNAT exception {{{3
83 if exists ('g:ada_gnat_extensions')
84 for Item in ['Assert_Failure']
85 let g:ada#Keywords += [{
87 \ 'menu': 'exception',
88 \ 'info': 'GNAT exception.',
94 " Section: add Ada buildin types {{{2
96 for Item in ['Boolean', 'Integer', 'Natural', 'Positive', 'Float', 'Character', 'Wide_Character', 'Wide_Wide_Character', 'String', 'Wide_String', 'Wide_Wide_String', 'Duration']
97 let g:ada#Keywords += [{
100 \ 'info': 'Ada buildin type.',
105 " Section: add GNAT buildin types {{{3
107 if exists ('g:ada_gnat_extensions')
108 for Item in ['Short_Integer', 'Short_Short_Integer', 'Long_Integer', 'Long_Long_Integer', 'Short_Float', 'Short_Short_Float', 'Long_Float', 'Long_Long_Float']
109 let g:ada#Keywords += [{
112 \ 'info': 'GNAT buildin type.',
118 " Section: add Ada Attributes {{{2
120 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']
121 let g:ada#Keywords += [{
123 \ 'menu': 'attribute',
124 \ 'info': 'Ada attribute.',
129 " Section: add GNAT Attributes {{{3
131 if exists ('g:ada_gnat_extensions')
132 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']
133 let g:ada#Keywords += [{
135 \ 'menu': 'attribute',
136 \ 'info': 'GNAT attribute.',
142 " Section: add Ada Pragmas {{{2
144 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']
145 let g:ada#Keywords += [{
148 \ 'info': 'Ada pragma.',
153 " Section: add GNAT Pragmas {{{3
155 if exists ('g:ada_gnat_extensions')
156 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']
157 let g:ada#Keywords += [{
160 \ 'info': 'GNAT pragma.',
167 " Section: g:ada#Ctags_Kinds {{{1
169 let g:ada#Ctags_Kinds = {
170 \ 'P': ["packspec", "package specifications"],
171 \ 'p': ["package", "packages"],
172 \ 'T': ["typespec", "type specifications"],
173 \ 't': ["type", "types"],
174 \ 'U': ["subspec", "subtype specifications"],
175 \ 'u': ["subtype", "subtypes"],
176 \ 'c': ["component", "record type components"],
177 \ 'l': ["literal", "enum type literals"],
178 \ 'V': ["varspec", "variable specifications"],
179 \ 'v': ["variable", "variables"],
180 \ 'f': ["formal", "generic formal parameters"],
181 \ 'n': ["constant", "constants"],
182 \ 'x': ["exception", "user defined exceptions"],
183 \ 'R': ["subprogspec", "subprogram specifications"],
184 \ 'r': ["subprogram", "subprograms"],
185 \ 'K': ["taskspec", "task specifications"],
186 \ 'k': ["task", "tasks"],
187 \ 'O': ["protectspec", "protected data specifications"],
188 \ 'o': ["protected", "protected data"],
189 \ 'E': ["entryspec", "task/protected data entry specifications"],
190 \ 'e': ["entry", "task/protected data entries"],
191 \ 'b': ["label", "labels"],
192 \ 'i': ["identifier", "loop/declare identifiers"],
193 \ 'a': ["autovar", "automatic variables"],
194 \ 'y': ["annon", "loops and blocks with no identifier"]}
196 " Section: ada#Word (...) {{{1
198 " Extract current Ada word across multiple lines
199 " AdaWord ([line, column])\
201 function ada#Word (...)
204 let l:Column_Nr = a:2 - 1
206 let l:Line_Nr = line('.')
207 let l:Column_Nr = col('.') - 1
210 let l:Line = substitute (getline (l:Line_Nr), g:ada#Comment, '', '' )
212 " Cope with tag searching for items in comments; if we are, don't loop
213 " backards looking for previous lines
214 if l:Column_Nr > strlen(l:Line)
215 " We were in a comment
216 let l:Line = getline(l:Line_Nr)
217 let l:Search_Prev_Lines = 0
219 let l:Search_Prev_Lines = 1
222 " Go backwards until we find a match (Ada ID) that *doesn't* include our
223 " location - i.e., the previous ID. This is because the current 'correct'
224 " match will toggle matching/not matching as we traverse characters
225 " backwards. Thus, we have to find the previous unrelated match, exclude
226 " it, then use the next full match (ours).
227 " Remember to convert vim column 'l:Column_Nr' [1..n] to string offset [0..(n-1)]
228 " ... but start, here, one after the required char.
229 let l:New_Column = l:Column_Nr + 1
231 let l:New_Column = l:New_Column - 1
233 " Have to include previous l:Line from file
234 let l:Line_Nr = l:Line_Nr - 1
235 if l:Line_Nr < 1 || !l:Search_Prev_Lines
236 " Start of file or matching in a comment
239 let l:Our_Match = match (l:Line, g:ada#WordRegex )
242 " Get previous l:Line, and prepend it to our search string
243 let l:New_Line = substitute (getline (l:Line_Nr), g:ada#Comment, '', '' )
244 let l:New_Column = strlen (l:New_Line) - 1
245 let l:Column_Nr = l:Column_Nr + l:New_Column
246 let l:Line = l:New_Line . l:Line
248 " Check to see if this is a match excluding 'us'
249 let l:Match_End = l:New_Column +
250 \ matchend (strpart (l:Line,l:New_Column), g:ada#WordRegex ) - 1
251 if l:Match_End >= l:New_Column &&
252 \ l:Match_End < l:Column_Nr
254 let l:Our_Match = l:Match_End+1 +
255 \ match (strpart (l:Line,l:Match_End+1), g:ada#WordRegex )
264 let l:Line = strpart (l:Line, l:Our_Match)
267 " Now simply add further lines until the match gets no bigger
268 let l:Match_String = matchstr (l:Line, g:ada#WordRegex)
269 let l:Last_Line = line ('$')
270 let l:Line_Nr = line ('.') + 1
271 while l:Line_Nr <= l:Last_Line
272 let l:Last_Match = l:Match_String
273 let l:Line = l:Line .
274 \ substitute (getline (l:Line_Nr), g:ada#Comment, '', '')
275 let l:Match_String = matchstr (l:Line, g:ada#WordRegex)
276 if l:Match_String == l:Last_Match
281 " Strip whitespace & return
282 return substitute (l:Match_String, '\s\+', '', 'g')
285 " Section: ada#List_Tag (...) {{{1
287 " List tags in quickfix window
289 function ada#List_Tag (...)
291 let l:Tag_Word = ada#Word (a:1, a:2)
295 let l:Tag_Word = ada#Word ()
298 echo "Searching for" l:Tag_Word
300 let l:Pattern = '^' . l:Tag_Word . '$'
301 let l:Tag_List = taglist (l:Pattern)
302 let l:Error_List = []
306 for Tag_Item in l:Tag_List
307 if l:Tag_Item['kind'] == ''
308 let l:Tag_Item['kind'] = 's'
311 let l:Error_List += [
312 \ l:Tag_Item['filename'] . '|' .
313 \ l:Tag_Item['cmd'] . '|' .
314 \ l:Tag_Item['kind'] . "\t" .
315 \ l:Tag_Item['name'] ]
317 set errorformat=%f\|%l\|%m
320 endfunction ada#List_Tag
322 " Section: ada#Jump_Tag (Word, Mode) {{{1
324 " Word tag - include '.' and if Ada make uppercase
326 function ada#Jump_Tag (Word, Mode)
329 let l:Word = ada#Word()
331 throw "NOT_FOUND: no identifier found."
337 echo "Searching for " . l:Word
340 execute a:Mode l:Word
342 let ignorecase = &ignorecase
344 execute a:Mode l:Word
345 let &ignorecase = ignorecase
349 endfunction ada#Jump_Tag
351 " Section: ada#Insert_Backspace () {{{1
353 " Backspace at end of line after auto-inserted commentstring '-- ' wipes it
355 function ada#Insert_Backspace ()
356 let l:Line = getline ('.')
357 if col ('.') > strlen (l:Line) &&
358 \ match (l:Line, '-- $') != -1 &&
359 \ match (&comments,'--') != -1
360 return "\<bs>\<bs>\<bs>"
366 endfunction ada#InsertBackspace
368 " Section: Insert Completions {{{1
370 " Section: ada#User_Complete(findstart, base) {{{2
372 " This function is used for the 'complete' option.
374 function! ada#User_Complete(findstart, base)
377 " locate the start of the word
379 let line = getline ('.')
380 let start = col ('.') - 1
381 while start > 0 && line[start - 1] =~ '\i\|'''
389 let l:Pattern = '^' . a:base . '.*$'
393 for Tag_Item in g:ada#Keywords
394 if l:Tag_Item['word'] =~? l:Pattern
395 if complete_add (l:Tag_Item) == 0
405 endfunction ada#User_Complete
407 " Section: ada#Completion (cmd) {{{2
409 " Word completion (^N/^R/^X^]) - force '.' inclusion
410 function ada#Completion (cmd)
412 return a:cmd . "\<C-R>=ada#Completion_End ()\<CR>"
413 endfunction ada#Completion
415 " Section: ada#Completion_End () {{{2
417 function ada#Completion_End ()
420 endfunction ada#Completion_End
422 " Section: ada#Create_Tags {{{1
424 function ada#Create_Tags (option)
425 if a:option == 'file'
426 let l:Filename = fnamemodify (bufname ('%'), ':p')
427 elseif a:option == 'dir'
429 \ fnamemodify (bufname ('%'), ':p:h') . "*.ada " .
430 \ fnamemodify (bufname ('%'), ':p:h') . "*.adb " .
431 \ fnamemodify (bufname ('%'), ':p:h') . "*.ads"
433 let l:Filename = a:option
435 execute '!ctags --excmd=number ' . l:Filename
436 endfunction ada#Create_Tags
438 " Section: ada#Switch_Session {{{1
440 function ada#Switch_Session (New_Session)
442 " you should not save to much date into the seession since they will
445 let l:sessionoptions=&sessionoptions
448 set sessionoptions=buffers,curdir,folds,globals,resize,slash,tabpages,tabpages,unix,winpos,winsize
450 if a:New_Session != v:this_session
452 " We actually got a new session - otherwise there
455 if strlen (v:this_session) > 0
456 execute 'mksession! ' . v:this_session
459 let v:this_session = a:New_Session
461 "if filereadable (v:this_session)
462 "execute 'source ' . v:this_session
467 autocmd VimLeavePre * execute 'mksession! ' . v:this_session
470 "if exists ("g:Tlist_Auto_Open") && g:Tlist_Auto_Open
476 let &sessionoptions=l:sessionoptions
480 endfunction ada#Switch_Session
482 " Section: GNAT Pretty Printer folding {{{1
484 if exists('g:ada_folding') && g:ada_folding[0] == 'g'
486 " Lines consisting only of ')' ';' are due to a gnat pretty bug and
487 " have the same level as the line above (can't happen in the first
490 let s:Fold_Collate = '^\([;)]*$\|'
493 " some lone statements are folded with the line above
495 if stridx (g:ada_folding, 'i') >= 0
496 let s:Fold_Collate .= '\s\+\<is\>$\|'
498 if stridx (g:ada_folding, 'b') >= 0
499 let s:Fold_Collate .= '\s\+\<begin\>$\|'
501 if stridx (g:ada_folding, 'p') >= 0
502 let s:Fold_Collate .= '\s\+\<private\>$\|'
504 if stridx (g:ada_folding, 'x') >= 0
505 let s:Fold_Collate .= '\s\+\<exception\>$\|'
508 " We also handle empty lines and
510 let s:Fold_Collate .= '--\)'
512 function ada#Pretty_Print_Folding (Line) " {{{2
513 let l:Text = getline (a:Line)
515 if l:Text =~ s:Fold_Collate
517 " fold with line above
520 elseif l:Text =~ '^\s\+('
522 " gnat outdents a line which stards with a ( by one characters so
523 " that parameters which follow are aligned.
525 let l:Level = (indent (a:Line) + 1) / &shiftwidth
527 let l:Level = indent (a:Line) / &shiftwidth
531 endfunction ada#Pretty_Print_Folding " }}}2
534 " Section: Options and Menus {{{1
536 " Section: ada#Switch_Syntax_Options {{{2
538 function ada#Switch_Syntax_Option (option)
540 if exists ('g:ada_' . a:option)
541 unlet g:ada_{a:option}
542 echo a:option . 'now off'
544 let g:ada_{a:option}=1
545 echo a:option . 'now on'
548 endfunction ada#Switch_Syntax_Option
550 " Section: ada#Map_Menu {{{2
552 function ada#Map_Menu (Text, Keys, Command)
556 \ "Ada." . escape(a:Text, ' ') .
558 \ " :" . a:Command . "<CR>"
560 \ "command -buffer " .
562 \" :" . a:Command . "<CR>"
563 elseif a:Keys[0] == '<'
566 \ "Ada." . escape(a:Text, ' ') .
568 \ " :" . a:Command . "<CR>"
570 \ "nnoremap <buffer> " .
572 \" :" . a:Command . "<CR>"
574 \ "inoremap <buffer> " .
576 \" <C-O>:" . a:Command . "<CR>"
578 if exists("g:mapleader")
579 let l:leader = g:mapleader
585 \ "Ada." . escape(a:Text, ' ') .
586 \ "<Tab>" . escape(l:leader . "a" . a:Keys , '\') .
587 \ " :" . a:Command . "<CR>"
589 \ "nnoremap <buffer>" .
590 \ " <Leader>a" . a:Keys .
593 \ "inoremap <buffer>" .
594 \ " <Learder>a" . a:Keys .
595 \" <C-O>:" . a:Command
600 " Section: ada#Map_Popup {{{2
602 function ada#Map_Popup (Text, Keys, Command)
603 if exists("g:mapleader")
604 let l:leader = g:mapleader
610 \ "PopUp." . escape(a:Text, ' ') .
611 \ "<Tab>" . escape(l:leader . "a" . a:Keys , '\') .
612 \ " :" . a:Command . "<CR>"
614 call ada#Map_Menu (a:Text, a:Keys, a:Command)
616 endfunction ada#Map_Popup
620 lockvar g:ada#WordRegex
621 lockvar g:ada#DotWordRegex
622 lockvar g:ada#Comment
623 lockvar! g:ada#Keywords
624 lockvar! g:ada#Ctags_Kinds
631 "------------------------------------------------------------------------------
632 " Copyright (C) 2006 Martin Krischik
634 " Vim is Charityware - see ":help license" or uganda.txt for licence details.
635 "------------------------------------------------------------------------------
636 " vim: textwidth=78 wrap tabstop=8 shiftwidth=3 softtabstop=3 noexpandtab
637 " vim: foldmethod=marker