home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmmac.zip / REXXKEYS.E < prev    next >
Text File  |  1996-02-06  |  12KB  |  358 lines

  1. /**********************************************************************/
  2. /*                             REXKEYS.E                              */
  3. /*                                                                    */
  4. /* The c_enter and space bar keys have been defined to do specific    */
  5. /* REXX syntax structures.                                            */
  6. /*                                                                    */
  7. /* Based on EKEYS.E (part of the base E3 code)                        */
  8. /* Written by B. Thompson, 22 Sep 1987                                */
  9. /*                                                                    */
  10. /**********************************************************************/
  11. /*  Updated by Larry Margolis for EOS2 and EPM.  To include, set in   */
  12. /*  your MYCNF.E:   REXX_SYNTAX_ASSIST = 1                            */
  13. /*                                                                    */
  14. /**********************************************************************/
  15.  
  16. const
  17. compile if not defined(REXX_SYNTAX_INDENT)
  18.    REXX_SYNTAX_INDENT = SYNTAX_INDENT
  19. compile endif
  20. compile if not defined(TERMINATE_COMMENTS)
  21.    TERMINATE_COMMENTS = 0
  22. compile endif
  23. compile if not defined(REXX_KEYWORD_HIGHLIGHTING)
  24.    REXX_KEYWORD_HIGHLIGHTING = 0
  25. compile endif
  26. compile if not defined(WANT_END_COMMENTED)
  27.    WANT_END_COMMENTED = 1
  28. compile endif
  29. compile if not defined(REXX_EXTENSIONS)  -- Keep in sync with TAGS.E
  30.    REXX_EXTENSIONS = 'BAT CMD ERX EXC EXEC XEDIT REX REXX VRX'
  31. compile endif
  32. compile if not defined(REXX_SYNTAX_CASE)
  33.    REXX_SYNTAX_CASE = 'lower'
  34. compile endif
  35. compile if not defined(REXX_SYNTAX_FORCE_CASE)
  36.    REXX_SYNTAX_FORCE_CASE = 0
  37. compile endif
  38. compile if not defined(REXX_SYNTAX_NO_ELSE)
  39.    REXX_SYNTAX_NO_ELSE = 0
  40. compile endif
  41.  
  42. compile if REXX_SYNTAX_CASE <> 'lower' & REXX_SYNTAX_CASE <> 'Mixed'
  43.    *** Error: REXX_SYNTAX_CASE must be "Lower" or "Mixed"
  44. compile endif
  45.  
  46. compile if INCLUDING_FILE <> 'EXTRA.E'  -- Following only gets defined in the base
  47. compile if EVERSION >= '4.12'
  48. defload
  49.    universal load_ext
  50. compile if EPM
  51.    universal load_var
  52. compile endif
  53. compile if EVERSION >= '5.50'
  54.    if wordpos(load_ext, REXX_EXTENSIONS) then
  55. compile else
  56.    if load_ext='BAT' | load_ext='CMD' | load_ext='EXC' | load_ext='EXEC' | load_ext='XEDIT' | load_ext='ERX' then
  57. compile endif
  58.       getline line,1
  59.       if substr(line,1,2)='/*' or (line='' & .last = 1) then
  60.          keys   rexx_keys
  61.  compile if REXX_TABS <> 0
  62.   compile if EPM
  63.          if not (load_var // 2) then  -- 1 would be on if tabs set from EA EPM.TABS
  64.   compile endif
  65.          'tabs' REXX_TABS
  66.   compile if EPM
  67.          endif
  68.   compile endif
  69.  compile endif
  70.  compile if REXX_MARGINS <> 0
  71.   compile if EPM
  72.    compile if EVERSION >= '6.01b'
  73.          if not (load_var bitand 2) then  -- 2 would be on if tabs set from EA EPM.MARGINS
  74.    compile else
  75.          if not (load_var%2 - 2*(load_var%4)) then  -- 2 would be on if tabs set from EA EPM.MARGINS
  76.    compile endif
  77.   compile endif
  78.          'ma'   REXX_MARGINS
  79.   compile if EPM
  80.          endif
  81.   compile endif
  82.  compile endif
  83.       endif
  84.  compile if REXX_KEYWORD_HIGHLIGHTING and EPM32
  85.       if .visible then
  86.          'toggle_parse 1 epmkwds.cmd'
  87.       endif
  88.  compile endif
  89.    endif
  90. compile endif
  91.  
  92. compile if WANT_CUA_MARKING & EPM
  93.  defkeys rexx_keys clear
  94. compile else
  95.  defkeys rexx_keys
  96. compile endif
  97.  
  98. compile if EVERSION >= 5
  99. def space=
  100. compile else
  101. def ' '=
  102. compile endif
  103.    universal expand_on
  104.    if expand_on then
  105.       if not rex_first_expansion() then
  106.          keyin ' '
  107.       endif
  108.    else
  109.       keyin ' '
  110.    endif
  111.  compile if EVERSION >= '5.20'
  112.    undoaction 1, junk                -- Create a new state
  113.  compile endif
  114.  
  115. compile if ASSIST_TRIGGER = 'ENTER'
  116. def enter=
  117.  compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''
  118.    universal enterkey
  119.  compile endif
  120. compile else
  121. def c_enter=
  122.  compile if ENHANCED_ENTER_KEYS & c_ENTER_ACTION <> ''
  123.    universal c_enterkey
  124.  compile endif
  125. compile endif
  126.    universal expand_on
  127.  
  128. compile if EVERSION >= 5
  129.    if expand_on then
  130. compile else
  131.    if expand_on & not command_state() then
  132. compile endif
  133. compile if EVERSION >= '4.12'
  134.       if not rex_second_expansion() then
  135. compile else
  136.       if rex_second_expansion() then
  137.          call maybe_autosave()
  138.       else
  139. compile endif
  140. compile if ASSIST_TRIGGER = 'ENTER'
  141.  compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''
  142.          call enter_common(enterkey)
  143.  compile else
  144.          call my_enter()
  145.  compile endif
  146. compile else  -- ASSIST_TRIGGER
  147.  compile if ENHANCED_ENTER_KEYS & c_ENTER_ACTION <> ''
  148.          call enter_common(c_enterkey)
  149.  compile else
  150.          call my_c_enter()
  151.  compile endif
  152. compile endif -- ASSIST_TRIGGER
  153.       endif
  154.    else
  155. compile if ASSIST_TRIGGER = 'ENTER'
  156.  compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''
  157.       call enter_common(enterkey)
  158.  compile else
  159.       call my_enter()
  160.  compile endif
  161. compile else  -- ASSIST_TRIGGER
  162.  compile if ENHANCED_ENTER_KEYS & c_ENTER_ACTION <> ''
  163.       call enter_common(c_enterkey)
  164.  compile else
  165.       call my_c_enter()
  166.  compile endif
  167. compile endif -- ASSIST_TRIGGER
  168.    endif
  169.  
  170. def c_x=       -- Force expansion if we don't have it turned on automatic
  171.    if not rex_first_expansion() then
  172.       call rex_second_expansion()
  173.    endif
  174. compile endif  -- EXTRA
  175.  
  176. compile if not EXTRA_EX or INCLUDING_FILE = 'EXTRA.E'  -- Following gets defined in EXTRA.EX if it's being used
  177. defproc rex_first_expansion            -- Called by space bar
  178.    retc = 0                            -- Default, enter a space
  179. compile if EVERSION >= 5
  180.    if .line then
  181. compile else
  182.    if .line and (not command_state()) then
  183. compile endif
  184.       w=strip(textline(.line),'T')
  185.       wrd=upcase(w)
  186. compile if REXX_SYNTAX_FORCE_CASE
  187.       lb=copies(' ', max(1,verify(w,' '))-1)  -- Number of blanks before first word.
  188. compile endif
  189.       If wrd='IF' Then
  190. compile if REXX_SYNTAX_CASE = 'lower'
  191.  compile if REXX_SYNTAX_FORCE_CASE
  192.          replaceline lb'if then'
  193.  compile else
  194.          replaceline w' then'
  195.  compile endif
  196.  compile if not REXX_SYNTAX_NO_ELSE
  197.          insertline substr(wrd,1,length(wrd)-2)'else',.line+1
  198.  compile endif
  199. compile else
  200.  compile if REXX_SYNTAX_FORCE_CASE
  201.          replaceline lb'If Then'
  202.  compile else
  203.          replaceline w' Then'
  204.  compile endif
  205.  compile if not REXX_SYNTAX_NO_ELSE
  206.          insertline substr(wrd,1,length(wrd)-2)'Else',.line+1
  207.  compile endif
  208. compile endif
  209.          if not insert_state() then insert_toggle
  210. compile if EVERSION >= '5.50'
  211.              call fixup_cursor()
  212. compile endif
  213.          endif
  214.       elseif wrd='WHEN' Then
  215. compile if REXX_SYNTAX_CASE = 'lower'
  216.  compile if REXX_SYNTAX_FORCE_CASE
  217.          replaceline lb'when then'
  218.  compile else
  219.          replaceline w' then'
  220.  compile endif
  221. compile else
  222.  compile if REXX_SYNTAX_FORCE_CASE
  223.          replaceline lb'When Then'
  224.  compile else
  225.          replaceline w' Then'
  226.  compile endif
  227. compile endif
  228.          if not insert_state() then insert_toggle
  229. compile if EVERSION >= '5.50'
  230.              call fixup_cursor()
  231. compile endif
  232.          endif
  233.       elseif wrd='DO' Then
  234. compile if REXX_SYNTAX_FORCE_CASE
  235.  compile if REXX_SYNTAX_CASE = 'lower'
  236.          replaceline lb'do'
  237.  compile else
  238.          replaceline lb'Do'
  239.  compile endif
  240. compile endif
  241. compile if WANT_END_COMMENTED
  242.  compile if REXX_SYNTAX_CASE = 'lower'
  243.          insertline substr(wrd,1,length(wrd)-2)'end /* do */',.line+1
  244.  compile else
  245.          insertline substr(wrd,1,length(wrd)-2)'End /* Do */',.line+1
  246.  compile endif
  247. compile else
  248.  compile if REXX_SYNTAX_CASE = 'lower'
  249.          insertline substr(wrd,1,length(wrd)-2)'end',.line+1
  250.  compile else
  251.          insertline substr(wrd,1,length(wrd)-2)'End',.line+1
  252.  compile endif
  253. compile endif
  254. ;        if not insert_state() then insert_toggle endif
  255.       endif
  256.    endif
  257.    return retc
  258.  
  259. defproc rex_second_expansion
  260.    retc=1                               -- Default, don't insert a line
  261.    if .line then
  262.       getline line
  263. compile if REXX_SYNTAX_FORCE_CASE
  264.       parse value line with origword .
  265. compile endif
  266.       line = upcase(line)
  267.       parse value line with firstword .
  268.       c=max(1,verify(line,' '))-1  -- Number of blanks before first word.
  269.  
  270.       If firstword='SELECT' then
  271. compile if REXX_SYNTAX_FORCE_CASE
  272.  compile if REXX_SYNTAX_CASE = 'lower'
  273.          if origword<>'select' then replaceline overlay('select', textline(.line), c+1); endif
  274.  compile else
  275.          if origword<>'Select' then replaceline overlay('Select', textline(.line), c+1); endif
  276.  compile endif
  277. compile endif
  278. compile if REXX_SYNTAX_CASE = 'lower'
  279.          insertline substr('',1,c+REXX_SYNTAX_INDENT)'when',.line+1
  280.          insertline substr('',1,c /*+REXX_SYNTAX_INDENT*/)'otherwise',.line+2
  281.  compile if WANT_END_COMMENTED
  282.          insertline substr('',1,c)'end  /* select */',.line+3
  283.  compile else
  284.          insertline substr('',1,c)'end',.line+3
  285.  compile endif
  286. compile else
  287.          insertline substr('',1,c+REXX_SYNTAX_INDENT)'When',.line+1
  288.          insertline substr('',1,c /*+REXX_SYNTAX_INDENT*/)'Otherwise',.line+2
  289.  compile if WANT_END_COMMENTED
  290.          insertline substr('',1,c)'End  /* Select */',.line+3
  291.  compile else
  292.          insertline substr('',1,c)'End',.line+3
  293.  compile endif
  294. compile endif
  295.          '+1'                             -- Move to When clause
  296.          .col = c+REXX_SYNTAX_INDENT+5         -- Position the cursor
  297.       Elseif firstword = 'DO' then
  298. compile if REXX_SYNTAX_FORCE_CASE
  299.  compile if REXX_SYNTAX_CASE = 'lower'
  300.          if origword<>'do' then replaceline overlay('do', textline(.line), c+1); endif
  301.  compile else
  302.          if origword<>'Do' then replaceline overlay('Do', textline(.line), c+1); endif
  303.  compile endif
  304. compile endif
  305.          call einsert_line()
  306.          .col=.col+REXX_SYNTAX_INDENT
  307.       Elseif Pos('THEN DO',line) > 0 or Pos('ELSE DO',line) > 0 Then
  308.          p = Pos('ELSE DO',line)  -- Don't be faked out by 'else doc = 5'
  309.          if not p then
  310.             p = Pos('THEN DO',line)
  311. compile if REXX_SYNTAX_FORCE_CASE
  312.  compile if REXX_SYNTAX_CASE = 'lower'
  313.             s1 = 'then do'
  314.          else
  315.             s1 = 'else do'
  316.  compile else
  317.             s1 = 'Then Do'
  318.          else
  319.             s1 = 'Else Do'
  320.  compile endif
  321. compile endif
  322.          endif
  323.          if p & not pos(substr(line, p+7, 1), ' ;') then return 0; endif
  324. compile if REXX_SYNTAX_FORCE_CASE
  325.          if substr(textline(.line), p, 7)<>s1 then replaceline overlay(s1, textline(.line), p); endif
  326. compile endif
  327.          call einsert_line()
  328.          .col=.col+REXX_SYNTAX_INDENT
  329. compile if WANT_END_COMMENTED
  330.  compile if REXX_SYNTAX_CASE = 'lower'
  331.          insertline substr('',1,c)'end /* do */',.line+1
  332.  compile else
  333.          insertline substr('',1,c)'End /* Do */',.line+1
  334.  compile endif
  335. compile else
  336.  compile if REXX_SYNTAX_CASE = 'lower'
  337.          insertline substr('',1,c)'end',.line+1
  338.  compile else
  339.          insertline substr('',1,c)'End',.line+1
  340.  compile endif
  341. compile endif
  342. compile if TERMINATE_COMMENTS
  343.       Elseif pos('/*',line) then          -- Annoying to me, as I don't always
  344.          if not pos('*/',line) then       -- want a comment closed on that line
  345.             end_line; keyin' */'          -- Enable if you wish by uncommenting
  346.          endif
  347.          call einsert_line()
  348. compile endif
  349.       Else
  350.          retc = 0                         -- Insert a blank line
  351.       Endif
  352.    Else
  353.       retc=0
  354.    Endif
  355.    Return(retc)
  356.  
  357. compile endif  -- EXTRA
  358.