home *** CD-ROM | disk | FTP | other *** search
- /* C keys */
- /* */
- /* The enter and space bar keys have been defined to do*/
- /* specific C editing features. */
-
- CONST
- compile if not defined(I_like_my_cases_under_my_switch)
- I_like_my_cases_under_my_switch = 1
- compile endif
- compile if not defined(I_like_a_semicolon_supplied_after_default)
- I_like_a_semicolon_supplied_after_default = 0
- compile endif
-
- compile if EVERSION >= '4.12'
- ; Keyset selection is now done once at file load time, not every time
- ; the file is selected. And because the DEFLOAD procedures don't have to be
- ; kept together in the macros (ET will concatenate all the DEFLOADs the
- ; same way it does DEFINITs), we can put the DEFLOAD here where it belongs,
- ; with the rest of the keyset function. (what a concept!)
- ;
- defload
- compile if EPM
- universal load_var
- compile endif
- ext = filetype() -- C++ Data Base Manager
- if ext='C' or ext='H' or ext='CPP' or ext='SQC' then
- keys C_keys
- compile if C_TABS <> 0
- compile if EPM
- if not (load_var // 2) then -- 1 would be on if tabs set from EA EPM.TABS
- compile endif
- 'tabs' C_TABS
- compile if EPM
- endif
- compile endif
- compile endif
- compile if C_MARGINS <> 0
- compile if EPM
- if not (load_var%2 - 2*(load_var%4)) then -- 2 would be on if tabs set from EA EPM.MARGINS
- compile endif
- 'ma' C_MARGINS
- compile if EPM
- endif
- compile endif
- compile endif
- endif
- compile endif
-
- compile if WANT_CUA_MARKING & EPM
- defkeys c_keys clear
- compile else
- defkeys c_keys
- compile endif
-
- compile if EVERSION >= 5
- def space=
- compile else
- def ' '=
- compile endif
- universal expand_on
- if expand_on then
- if not c_first_expansion() then
- keyin ' '
- endif
- else
- keyin ' '
- endif
- compile if EVERSION >= '5.20'
- undoaction 1, junk -- Create a new state
- compile endif
-
- compile if ASSIST_TRIGGER = 'ENTER'
- def enter=
- compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''
- universal enterkey
- compile endif
- compile else
- def c_enter=
- compile if ENHANCED_ENTER_KEYS & c_ENTER_ACTION <> ''
- universal c_enterkey
- compile endif
- compile endif
- universal expand_on
-
- compile if EVERSION >= 5
- if expand_on then
- compile else
- if expand_on & not command_state() then
- compile endif
- compile if EVERSION <= '4.12'
- if c_second_expansion() then
- call maybe_autosave()
- else
- compile else
- if not c_second_expansion() then
- compile endif
- compile if ASSIST_TRIGGER = 'ENTER'
- compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''
- call enter_common(enterkey)
- compile else
- call my_enter()
- compile endif
- compile else -- ASSIST_TRIGGER
- compile if ENHANCED_ENTER_KEYS & c_ENTER_ACTION <> ''
- call enter_common(c_enterkey)
- compile else
- call my_c_enter()
- compile endif
- compile endif -- ASSIST_TRIGGER
- endif
- else
- compile if ASSIST_TRIGGER = 'ENTER'
- compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''
- call enter_common(enterkey)
- compile else
- call my_enter()
- compile endif
- compile else -- ASSIST_TRIGGER
- compile if ENHANCED_ENTER_KEYS & c_ENTER_ACTION <> ''
- call enter_common(c_enterkey)
- compile else
- call my_c_enter()
- compile endif
- compile endif -- ASSIST_TRIGGER
- endif
-
- /* Taken out, interferes with some people's c_enter. */
- ;def c_enter= /* I like Ctrl-Enter to finish the comment field also. */
- ; getline line
- ; if pos('/*',line) then
- ; if not pos('*/',line) then
- ; end_line;keyin' */'
- ; endif
- ; endif
- ; down;begin_line
-
- def c_x= /* Force expansion if we don't have it turned on automatic */
- if not c_first_expansion() then
- call c_second_expansion()
- endif
-
- defproc c_first_expansion
- retc=1
- compile if EVERSION >= 5
- if .line then
- compile else
- if .line and (not command_state()) then
- compile endif
- getline line
- line=strip(line,'T')
- w=line
- wrd=upcase(w)
- if wrd='FOR' then
- replaceline w' (; ; ) {'
- insertline substr(wrd,1,length(wrd)-3)'} /* endfor */',.line+1
- if not insert_state() then insert_toggle
- compile if EVERSION >= '5.50'
- call fixup_cursor()
- compile endif
- endif
- .col=.col+2
- elseif wrd='IF' then
- replaceline w' () {'
- insertline substr(wrd,1,length(wrd)-2)'} else {',.line+1
- insertline substr(wrd,1,length(wrd)-2)'} /* endif */',.line+2
- if not insert_state() then insert_toggle
- compile if EVERSION >= '5.50'
- call fixup_cursor()
- compile endif
- endif
- .col=.col+2
- elseif wrd='WHILE' then
- replaceline w' () {'
- insertline substr(wrd,1,length(wrd)-5)'} /* endwhile */',.line+1
- if not insert_state() then insert_toggle
- compile if EVERSION >= '5.50'
- call fixup_cursor()
- compile endif
- endif
- .col=.col+2
- elseif wrd='DO' then
- replaceline w' {'
- insertline substr(' ',1,length(wrd)-2,' ')'} while ( ); /* enddo */',.line+1
- call einsert_line()
- .col=.col+SYNTAX_INDENT /* indent for new line */
- elseif wrd='SWITCH' then
- replaceline w' () {'
- insertline substr(wrd,1,length(wrd)-6)'} /* endswitch */',.line+1
- if not insert_state() then insert_toggle
- compile if EVERSION >= '5.50'
- call fixup_cursor()
- compile endif
- endif
- .col=.col+2 /* move cursor between parentheses of switch ()*/
- elseif wrd='MAIN' then
- call enter_main_heading()
- else
- retc=0
- endif
- else
- retc=0
- endif
- return retc
-
- defproc c_second_expansion
- retc=1
- if .line then
- getline line
- parse value upcase(line) with '{' +0 a
- parse value line with wrd rest
- i=verify(wrd,'({:;','M',1)-1
- if i<=0 then i=length(wrd) endif
- firstword=upcase(substr(wrd,1,i))
- if firstword='FOR' then
- /* do tabs to fields of C for statement */
- cp=pos(';',line,.col)
- if cp and cp>=.col then
- .col=cp+2
- else
- cpn=pos(';',line,cp+1)
- if cpn and (cpn>=.col) then
- .col=cpn+2
- else
- call einsert_line()
- .col=.col+SYNTAX_INDENT
- endif
- endif
- elseif firstword='CASE' or firstword='DEFAULT' then
- call einsert_line()
- if .line>2 then /* take a look at the previous line */
- getline prevline,.line-2
- prevline=upcase(prevline)
- parse value prevline with w .
- if w='CASE' then /* align case statements */
- i=pos('C',prevline)
- replaceline substr('',1,i-1)||wrd rest,.line-1
- .col=i
- elseif w<>'CASE' and w<>'SWITCH' then /* shift current line over */
- i=verify(prevline,' ')
- if i then .col=i endif
- if i>SYNTAX_INDENT then i=i-SYNTAX_INDENT else i=1 endif
- .col=i
- replaceline substr('',1,i-1)||wrd rest,.line-1
- endif
- /* get rid of line containing just a ; */
- if firstword='DEFAULT' and .line <.last then
- getline line,.line+1
- if line=';' then
- deleteline .line+1
- endif
- endif
- endif
- .col=.col+SYNTAX_INDENT
- elseif firstword='BREAK' then
- call einsert_line()
- c=.col
- if .col>SYNTAX_INDENT then
- .col=.col-SYNTAX_INDENT
- endif
- keyin 'case :';left
- insertline substr('',1,c-1)'break;',.line+1
- elseif firstword='SWITCH' then
- call einsert_line()
- c=.col
- compile if I_like_my_cases_under_my_switch
- keyin 'case :';left
- compile else
- keyin substr(' ',1,SYNTAX_INDENT)'case :';left
- c=c+SYNTAX_INDENT
- compile endif
- insertline substr(' ',1,c+SYNTAX_INDENT-1)'break;',.line+1
- /* look at the next line to see if this is the first time */
- /* the user typed enter on this switch statement */
- if .line<=.last-2 then
- getline line,.line+2
- i=verify(line,' ')
- if i then
- if substr(line,i,1)='}' then
- compile if I_like_my_cases_under_my_switch
- if i>1 then
- i=i-1
- insertline substr(' ',1,i)'default:',.line+2
- else
- insertline 'default:',.line+2
- endif
- compile else
- i=i+SYNTAX_INDENT-1
- insertline substr(' ',1,i)'default:',.line+2
- compile endif
- compile if I_like_a_semicolon_supplied_after_default then
- insertline substr(' ',1,i+SYNTAX_INDENT)';',.line+3
- compile endif
- endif
- endif
- endif
- elseif a='{' or firstword='{' then /* firstword or last word {?*/
- ; if firstword='{' then
- ; replaceline wrd rest -- This shifts the { to col 1. Why???
- ; call einsert_line();.col=SYNTAX_INDENT+1
- ; else
- call einsert_line()
- .col=.col+SYNTAX_INDENT
- ; endif
- elseif firstword='MAIN' then
- call enter_main_heading()
- elseif firstword='DO' then
- insert
- .col=length(a)+2
- elseif pos('/*',line) then
- if not pos('*/',line) then
- end_line;keyin' */'
- endif
- call einsert_line()
- else
- retc=0
- endif
- else
- retc=0
- endif
- return retc
-
- defproc enter_main_heading
- compile if not USE_ANSI_C_NOTATION -- Use standard notation
- temp=substr('',1,SYNTAX_INDENT) /* indent spaces */
- replaceline 'main(argc, argv, envp)'
- insertline temp'int argc;',.line+1 /* double indent */
- insertline temp'char *argv[];',.line+2
- insertline temp'char *envp[];',.line+3
- insertline '{',.line+4
- insertline '',.line+5
- mainline = .line
- if .cursory<7 then
- .cursory=7
- endif
- mainline+5
- .col=SYNTAX_INDENT+1
- insertline '}',.line+1
- compile else -- Use shorter ANSII notation
- replaceline 'main(int argc, char *argv[], char *envp[])'
- insertline '{',.line+1
- insertline '',.line+2
- .col=SYNTAX_INDENT+1
- insertline '}',.line+3
- mainline = .line
- if .cursory<4 then
- .cursory=4
- endif
- mainline+2
- compile endif
-