!* -*-TECO-*- *! !~FILENAME~:! !Functions for editing Ada code.! ADA !Ada Mode:! !& Ada Mode:! !C Set up for editing Ada code. Tab indents for next Ada statement. Meta-I is ^R Indent Relative. C-M-. is ^R Ada Template, which inserts a template for the statement started. ^R Backward Sexp and ^R Forward Sexp move over Ada objects; ^R Kill Sexp and ^R Backward Kill Sexp delete them. An Ada object is an identifier, string, or parenthesized expression.! m(m.m& Init Buffer Locals) !* flush previous mode! 1,(:i*--)m.lComment Start !* set comment variables! 1,(:i*-- )m.lComment Begin !* ...! 1,40m.lComment Column !* ...! 1,(m.m^R Ada Indent)m.qI !* Tab: indent under previous line! 1,(m.m^R Indent Relative)m.q..I !* M-I: indent under previous line! 1,(m.m^R Tab to Tab Stop)m.q...I !* C-M-I: indent to tab stop! 1,(:i* : : : : : : : : : : : : : :( ))m.lTab Stop Definitions !* Set tab stops every 4 columns! 1,(m.m^R Ada Template)m.q.... !* C-M-.: template hack! 1,q¨1,q.í.q›w)m.q.› !* tab hacking rubout! !* now create a ..D with Lisp syntax appropriate for Ada! m.q..D !* local ..D! 0fo..qAda ..Df"nu..d'"# !* if already exists, use it! :g..du..d !* otherwise copy previous one! -1u1 0<%1*5+1:f..d > !* [NUL,0) are breaks! 10<%1*5+1:f..dA> !* [0,9] are constituents! A-9-1<%1*5+1:f..d > !* (9,A) are breaks! 26<%1*5+1:f..dA> !* [A,Z] are constituents! a-Z-1<%1*5+1:f..d > !* (Z,a) are breaks! 26<%1*5+1:f..dA> !* [a,z] are constituents! 128-z-1<%1*5+1:f..d > !* (z,DEL] are breaks! _*5+1:f..dA !* underscore is a constituents! (*5+1:f..d( !* parentheses are parentheses! )*5+1:f..d) !* ...! "*5+1:f..d| !'! !* quote for strings! \*5+1:f..d/ !* backslash is quote! q..dm.vAda ..Dw' 1m(m.m& Set Mode Line)Ada  !* set mode line, run hook, etc.! !^R Ada Indent:! !^R Move to column for next Ada statement. Does not work properly if you put multiple statements per line.! m(m.m& Declare Load-Time Defaults) Ada => Indentation,: 4 Ada begin Indentation,: 4 Ada case Indentation,: 4 Ada declare Indentation,: 4 Ada do Indentation,: 4 Ada else Indentation,: 4 Ada exception Indentation,: 4 Ada is Indentation,: 4 Ada loop Indentation,: 4 Ada private Indentation,: 4 Ada record Indentation,: 4 Ada select Indentation,: 4 Ada then Indentation,: 4  !* Note: could use @:fwl to move over tokens until end of line or comment start instead a simple search. Wins in face of comment start in strings. *! .[1[2[3[4 !* 1: where we started! -@f l 10,0a-10"n q1j f:m(m.m^R Indent Relative)' !* if not at beginning of line, do! !* indent relative instead! !* Find first nonblank line (not including comments).! < b-.; -l !* exit if beginning of buffer, else try! !* previous line! :f:fb--: -@f l !* find first nonblank before comment! 0,0a-10@:; !* exit if not at beginning of line,! 0l > !* i.e. there's text before the comment! ;,0a-;"e 0u2' !* 2: extra indentation of 0 for! !* beginning of buffer or semicolon! "# !"e ! Indentationu2' "# -@fwx3 !* get last identifier of line! 2fo..qAda 3 Indentationu2'' !* 2: extra indentation, use 2 if not! !* known (i.e. if in middle of! !* statement)! !* Find start of this statement by moving backward until end of previous! !* statement.! .u4 !* 4: first nonblank line of this! !* statement! < -l b-.; !* previous line, exit if beginning! :f:fb--: -@f l !* find first nonblank before comment! 0a-;@; !* semicolon, exit! !"e 0;' !* exit if when terminator! 0a"c -@fwx3 -1fo..qAda 3 Indentation;' !* exit if known keyword! 0a-10"n .u4' !* if nonblank line, remember it! > q4j 0l @f l fsSHpos+q2u2 !* 2: total indentation! q1j fsSHposu1 !* 1: indentation where we started! q1-q2"l q2:m(m.m& Indent)' !* before indent point, move there! f:m(m.m^R Indent Relative) !* past indent point, indent relative! !^R Ada Template:! !^R Insert template for keyword just typed.! .[1[2[3 !* 1: where we started! -@:fwl -@fwf(l)x2 !* 2: keyword! 1,m.m# Ada 2u3 !* 3: function for keyword! q3"n 0l @f l !* Find beginning of line! fsSHPos(q1j),(fff"nw'):m3' !* Goto function if found one! 1,m(m.m& Get Library Pointer)WORDAB"n !* Else if WordAb package is loaded! q1j @m(m.m^R Abbrev Expand Only)f !* Try expanding abbrevs! .u1 -@:fwl -@fwf(l)x2 !* 2: keyword! 1,m.m# Ada 2u3 !* 3: function for keyword! q3"n 0l @f l !* Find beginning of line! fsSHPos(q1j),(fff"nw'):m3' !* Goto function if found one! @m(m.m^R Unexpand Last Word)f !* Else undo expansion! ' !* End if WORDAB! :i*No template for 2fsErr 0 !* else give error! !& Ada Previous Label:! !S Return string for previous label, or 0 if none! 0[4 .[0 fnq0j -@fwl !* protect point, go back over word! -@f l 0,0a-10"e -1 :f:fb--: -@f l' !* move back to previous token! 0,0a-:"e r -@fwx4' !* if colon, then pick up loop label! q4 !* return with label! !# Ada while:! !# Ada for:! !S Insert template for WHILE and FOR! m(m.m& Ada Previous Label)[4 !* 4: loop label if any! .[0 i loop  0,m(m.m& XIndent)w iend loop q4"n 32i g4' i; q0,.(q0j) !# Ada if:! !S Insert template for IF! .[0 i then  "n f"lw -1-'< !* if arg, insert else clauses! 0,m(m.m& XIndent)w ielseif then > "l 0,m(m.m& XIndent)w ielse '' 0,m(m.m& XIndent)w iend if; q0,.(q0j) !# Ada case:! !S Insert template for CASE! .[0 i is f"lw -' "gi others =>  0,+qAda is Indentation+qAda => Indentationm(m.m& XIndent)w' i  0,m(m.m& XIndent)w iend case; q0,.(q0j) !# Ada begin:! !S Insert template for BEGIN! m(m.m& Ada Previous Label)[4 !* 4: loop label if any! .(i  0,+qAda loop Indentationm(m.m& XIndent)w .[1 i  0,m(m.m& XIndent)w iend q4"n 32i g4' i;),.(q1j) !# Ada loop:! !S Insert template for LOOP! m(m.m& Ada Previous Label)[4 !* pick up label if any! .(i  0,+qAda loop Indentationm(m.m& XIndent)w .[1 i  0,m(m.m& XIndent)w iend loop q4"n 32i g4' i;),.(q1j) !# Ada declare:! !S Insert template for DECLARE! m(m.m& Ada Previous Label)[4 !* pick up label if any! .(i  0,+qAda declare Indentationm(m.m& XIndent)w .[1 i  0,m(m.m& XIndent)w ibegin  0,m(m.m& XIndent)w iend q4"n 32i g4' i;),.(q1j) !# Ada record:! !S Insert template for RECORD! .(i  0,+qAda loop Indentationm(m.m& XIndent)w .[1 i  0,m(m.m& XIndent)w iend record;),.(q1j) !# Ada package:! !# Ada task:! !# Ada body:! !S Insert template for PACKAGE or TASK! .[3 .-z([2 -@:fwl -5f~ body"e -2@:fwl'"# "l i body -5c'' -@fwx2)+zj 3,m(m.m& Read Line)2 name: [0 fq0:"g 0' i 0 is  :"g 0,+qAda is Indentationm(m.m& XIndent)w .[1i '"# 0,m(m.m& XIndent)w iend;  0,m(m.m& XIndent)w i2 body 0 is  0,+qAda is Indentationm(m.m& XIndent)w .[1 i ' 0,m(m.m& XIndent)w iend 0; q3,.(q1j) !# Ada procedure:! !# Ada function:! !S Insert template for PROCEDURE and FUNCTION! .( [2 -@:fwl -@fwx2)j !* get task or package in 2! 3,m(m.m& Read Line)2 name: [0 fq0:"g 0' .(i 0 .[1 i is  0,m(m.m& XIndent)w ibegin  0,+qAda begin Indentationm(m.m& XIndent)w "n i  0,m(m.m& XIndent)w iexception  0,+qAda exception Indentationm(m.m& XIndent) iwhen others =>  0,+qAda exception Indentation+qAda => Indentationm(m.m& XIndent)' i  0,m(m.m& XIndent)w iend 0;),.(q1j) !# Ada exception:! !S Insert template for EXCEPTION! .(i  0,+qAda exception Indentationm(m.m& XIndent)w iwhen others =>  0,+qAda exception Indentation+qAda => Indentationm(m.m& XIndent)w),. !# Ada accept:! !S Insert template for ACCEPT! .[0 i do  0,+qAda do Indentationm(m.m& XIndent)w i  0,m(m.m& XIndent)w iend; q0,.(q0j) !# Ada select:! !S Insert template for SELECT! .(i  0,+qAda select Indentationm(m.m& XIndent)w .[0 i  "n f"lw -1-'< !* if arg, insert or clauses! 0,m(m.m& XIndent)w ior >' "l 0,m(m.m& XIndent)w ielse ' 0,m(m.m& XIndent)w iend;),.(q0j) !* * Local Modes: * Comment Column:40 * End: *!