home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / mlepm.zip / rexxmode.e < prev    next >
Text File  |  1995-09-14  |  8KB  |  246 lines

  1. /* rexxmode.e - this is the E part of the Rexx mode package  940522 */
  2.  
  3. /* The enter and space bar keys have been defined to do             */
  4. /* specific REXX editing features.                                  */
  5.  
  6. /* 940522: Martin Lafaix (lafaix@sophia.inria.fr)                   */
  7. /*                                                                  */
  8. /*  .A new function : REXX_mode.  It sets current editing mode to   */
  9. /*   be REXX mode.                                                  */
  10. /*                                                                  */
  11. /* 940510: Martin Lafaix (lafaix@sophia.inria.fr)                   */
  12. /*                                                                  */
  13. /*  .Adapting rexxkeys.e to hooks.                                  */
  14. /*                                                                  */
  15.  
  16. /* This file is an adaptation of the EPM 'rexxkeys.e' E Macro file  */
  17.  
  18. compile if not defined(BLACK)
  19. const
  20.    my_rexx_keys_is_external = 1
  21.    INCLUDING_FILE = 'REXXMODE.E'
  22.    EXTRA_EX = 0
  23.    include 'stdconst.e'
  24. compile else
  25.    const my_rexx_keys_is_external = 0
  26. compile endif
  27.  
  28. compile if my_rexx_keys_is_external = 1
  29.    REXX_TABS = 3
  30.    REXX_MARGINS = 1 MAXMARGIN 1
  31.    WANT_CUA_MARKING = 'SWITCH'
  32.    ASSIST_TRIGGER = 'ENTER'
  33.    ENHANCED_ENTER_KEYS = 1
  34.    ENTER_ACTION   = 'ADDATEND'
  35.    c_ENTER_ACTION = 'ADDLINE'
  36.    SYNTAX_INDENT = 3
  37. compile endif
  38.  
  39. compile if INCLUDING_FILE <> 'EXTRA.E'  -- Following only gets defined in the base
  40.  
  41. definit
  42. compile if my_rexx_keys_is_external = 0
  43.    'maddhook load_hook rexx_load_hook'
  44. compile endif
  45.  
  46. defc REXX_mode
  47.    keys my_rexx_keys
  48.    'msetfilemode REXX mode'
  49.  
  50. defc rexx_load_hook
  51.    universal load_ext
  52.    universal load_var
  53.    if load_ext='BAT' | load_ext='CMD' | load_ext='EXC' | load_ext='EXEC' | load_ext='XEDIT' | load_ext='ERX' then
  54.       getline line,1
  55.       if substr(line,1,2)='/*' or (line='' & .last = 1) then
  56.  compile if REXX_TABS <> 0
  57.          if not (load_var // 2) then  -- 1 would be on if tabs set from EA EPM.TABS
  58.             'tabs' REXX_TABS
  59.          endif
  60.  compile endif
  61.  compile if REXX_MARGINS <> 0
  62.          if not (load_var%2 - 2*(load_var%4)) then  -- 2 would be on if tabs set from EA EPM.MARGINS
  63.             'ma'   REXX_MARGINS
  64.          endif
  65.  compile endif
  66.          'REXX_mode'
  67.       endif
  68.    endif
  69.  
  70. compile if WANT_CUA_MARKING & EPM
  71.  defkeys my_rexx_keys clear
  72. compile else
  73.  defkeys my_rexx_keys
  74. compile endif
  75.  
  76. def space=
  77.    universal expand_on
  78.    if expand_on then
  79.       if not rex_first_expansion() then
  80.          keyin ' '
  81.       endif
  82.    else
  83.       keyin ' '
  84.    endif
  85.    undoaction 1, junk                -- Create a new state
  86.  
  87. compile if ASSIST_TRIGGER = 'ENTER'
  88. def enter=
  89.  compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''
  90.    universal enterkey
  91.  compile endif
  92. compile else
  93. def c_enter=
  94.  compile if ENHANCED_ENTER_KEYS & c_ENTER_ACTION <> ''
  95.    universal c_enterkey
  96.  compile endif
  97. compile endif
  98.    universal expand_on
  99.    universal ML_autoindent
  100.  
  101.    if expand_on then
  102.       if not rex_second_expansion() then
  103. compile if ASSIST_TRIGGER = 'ENTER'
  104.  compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''
  105.          call enter_common(enterkey)
  106.  compile else
  107.          call my_enter()
  108.  compile endif
  109. compile else  -- ASSIST_TRIGGER
  110.  compile if ENHANCED_ENTER_KEYS & c_ENTER_ACTION <> ''
  111.          call enter_common(c_enterkey)
  112.  compile else
  113.          call my_c_enter()
  114.  compile endif
  115. compile endif -- ASSIST_TRIGGER
  116.          if Ml_autoindent then
  117.             call indent_pos()
  118.          endif
  119.       endif
  120.    else
  121. compile if ASSIST_TRIGGER = 'ENTER'
  122.  compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''
  123.       call enter_common(enterkey)
  124.  compile else
  125.       call my_enter()
  126.  compile endif
  127. compile else  -- ASSIST_TRIGGER
  128.  compile if ENHANCED_ENTER_KEYS & c_ENTER_ACTION <> ''
  129.       call enter_common(c_enterkey)
  130.  compile else
  131.       call my_c_enter()
  132.  compile endif
  133. compile endif -- ASSIST_TRIGGER
  134.    endif
  135.  
  136. def c_x=       -- Force expansion if we don't have it turned on automatic
  137.    if not rex_first_expansion() then
  138.       call rex_second_expansion()
  139.    endif
  140.  
  141. defc indent_rexx_line
  142.    call indent_pos()
  143. compile endif  -- EXTRA
  144.  
  145. compile if not EXTRA_EX or INCLUDING_FILE = 'EXTRA.E'  -- Following gets defined in EXTRA.EX if it's being used
  146. defproc rex_first_expansion            -- Called by space bar
  147.    retc = 0                            -- Default, enter a space
  148.    if .line then
  149.       w=strip(textline(.line),'T')
  150.       wrd=upcase(w)
  151.       If wrd='IF' Then
  152.          replaceline w' then'
  153.          insertline substr(wrd,1,length(wrd)-2)'else',.line+1
  154.          if not insert_state() then insert_toggle
  155.              call fixup_cursor()
  156.          endif
  157.       elseif wrd='WHEN' Then
  158.          replaceline w' then'
  159.          if not insert_state() then insert_toggle
  160.              call fixup_cursor()
  161.          endif
  162.       elseif wrd='DO' Then
  163.          insertline substr(wrd,1,length(wrd)-2)'end /* do */',.line+1
  164. ;        if not insert_state() then insert_toggle endif
  165.       endif
  166.    endif
  167.    return retc
  168.  
  169. defproc rex_second_expansion
  170.    retc=1                               -- Default, don't insert a line
  171.    if .line then
  172.       getline line
  173.       line = upcase(line)
  174.       parse value line with firstword .
  175.       c=max(1,verify(line,' '))-1  -- Number of blanks before first word.
  176.  
  177.       If firstword='SELECT' then
  178.          insertline substr('',1,c+SYNTAX_INDENT)'when',.line+1
  179.          insertline substr('',1,c /*+SYNTAX_INDENT*/)'otherwise',.line+2
  180.          insertline substr('',1,c)'end  /* select */',.line+3
  181.          '+1'                             -- Move to When clause
  182.          .col = c+SYNTAX_INDENT+5         -- Position the cursor
  183.       Elseif firstword = 'DO' then
  184.          call einsert_line()
  185.          .col=.col+SYNTAX_INDENT
  186.       Elseif Pos('THEN DO',line) > 0 or Pos('ELSE DO',line) > 0 Then
  187.          call einsert_line()
  188.          .col=.col+SYNTAX_INDENT
  189.          insertline substr('',1,c)'end  /* Do */',.line+1
  190. ;     Elseif pos('/*',line) then          -- Annoying to me, as I don't always
  191. ;        if not pos('*/',line) then       -- want a comment closed on that line
  192. ;           end_line;keyin' */'           -- Enable if you wish by uncommenting
  193. ;        endif
  194. ;        call einsert_line()
  195.       Else
  196.          retc = 0                         -- Insert a blank line
  197.       Endif
  198.    Else
  199.       retc=0
  200.    Endif
  201.    Return(retc)
  202.  
  203. defproc indent_pos  /* Indent current line */
  204.    if .line then
  205.       oldline=.line
  206.       .line=.line-1
  207.       while .line & textline(.line)='' do
  208.          .line=.line-1
  209.       endwhile
  210.       if .line then
  211.          call pfirst_nonblank()
  212.          getline line
  213.          line=strip(line,'T')
  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 = 'DO' | firstword='OTHERWISE' then
  219.             .col=.col+SYNTAX_INDENT
  220.          elseif pos('THEN DO',line) | pos('ELSE DO',line) then
  221.             .col=.col+SYNTAX_INDENT
  222.          endif
  223.       else
  224.          .col=1
  225.       endif
  226.       newpos=.col
  227.       .line=oldline
  228.       call pfirst_nonblank()
  229.       if .col<newpos then
  230.          for i=1 to newpos-.col
  231.             keyin ' '
  232.          endfor
  233.       elseif .col>newpos then
  234.          delta=.col-newpos; .col=.col-delta
  235.          for i=1 to delta
  236.             deletechar
  237.          endfor
  238.       endif
  239.    endif
  240.  
  241. compile endif  -- EXTRA
  242.  
  243. compile if EVERSION >= 6
  244.    EA_comment 'This is a REXX editing mode, with automatic syntax expansion and indentation'
  245. compile endif
  246.