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