home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / editors / epm / e_macros / ekeys.e < prev    next >
Encoding:
Text File  |  1993-09-29  |  7.0 KB  |  251 lines

  1. /*                    E      keys                       */
  2. /*                                                      */
  3. /* The enter and space bar keys have been defined to do */
  4. /* specific E3 syntax structures.                       */
  5.  
  6. compile if not defined(E_SYNTAX_INDENT)
  7. const
  8.    E_SYNTAX_INDENT = SYNTAX_INDENT
  9. compile endif
  10.  
  11.  
  12. compile if INCLUDING_FILE <> 'EXTRA.E'  -- Following only gets defined in the base
  13. compile if EVERSION >= '4.12'
  14. ;  Keyset selection is now done once at file load time, not every time
  15. ;  the file is selected.  And because the DEFLOAD procedures don't have to be
  16. ;  kept together in the macros (ET will concatenate all the DEFLOADs the
  17. ;  same way it does DEFINITs), we can put the DEFLOAD here where it belongs,
  18. ;  with the rest of the keyset function.  (what a concept!)
  19. ;
  20. defload
  21.    universal load_ext
  22. compile if EPM
  23.    universal load_var
  24. compile endif
  25.    if load_ext='E' then
  26.       keys   E_keys
  27.  compile if E_TABS <> 0
  28.   compile if EPM
  29.       if not (load_var // 2) then  -- 1 would be on if tabs set from EA EPM.TABS
  30.   compile endif
  31.       'tabs' E_TABS
  32.   compile if EPM
  33.       endif
  34.   compile endif
  35.  compile endif
  36.  compile if E_MARGINS <> 0
  37.   compile if EPM
  38.       if not (load_var%2 - 2*(load_var%4)) then  -- 2 would be on if tabs set from EA EPM.MARGINS
  39.   compile endif
  40.       'ma'   E_MARGINS
  41.   compile if EPM
  42.       endif
  43.   compile endif
  44.  compile endif
  45.    endif
  46. compile endif
  47.  
  48. compile if WANT_CUA_MARKING & EPM
  49.  defkeys e_keys clear
  50. compile else
  51.  defkeys e_keys
  52. compile endif
  53.  
  54. compile if EVERSION >= 5
  55. def space=
  56. compile else
  57. def ' '=
  58. compile endif
  59.    universal expand_on
  60.    if expand_on then
  61.       if  not e_first_expansion() then
  62.          keyin ' '
  63.       endif
  64.    else
  65.       keyin ' '
  66.    endif
  67.  compile if EVERSION >= '5.20'
  68.    undoaction 1, junk                -- Create a new state
  69.  compile endif
  70.  
  71. compile if ASSIST_TRIGGER = 'ENTER'
  72. def enter=
  73.  compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''
  74.    universal enterkey
  75.  compile endif
  76. compile else
  77. def c_enter=
  78.  compile if ENHANCED_ENTER_KEYS & c_ENTER_ACTION <> ''
  79.    universal c_enterkey
  80.  compile endif
  81. compile endif
  82.    universal expand_on
  83.  
  84. compile if EVERSION >= 5
  85.    if expand_on then
  86. compile else
  87.    if expand_on & not command_state() then
  88. compile endif
  89. compile if EVERSION >= '4.12'
  90.       if not e_second_expansion() then
  91. compile else
  92.       if e_second_expansion() then
  93.          call maybe_autosave()
  94.       else
  95. compile endif
  96. compile if ASSIST_TRIGGER = 'ENTER'
  97.  compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''
  98.          call enter_common(enterkey)
  99.  compile else
  100.          call my_enter()
  101.  compile endif
  102. compile else  -- ASSIST_TRIGGER
  103.  compile if ENHANCED_ENTER_KEYS & c_ENTER_ACTION <> ''
  104.          call enter_common(c_enterkey)
  105.  compile else
  106.          call my_c_enter()
  107.  compile endif
  108. compile endif -- ASSIST_TRIGGER
  109.       endif
  110.    else
  111. compile if ASSIST_TRIGGER = 'ENTER'
  112.  compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''
  113.       call enter_common(enterkey)
  114.  compile else
  115.       call my_enter()
  116.  compile endif
  117. compile else  -- ASSIST_TRIGGER
  118.  compile if ENHANCED_ENTER_KEYS & c_ENTER_ACTION <> ''
  119.       call enter_common(c_enterkey)
  120.  compile else
  121.       call my_c_enter()
  122.  compile endif
  123. compile endif -- ASSIST_TRIGGER
  124.    endif
  125.  
  126. /* Taken out, interferes with some people's c_enter. */
  127. ;def c_enter=   /* I like Ctrl-Enter to finish the comment field also. */
  128. ;   getline line
  129. ;   if pos('/*',line) then
  130. ;      if not pos('*/',line) then
  131. ;         end_line;keyin' */'
  132. ;      endif
  133. ;   endif
  134. ;   down;begin_line
  135.  
  136. def c_x=       /* Force expansion if we don't have it turned on automatic */
  137.    if not e_first_expansion() then
  138.       call e_second_expansion()
  139.    endif
  140. compile endif  -- EXTRA
  141.  
  142. compile if not EXTRA_EX or INCLUDING_FILE = 'EXTRA.E'  -- Following gets defined in EXTRA.EX if it's being used
  143. defproc e_first_expansion
  144.    /*  up;down */
  145.    retc=1
  146. compile if EVERSION >= 5
  147.    if .line then
  148. compile else
  149.    if .line and (not command_state()) then
  150. compile endif
  151.       getline line
  152.       line=strip(line,'T')
  153.       w=line
  154.       wrd=upcase(w)
  155.       if wrd='FOR' then
  156.          replaceline w' =  to'
  157.          insertline substr(wrd,1,length(wrd)-3)'endfor',.line+1
  158.          if not insert_state() then insert_toggle
  159.          endif
  160.          keyin ' '
  161.       elseif wrd='IF' then
  162.          replaceline w' then'
  163.          insertline substr(wrd,1,length(wrd)-2)'else',.line+1
  164.          insertline substr(wrd,1,length(wrd)-2)'endif',.line+2
  165.          if not insert_state() then insert_toggle
  166. compile if EVERSION >= '5.50'
  167.              call fixup_cursor()
  168. compile endif
  169.          endif
  170.          keyin ' '
  171.       elseif wrd='ELSEIF' then
  172.          replaceline w' then'
  173.          if not insert_state() then insert_toggle
  174. compile if EVERSION >= '5.50'
  175.              call fixup_cursor()
  176. compile endif
  177.          endif
  178.          keyin ' '
  179.       elseif wrd='WHILE' then
  180.          replaceline w' do'
  181.          insertline substr(wrd,1,length(wrd)-5)'endwhile',.line+1
  182.          if not insert_state() then insert_toggle
  183. compile if EVERSION >= '5.50'
  184.              call fixup_cursor()
  185. compile endif
  186.          endif
  187.          keyin ' '
  188.       elseif wrd='LOOP' then
  189.          replaceline w
  190.          insertline substr(wrd,1,length(wrd)-4)'endloop',.line+1
  191.          call einsert_line()
  192.          .col=.col+E_SYNTAX_INDENT
  193.       elseif wrd='DO' then
  194.          replaceline w
  195.          insertline substr(wrd,1,length(wrd)-2)'enddo',.line+1
  196.          call einsert_line()
  197.          .col=.col+E_SYNTAX_INDENT
  198.       else
  199.          retc=0
  200.       endif
  201.    else
  202.       retc=0
  203.    endif
  204.    return retc
  205.  
  206. defproc e_second_expansion
  207.    retc=1
  208.    if .line then
  209.       getline line
  210.       parse value line with wrd rest
  211.       firstword=upcase(wrd)
  212.       if firstword='FOR' then
  213.          /* do tabs to fields of pascal for statement */
  214.          parse value upcase(line) with a '='
  215.          if length(a)>=.col then
  216.             .col=length(a)+3
  217.          else
  218.             parse value upcase(line) with a 'TO'
  219.             if length(a)>=.col then
  220.                .col=length(a)+4
  221.             else
  222.                call einsert_line()
  223.                .col=.col+E_SYNTAX_INDENT
  224.             endif
  225.          endif
  226.       elseif firstword='IF' or firstword='ELSEIF' or firstword='WHILE' or firstword='LOOP' or firstword='DO' or firstword='ELSE' then
  227.          if pos('END'firstword, upcase(line)) then
  228.             retc = 0
  229.          else
  230.             call einsert_line()
  231.             .col=.col+E_SYNTAX_INDENT
  232.             if firstword='LOOP' | firstword='DO' then
  233.                insertline substr(line,1,.col-E_SYNTAX_INDENT-1)'end'lowcase(wrd), .line+1
  234.             endif
  235.          endif
  236.       elseif pos('/*',line) then
  237. ;     elseif substr(firstword,1,2)='/*' then  /*see speed requirements */
  238.          if not pos('*/',line) then
  239.             end_line;keyin' */'
  240.          endif
  241.          call einsert_line()
  242.       else
  243.          retc=0
  244.       endif
  245.    else
  246.       retc=0
  247.    endif
  248.    return retc
  249.  
  250. compile endif  -- EXTRA
  251.