home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / prodtool / epm / e_macros / ckeys.e < prev    next >
Encoding:
Text File  |  1992-04-23  |  10.6 KB  |  350 lines

  1. /*                    C keys                            */
  2. /*                                                      */
  3. /*  The enter and space bar keys have been defined to do*/
  4. /* specific C editing features.                         */
  5.  
  6. CONST
  7. compile if not defined(I_like_my_cases_under_my_switch)
  8.    I_like_my_cases_under_my_switch = 1
  9. compile endif
  10. compile if not defined(I_like_a_semicolon_supplied_after_default)
  11.    I_like_a_semicolon_supplied_after_default = 0
  12. compile endif
  13.  
  14. compile if EVERSION >= '4.12'
  15. ;  Keyset selection is now done once at file load time, not every time
  16. ;  the file is selected.  And because the DEFLOAD procedures don't have to be
  17. ;  kept together in the macros (ET will concatenate all the DEFLOADs the
  18. ;  same way it does DEFINITs), we can put the DEFLOAD here where it belongs,
  19. ;  with the rest of the keyset function.  (what a concept!)
  20. ;
  21. defload
  22. compile if EPM
  23.    universal load_var
  24. compile endif
  25.    ext = filetype()  --          C++        Data Base Manager
  26.    if ext='C' or ext='H' or ext='CPP' or ext='SQC' then
  27.       keys   C_keys
  28.  compile if C_TABS <> 0
  29.   compile if EPM
  30.       if not (load_var // 2) then  -- 1 would be on if tabs set from EA EPM.TABS
  31.   compile endif
  32.       'tabs' C_TABS
  33.   compile if EPM
  34.       endif
  35.   compile endif
  36.  compile endif
  37.  compile if C_MARGINS <> 0
  38.   compile if EPM
  39.       if not (load_var%2 - 2*(load_var%4)) then  -- 2 would be on if tabs set from EA EPM.MARGINS
  40.   compile endif
  41.       'ma'   C_MARGINS
  42.   compile if EPM
  43.       endif
  44.   compile endif
  45.  compile endif
  46.    endif
  47. compile endif
  48.  
  49. compile if WANT_CUA_MARKING & EPM
  50.  defkeys c_keys clear
  51. compile else
  52.  defkeys c_keys
  53. compile endif
  54.  
  55. compile if EVERSION >= 5
  56. def space=
  57. compile else
  58. def ' '=
  59. compile endif
  60.    universal expand_on
  61.    if expand_on then
  62.       if  not c_first_expansion() then
  63.          keyin ' '
  64.       endif
  65.    else
  66.       keyin ' '
  67.    endif
  68.  compile if EVERSION >= '5.20'
  69.    undoaction 1, junk                -- Create a new state
  70.  compile endif
  71.  
  72. compile if ASSIST_TRIGGER = 'ENTER'
  73. def enter=
  74.  compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''  
  75.    universal enterkey
  76.  compile endif
  77. compile else
  78. def c_enter=
  79.  compile if ENHANCED_ENTER_KEYS & c_ENTER_ACTION <> ''  
  80.    universal c_enterkey
  81.  compile endif
  82. compile endif
  83.    universal expand_on
  84.  
  85. compile if EVERSION >= 5
  86.    if expand_on then
  87. compile else
  88.    if expand_on & not command_state() then
  89. compile endif
  90. compile if EVERSION <= '4.12'
  91.       if c_second_expansion() then
  92.          call maybe_autosave()
  93.       else
  94. compile else
  95.       if not c_second_expansion() then
  96. compile endif
  97. compile if ASSIST_TRIGGER = 'ENTER'
  98.  compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''  
  99.          call enter_common(enterkey)
  100.  compile else
  101.          call my_enter()
  102.  compile endif
  103. compile else  -- ASSIST_TRIGGER
  104.  compile if ENHANCED_ENTER_KEYS & c_ENTER_ACTION <> ''  
  105.          call enter_common(c_enterkey)
  106.  compile else
  107.          call my_c_enter()
  108.  compile endif
  109. compile endif -- ASSIST_TRIGGER
  110.       endif
  111.    else
  112. compile if ASSIST_TRIGGER = 'ENTER'
  113.  compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''  
  114.       call enter_common(enterkey)
  115.  compile else
  116.       call my_enter()
  117.  compile endif
  118. compile else  -- ASSIST_TRIGGER
  119.  compile if ENHANCED_ENTER_KEYS & c_ENTER_ACTION <> ''  
  120.       call enter_common(c_enterkey)
  121.  compile else
  122.       call my_c_enter()
  123.  compile endif
  124. compile endif -- ASSIST_TRIGGER
  125.    endif
  126.  
  127. /* Taken out, interferes with some people's c_enter. */
  128. ;def c_enter=   /* I like Ctrl-Enter to finish the comment field also. */
  129. ;   getline line
  130. ;   if pos('/*',line) then
  131. ;      if not pos('*/',line) then
  132. ;         end_line;keyin' */'
  133. ;      endif
  134. ;   endif
  135. ;   down;begin_line
  136.  
  137. def c_x=       /* Force expansion if we don't have it turned on automatic */
  138.    if not c_first_expansion() then
  139.       call c_second_expansion()
  140.    endif
  141.  
  142. defproc c_first_expansion
  143.    retc=1
  144. compile if EVERSION >= 5
  145.    if .line then
  146. compile else
  147.    if .line and (not command_state()) then
  148. compile endif
  149.       getline line
  150.       line=strip(line,'T')
  151.       w=line
  152.       wrd=upcase(w)
  153.       if wrd='FOR' then
  154.          replaceline w' (; ; ) {'
  155.          insertline substr(wrd,1,length(wrd)-3)'} /* endfor */',.line+1
  156.          if not insert_state() then insert_toggle 
  157. compile if EVERSION >= '5.50'
  158.              call fixup_cursor()
  159. compile endif
  160.          endif
  161.          .col=.col+2
  162.       elseif wrd='IF' then
  163.          replaceline w' () {'
  164.          insertline substr(wrd,1,length(wrd)-2)'} else {',.line+1
  165.          insertline substr(wrd,1,length(wrd)-2)'} /* endif */',.line+2
  166.          if not insert_state() then insert_toggle 
  167. compile if EVERSION >= '5.50'
  168.              call fixup_cursor()
  169. compile endif
  170.          endif
  171.          .col=.col+2
  172.       elseif wrd='WHILE' then
  173.          replaceline w' () {'
  174.          insertline substr(wrd,1,length(wrd)-5)'} /* endwhile */',.line+1
  175.          if not insert_state() then insert_toggle 
  176. compile if EVERSION >= '5.50'
  177.              call fixup_cursor()
  178. compile endif
  179.          endif
  180.          .col=.col+2
  181.       elseif wrd='DO' then
  182.          replaceline w' {'
  183.          insertline substr(' ',1,length(wrd)-2,' ')'} while (  ); /* enddo */',.line+1
  184.          call einsert_line()
  185.          .col=.col+SYNTAX_INDENT    /* indent for new line */
  186.       elseif wrd='SWITCH' then
  187.          replaceline w' () {'
  188.          insertline substr(wrd,1,length(wrd)-6)'} /* endswitch */',.line+1
  189.          if not insert_state() then insert_toggle 
  190. compile if EVERSION >= '5.50'
  191.              call fixup_cursor()
  192. compile endif
  193.          endif
  194.          .col=.col+2    /* move cursor between parentheses of switch ()*/
  195.       elseif wrd='MAIN' then
  196.          call enter_main_heading()
  197.       else
  198.          retc=0
  199.       endif
  200.    else
  201.       retc=0
  202.    endif
  203.    return retc
  204.  
  205. defproc c_second_expansion
  206.    retc=1
  207.    if .line then
  208.       getline line
  209.       parse value upcase(line) with '{' +0 a
  210.       parse value line with wrd rest
  211.       i=verify(wrd,'({:;','M',1)-1
  212.       if i<=0 then i=length(wrd) endif
  213.       firstword=upcase(substr(wrd,1,i))
  214.       if firstword='FOR' then
  215.          /* do tabs to fields of C for statement */
  216.          cp=pos(';',line,.col)
  217.          if cp and cp>=.col then
  218.              .col=cp+2
  219.          else
  220.            cpn=pos(';',line,cp+1)
  221.            if cpn and (cpn>=.col) then
  222.              .col=cpn+2
  223.            else
  224.              call einsert_line()
  225.              .col=.col+SYNTAX_INDENT
  226.            endif
  227.          endif
  228.       elseif firstword='CASE' or firstword='DEFAULT' then
  229.          call einsert_line()
  230.          if .line>2 then  /* take a look at the previous line */
  231.             getline prevline,.line-2
  232.             prevline=upcase(prevline)
  233.             parse value prevline with w .
  234.             if w='CASE' then  /* align case statements */
  235.                i=pos('C',prevline)
  236.                replaceline substr('',1,i-1)||wrd rest,.line-1
  237.                .col=i
  238.             elseif w<>'CASE' and w<>'SWITCH' then  /* shift current line over */
  239.                i=verify(prevline,' ')
  240.                if i then .col=i endif
  241.                if i>SYNTAX_INDENT then i=i-SYNTAX_INDENT else i=1 endif
  242.                .col=i
  243.                replaceline substr('',1,i-1)||wrd rest,.line-1
  244.             endif
  245.             /* get rid of line containing just a ; */
  246.             if firstword='DEFAULT' and .line <.last then
  247.                getline line,.line+1
  248.                if line=';' then
  249.                   deleteline .line+1
  250.                endif
  251.             endif
  252.          endif
  253.          .col=.col+SYNTAX_INDENT
  254.       elseif firstword='BREAK' then
  255.          call einsert_line()
  256.          c=.col
  257.          if .col>SYNTAX_INDENT then
  258.             .col=.col-SYNTAX_INDENT
  259.          endif
  260.          keyin 'case :';left
  261.          insertline substr('',1,c-1)'break;',.line+1
  262.       elseif firstword='SWITCH' then
  263.          call einsert_line()
  264.          c=.col
  265. compile if I_like_my_cases_under_my_switch
  266.          keyin 'case :';left
  267. compile else
  268.          keyin substr(' ',1,SYNTAX_INDENT)'case :';left
  269.          c=c+SYNTAX_INDENT
  270. compile endif
  271.          insertline substr(' ',1,c+SYNTAX_INDENT-1)'break;',.line+1
  272.          /* look at the next line to see if this is the first time */
  273.          /* the user typed enter on this switch statement */
  274.          if .line<=.last-2 then
  275.             getline line,.line+2
  276.             i=verify(line,' ')
  277.             if i then
  278.                if substr(line,i,1)='}' then
  279. compile if I_like_my_cases_under_my_switch
  280.                   if i>1 then
  281.                      i=i-1
  282.                      insertline substr(' ',1,i)'default:',.line+2
  283.                   else
  284.                      insertline 'default:',.line+2
  285.                   endif
  286. compile else
  287.                   i=i+SYNTAX_INDENT-1
  288.                   insertline substr(' ',1,i)'default:',.line+2
  289. compile endif
  290. compile if I_like_a_semicolon_supplied_after_default then
  291.                   insertline substr(' ',1,i+SYNTAX_INDENT)';',.line+3
  292. compile endif
  293.                endif
  294.             endif
  295.          endif
  296.       elseif a='{' or firstword='{' then  /* firstword or last word {?*/
  297. ;        if firstword='{' then
  298. ;           replaceline  wrd rest      -- This shifts the { to col 1.  Why???
  299. ;           call einsert_line();.col=SYNTAX_INDENT+1
  300. ;        else
  301.             call einsert_line()
  302.             .col=.col+SYNTAX_INDENT
  303. ;        endif
  304.       elseif firstword='MAIN' then
  305.          call enter_main_heading()
  306.       elseif firstword='DO' then
  307.          insert
  308.          .col=length(a)+2
  309.       elseif pos('/*',line) then
  310.          if not pos('*/',line) then
  311.             end_line;keyin' */'
  312.          endif
  313.          call einsert_line()
  314.       else
  315.          retc=0
  316.       endif
  317.    else
  318.       retc=0
  319.    endif
  320.    return retc
  321.  
  322. defproc enter_main_heading
  323. compile if not USE_ANSI_C_NOTATION     -- Use standard notation
  324.    temp=substr('',1,SYNTAX_INDENT)  /* indent spaces */
  325.    replaceline 'main(argc, argv, envp)'
  326.    insertline temp'int argc;',.line+1         /* double indent */
  327.    insertline temp'char *argv[];',.line+2
  328.    insertline temp'char *envp[];',.line+3
  329.    insertline '{',.line+4
  330.    insertline '',.line+5
  331.    mainline = .line
  332.    if .cursory<7 then
  333.       .cursory=7
  334.    endif
  335.    mainline+5
  336.    .col=SYNTAX_INDENT+1
  337.    insertline '}',.line+1
  338. compile else                           -- Use shorter ANSII notation
  339.    replaceline 'main(int argc, char *argv[], char *envp[])'
  340.    insertline '{',.line+1
  341.    insertline '',.line+2
  342.    .col=SYNTAX_INDENT+1
  343.    insertline '}',.line+3
  344.    mainline = .line
  345.    if .cursory<4 then
  346.       .cursory=4
  347.    endif
  348.    mainline+2
  349. compile endif
  350.