home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / mlepm.zip / rcmode.e < prev    next >
Text File  |  1995-08-26  |  9KB  |  296 lines

  1. /* rcmode.e - this is the E part of the RC mode package      940522 */
  2.  
  3. /* The enter and space bar keys have been defined to do             */
  4. /* specific RC editing features.                                    */
  5.  
  6. /* 940522: Martin Lafaix (lafaix@sophia.inria.fr)                   */
  7. /*                                                                  */
  8. /*  .A new function : RC_mode.  It sets current editing mode to     */
  9. /*   be RC mode.                                                    */
  10. /*                                                                  */
  11. /* 940516: Martin Lafaix (lafaix@sophia.inria.fr)                   */
  12. /*                                                                  */
  13. /*  .Adapting ekeys.e to RC and hooks.                              */
  14. /*                                                                  */
  15.  
  16. /* This file is an adaptation of the EPM 'ekeys.e' E Macro file     */
  17.  
  18. compile if not defined(BLACK)
  19. const
  20.    my_rc_keys_is_external = 1
  21.    INCLUDING_FILE = 'RCMODE.E'
  22.    EXTRA_EX = 0
  23.    include 'stdconst.e'
  24. compile else
  25.    const my_rc_keys_is_external = 0
  26. compile endif
  27. compile if not defined(I_like_uppercase_keyword)
  28.    const I_like_uppercase_keyword = 1
  29. compile endif
  30.  
  31. compile if my_rc_keys_is_external = 1
  32.    C_TABS = 2
  33.    C_MARGINS = 1 MAXMARGIN 1
  34.    WANT_CUA_MARKING = 'SWITCH'
  35.    ASSIST_TRIGGER = 'ENTER'
  36.    ENHANCED_ENTER_KEYS = 1
  37.    ENTER_ACTION   = 'ADDATEND'
  38.    c_ENTER_ACTION = 'ADDLINE'
  39.    SYNTAX_INDENT = 2
  40. compile endif
  41.  
  42. compile if INCLUDING_FILE <> 'EXTRA.E'  -- Following only gets defined in the base
  43.  
  44. definit
  45. compile if my_rc_keys_is_external = 0
  46.    'maddhook load_hook rc_load_hook'
  47. compile endif
  48.  
  49. defc RC_mode
  50.    keys my_rc_keys
  51.    'msetfilemode RC mode'
  52.  
  53. defc rc_load_hook
  54.    universal load_ext
  55.    universal load_var
  56.    if load_ext='RC' | load_ext='DLG' then
  57.  compile if C_TABS <> 0
  58.       if not (load_var // 2) then  -- 1 would be on if tabs set from EA EPM.TABS
  59.          'tabs' C_TABS
  60.       endif
  61.  compile endif
  62.  compile if C_MARGINS <> 0
  63.       if not (load_var%2 - 2*(load_var%4)) then  -- 2 would be on if tabs set from EA EPM.MARGINS
  64.          'ma'   C_MARGINS
  65.       endif
  66.  compile endif
  67.       'RC_mode'
  68.    endif
  69.  
  70. compile if WANT_CUA_MARKING & EPM
  71.  defkeys my_rc_keys clear
  72. compile else
  73.  defkeys my_rc_keys
  74. compile endif
  75.  
  76. def space=
  77.    universal expand_on
  78.    if expand_on then
  79.       if  not my_rc_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 ML_autoindent
  99.    universal expand_on
  100.  
  101.    if expand_on then
  102.       if not my_rc_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. /* Taken out, interferes with some people's c_enter. */
  137. ;def c_enter=   /* I like Ctrl-Enter to finish the comment field also. */
  138. ;   getline line
  139. ;   if pos('/*',line) then
  140. ;      if not pos('*/',line) then
  141. ;         end_line;keyin' */'
  142. ;      endif
  143. ;   endif
  144. ;   down;begin_line
  145.  
  146. def c_x=       /* Force expansion if we don't have it turned on automatic */
  147.    if not my_rc_first_expansion() then
  148.       call my_rc_second_expansion()
  149.    endif
  150.  
  151. defc indent_rc_line
  152.    call indent_pos()
  153. compile endif  -- EXTRA
  154.  
  155. compile if not EXTRA_EX or INCLUDING_FILE = 'EXTRA.E'  -- Following gets defined in EXTRA.EX if it's being used
  156. defproc my_rc_first_expansion
  157.    /*  up;down */
  158.    retc=1
  159.    if .line then
  160.       getline line
  161.       line=strip(line,'T')
  162.       w=line
  163.       wrd=upcase(w)
  164.       firstwrd=strip(wrd,'L')
  165.       if wrd='SUBMENU' then
  166. compile if I_like_uppercase_keyword
  167.          replaceline wrd' "", '
  168. compile else
  169.          replaceline w' "", '
  170. compile endif
  171.          if not insert_state() then insert_toggle
  172.          endif
  173.          .col=.col+2
  174.       elseif wrd='STRINGTABLE' then
  175. compile if I_like_uppercase_keyword
  176.          replaceline wrd
  177. compile endif
  178.          insertline substr(wrd,1,length(wrd)-11)'BEGIN',.line+1
  179.          insertline substr(wrd,1,length(wrd)-11)'END',.line+2
  180.          .line=.line+1
  181.          if not insert_state() then insert_toggle
  182.              call fixup_cursor()
  183.          endif
  184.          call einsert_line()
  185.          .col=.col+SYNTAX_INDENT
  186.       elseif wrd='BEGIN' then
  187. compile if I_like_uppercase_keyword
  188.          replaceline wrd
  189. compile endif
  190.          insertline substr(wrd,1,length(wrd)-5)'END',.line+1
  191.          call einsert_line()
  192.          .col=.col+SYNTAX_INDENT
  193. compile if I_like_uppercase_keyword
  194.       elseif pos(firstwrd,'MENU DLGTEMPLATE ACCELTABLE MENUITEM') |
  195.              pos(firstwrd,'ASSOCTABLE AUTOCHECKBOX AUTORADIOBUTTON BITMAP') |
  196.              pos(firstwrd,'CHECKBOX CODEPAGE COMBOBOX CONTAINER CONTROL CTEXT') |
  197.              pos(firstwrd,'CTLDATA DEFPUSHBUTTON DIALOG DLGINCLUDE EDITTEXT') |
  198.              pos(firstwrd,'ENTRYFIELD FONT FRAME GROUPBOX HELPITEM HELPSUBITEM') |
  199.              pos(firstwrd,'HELPSUBTABLE HELPTABLE ICON LISTBOX LTEXT') |
  200.              pos(firstwrd,'MESSAGETABLE MLE NOTEBOOK POINTER PRESPARAMS PUSHBUTTON') |
  201.              pos(firstwrd,'RADIOBUTTON RCDATA RCINCLUDE RESOURCE RTEXT SLIDER') |
  202.              pos(firstwrd,'SPINBUTTON SUBITEMSIZE VALUESET WINDOW') |
  203.              pos(firstwrd,'WINDOWTEMPLATE') then
  204.           replaceline wrd
  205.          keyin ' '
  206. compile endif
  207.       else
  208.          retc=0
  209.       endif
  210.    else
  211.       retc=0
  212.    endif
  213.    return retc
  214.  
  215. defproc my_rc_second_expansion
  216.    retc=1
  217.    if .line then
  218.       getline line
  219.       parse value line with wrd rest
  220.       firstword=upcase(wrd)
  221.       if firstword='SUBMENU' then
  222.          /* do tabs to fields of pascal for statement */
  223.          parse value upcase(line) with a ','
  224.          if length(a)>=.col then
  225.             .col=length(a)+3
  226.          else
  227.             insertline substr(line,1,pos(wrd,line)-1)'  BEGIN',.line+1
  228.             insertline substr(line,1,pos(wrd,line)-1)'  END',.line+2
  229.             .line=.line+1
  230.             call einsert_line()
  231.             .col=.col+SYNTAX_INDENT
  232.          endif
  233.       elseif firstword='MENU' then
  234.          insertline substr(line,1,pos(wrd,line)-1)'BEGIN',.line+1
  235.          insertline substr(line,1,pos(wrd,line)-1)'END',.line+2
  236.          .line=.line+1
  237.          call einsert_line()
  238.          .col=.col+SYNTAX_INDENT
  239.       elseif firstword='ACCELTABLE' then
  240.          insertline substr(line,1,pos(wrd,line)-1)'BEGIN',.line+1
  241.          insertline substr(line,1,pos(wrd,line)-1)'END',.line+2
  242.          .line=.line+1
  243.          call einsert_line()
  244.          .col=.col+SYNTAX_INDENT
  245.       else
  246.          retc=0
  247.       endif
  248.    else
  249.       retc=0
  250.    endif
  251.    return retc
  252.  
  253. defproc indent_pos  /* Indent current line */
  254.    if .line then
  255.       oldline=.line
  256.       .line=.line-1
  257.       while .line & textline(.line)='' do
  258.          .line=.line-1
  259.       endwhile
  260.       if .line then
  261.          call pfirst_nonblank()
  262.          getline line
  263.          line=strip(line,'T')
  264.          parse value line with wrd rest
  265.          i=verify(wrd,'({:;','M',1)-1
  266.          if i<=0 then i=length(wrd) endif
  267.          firstword=upcase(substr(wrd,1,i))
  268.          if firstword='BEGIN' then
  269.             .col=.col+SYNTAX_INDENT
  270.          elseif firstword='END' then
  271.             .col=max(1,.col-SYNTAX_INDENT)
  272.          endif
  273.       else
  274.          .col=1
  275.       endif
  276.       newpos=.col
  277.       .line=oldline
  278.       call pfirst_nonblank()
  279.       if .col<newpos then
  280.          for i=1 to newpos-.col
  281.             keyin ' '
  282.          endfor
  283.       elseif .col>newpos then
  284.          delta=.col-newpos; .col=.col-delta
  285.          for i=1 to delta
  286.             deletechar
  287.          endfor
  288.       endif
  289.    endif
  290.  
  291. compile endif  -- EXTRA
  292.  
  293. compile if EVERSION >= 6
  294.    EA_comment 'This is a resource file (.RC and .DLG) editing mode, with automatic syntax expansion and indentation'
  295. compile endif
  296.