home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmkmap1.zip / STDKEYS.E < prev    next >
Text File  |  1995-10-04  |  70KB  |  2,341 lines

  1. /*
  2.  * StdKeys.e  :  A patched StdKeys.e file for use with KeyMap.e
  3.  *               04/1995 by Herbert
  4.  * What has changed?
  5.  *  - All actions performed by single keystrokes have been changed to
  6.  *    constructions like 'def <keyname> = call <procname>' followed by
  7.  *    'defproc <procname>', so every key command now has its own name.
  8.  *  - Every standard key binding can now be overridden easily by just
  9.  *    one line in your mykeys.e file. Of course this concept makes it
  10.  *    all a bit slower, but don't forget - what makes EPM remarkably slow
  11.  *    sometimes is not the time it needs to load a routine after a function
  12.  *    key has been pressed, it's almost always the PM...
  13.  * The main idea is to make the keymap easily configurable - even for people
  14.  * with little or no knowledge about e programming. Hope old EPMers are not
  15.  * going to crucify me for this, I just can't get used to EPM's standard
  16.  * keymap :-)
  17.  */
  18.  
  19.  
  20. /*
  21.  * Added this for compatibility with EPM 5.x
  22.  */
  23. compile if not defined( WANT_TAB_INSERTION_TO_SPACE)
  24. const
  25.   WANT_TAB_INSERTION_TO_SPACE = 0
  26. compile endif
  27.  
  28.  
  29.  
  30. define
  31. compile if EVERSION < 5
  32.    NOT_CMD_STATE = '& not command_state()'
  33. compile else
  34.    NOT_CMD_STATE = ' '
  35. compile endif
  36.  
  37. definit
  38.    universal blockreflowflag
  39. compile if defined(HIGHLIGHT_COLOR)
  40.    universal search_len
  41. compile endif
  42. compile if EVERSION < 5
  43.    universal inKstring
  44.    inKstring=0
  45. compile endif
  46.    blockreflowflag=0
  47. compile if defined(HIGHLIGHT_COLOR)
  48.    search_len = 5     -- Initialize to anything, to prevent possible "Invalid number argument"
  49. compile endif
  50.  
  51. compile if WANT_CUA_MARKING & EPM
  52. defkeys edit_keys new clear
  53.  
  54. def otherkeys =
  55.    k = lastkey()
  56.    call process_key(k)
  57.  
  58. defproc process_key(k)
  59.  compile if WANT_CUA_MARKING = 'SWITCH'
  60.    universal CUA_marking_switch
  61.  compile endif
  62.    if length(k)=1 & k<>\0 then
  63.       i_s = insert_state()
  64.  compile if WANT_CUA_MARKING = 'SWITCH'
  65.       if CUA_marking_switch then
  66.  compile endif
  67.          had_mark = process_mark_like_cua()
  68.          if not i_s & had_mark then
  69.             insert_toggle  -- Turn on insert mode because the key should replace
  70.          endif             -- the mark, not the character after the mark.
  71.  compile if WANT_CUA_MARKING = 'SWITCH'
  72.       else
  73.          had_mark = 0  -- set to 0 so we don't toggle insert state later
  74.       endif
  75.  compile endif
  76.       keyin k
  77.       if not i_s & had_mark then
  78.          insert_toggle
  79.       endif
  80.    endif
  81.  
  82. defproc process_mark_like_cua()
  83.    if marktype() then
  84.       getmark firstline,lastline,firstcol,lastcol,markfileid
  85.       getfileid fileid
  86.       if fileid<>markfileid then
  87.          sayerror MARKED_OTHER__MSG
  88.          unmark
  89.       elseif not check_mark_on_screen() then
  90.          sayerror MARKED_OFFSCREEN__MSG
  91.          unmark
  92.       else
  93. compile if WANT_DM_BUFFER
  94.          'Copy2DMBuff'     -- see clipbrd.e for details
  95. compile endif  -- WANT_DM_BUFFER
  96.          firstline; .col=firstcol
  97. compile if EVERSION >= '5.20'
  98.          undoaction 1, junk                -- Create a new state
  99. compile endif
  100.          call pdelete_mark()
  101.          'ClearSharBuff'       /* Remove Content in EPM shared text buffer */
  102.          return 1
  103.       endif
  104.    endif
  105.  
  106. defproc shifted
  107.    ks = getkeystate(VK_SHIFT)
  108.    return ks<>3 & ks<>4
  109.  
  110. compile if EVERSION < 5.50
  111. define CHARG_MARK = 'CHAR'
  112. compile else                -- New mark type
  113. define CHARG_MARK = 'CHARG'
  114. compile endif
  115.  
  116. defproc extend_mark(startline, startcol, forward)
  117. ;compile if WANT_CUA_MARKING = 'SWITCH'
  118. ;  universal CUA_marking_switch
  119. ;  if not CUA_marking_switch then return; endif
  120. ;compile endif
  121.    if marktype()='LINE' | marktype()='BLOCK' then return; endif
  122.    getfileid curfileid
  123.    if not marktype() then
  124. compile if EVERSION < 5.50  -- Forwards and backwards acts differently
  125.       call pset_mark(startline, .line, startcol-(not forward), .col-forward, CHARG_MARK, curfileid)
  126. compile else  -- CHARG handles the differences.
  127.       call pset_mark(startline, .line, startcol, .col, CHARG_MARK, curfileid)
  128. compile endif
  129.       return
  130.    endif
  131. compile if EVERSION < 5.50
  132.    getmark firstline,lastline,firstcol,lastcol,markfileid
  133. compile else
  134.    getmarkg firstline,lastline,firstcol,lastcol,markfileid
  135. compile endif
  136.    if markfileid<>curfileid then  -- If mark was in a different file, treat like no mark was set.
  137. compile if EVERSION < 5.50  -- Forwards and backwards acts differently
  138.       call pset_mark(startline, .line, startcol-(not forward), .col-forward, CHARG_MARK, curfileid)
  139. compile else  -- CHARG handles the differences.
  140.       call pset_mark(startline, .line, startcol, .col, CHARG_MARK, curfileid)
  141. compile endif
  142.       return
  143.    endif
  144.    lk = lastkey(0)
  145.    if (lk=s_up & .line=firstline-1) | (lk=s_down & .line=firstline+1) then
  146.       if length(textline(firstline)) < .col then
  147.          firstcol = .col
  148.       endif
  149.    endif
  150.    if startline>firstline | ((startline=firstline) & (startcol > firstcol)) then  -- at end of mark
  151.       if not forward then
  152.          if firstline=.line & firstcol=.col then unmark; return; endif
  153.       endif
  154. compile if EVERSION < '5.50'
  155.       call pset_mark(firstline, .line, firstcol, .col-1, CHARG_MARK, curfileid)
  156. compile else
  157.       call pset_mark(firstline, .line, firstcol, .col, CHARG_MARK, curfileid)
  158. compile endif
  159.    else                                                         -- at beginning of mark
  160.       if forward then
  161.          if lastline=.line & lastcol=.col-1 then unmark; return; endif
  162.       endif
  163.       call pset_mark(lastline, .line, lastcol, .col, CHARG_MARK, curfileid)
  164.    endif
  165.  
  166. ; c_home, c_end, c_left & c_right do different things if the shift key is depressed.
  167. ; The logic is extracted here mainly due to the complexity of the COMPILE IF's
  168. defproc begin_shift(var startline, var startcol, var shift_flag)
  169.  compile if WANT_CUA_MARKING = 'SWITCH'
  170.    universal CUA_marking_switch
  171.  compile endif
  172.    shift_flag = shifted()
  173.  compile if WANT_CUA_MARKING = 'SWITCH'
  174.    if shift_flag or not CUA_marking_switch then
  175.  compile else
  176.    if shift_flag then
  177.  compile endif
  178.       startline = .line; startcol = .col
  179.    else
  180.       unmark
  181.    endif
  182.  
  183. defproc end_shift(startline, startcol, shift_flag, forward_flag)
  184.  compile if WANT_CUA_MARKING = 'SWITCH'
  185.    universal CUA_marking_switch
  186.    if shift_flag & CUA_marking_switch then
  187.  compile else
  188.    if shift_flag then
  189.  compile endif
  190.       call extend_mark(startline, startcol, forward_flag)
  191.    endif
  192. compile else  -- WANT_CUA_MARKING & EPM
  193. defkeys edit_keys new
  194. compile endif  -- WANT_CUA_MARKING & EPM
  195.  
  196. compile if EVERSION < 5
  197. def entry=
  198. compile endif
  199.  
  200. ; Real keys, in alphabetical order.
  201. ; See end of this file for a list of keys unused in standard E.
  202.  
  203. ; We now distribute a standard front end for the DIR command, which redirects
  204. ; the output to a file named ".dos dir <dirspec>".  The third line should be
  205. ; "Directory of <dirname>".  If so, we use it.  If not, we use DIRSPEC from the
  206. ; .filename instead, but note that the latter might contain wildcards.
  207. define
  208.    QUOTED_DIR_STRING ='"'DIRECTORYOF_STRING'"'
  209.  
  210. def a_1 = call get_file_at_cursor()
  211. defproc get_file_at_cursor() /* edit filename on current text line */
  212.    getline line
  213. compile if (EVERSION >= '4.12' & EVERSION < 5 & SHELL_USAGE) | WANT_EPM_SHELL
  214.  compile if EOS2
  215.    if .filename = '.SHELL' then
  216.  compile else
  217.    if leftstr(.filename, 15) = ".command_shell_" then
  218.  compile endif
  219.       if substr(line, 13, 1) = ' ' then  -- old format DIR, or not a DIR line
  220.          flag = substr(line, 1, 1) <> ' ' &
  221.                 (isnum(substr(line, 14, 8)) | substr(line, 14, 8)='<DIR>') &
  222.                 length(line) < 40 &
  223.                 isnum(substr(line, 24, 2) || substr(line, 27, 2) || substr(line, 30, 2)) &
  224.                 substr(line, 26, 1) = substr(line, 29, 1) &
  225.                 pos(substr(line, 26, 1), '/x.-')
  226.          filename=strip(substr(line,1,8))
  227.          word2=strip(substr(line,10,3))
  228.          if word2<>'' then filename=filename'.'word2; endif
  229.       else                               -- new format DIR, or not a DIR line
  230.          flag = substr(line, 41, 1) <> ' ' &
  231.                 (isnum(substr(line, 18, 9)) | substr(line, 18, 9)='<DIR>') &
  232.                 isnum(substr(line, 1, 2) || substr(line, 4, 2) || substr(line, 7, 2)) &
  233.                 substr(line, 3, 1) = substr(line, 6, 1) &
  234.                 pos(substr(line, 3, 1), '/x.-')
  235.          filename=substr(line,41)
  236.       endif
  237.       if flag then
  238.          call psave_pos(save_pos)
  239.          getsearch oldsearch
  240.  compile if EPM
  241.          display -2
  242.  compile endif
  243.          'xcom l /'DIRECTORYOF_STRING'/c-'
  244.          dir_rc = rc
  245.          if not rc then
  246.             getline word3
  247.             parse value word3 with $QUOTED_DIR_STRING word3
  248. ;;          parse value word3 with . . word3 .
  249.             if verify(word3,'?*','M') then  -- If wildcards - must be 4OS2 or similar shell
  250.                word3 = substr(word3, 1, lastpos(word3, '\')-1)
  251.             endif
  252.             word3 = strip(word3)
  253.  compile if EOS2
  254.          else
  255.             sayerror 1
  256.  compile endif
  257.          endif
  258.  compile if EPM
  259.          display 2
  260.  compile endif
  261.          setsearch oldsearch
  262.          call prestore_pos(save_pos)
  263.          if not dir_rc then
  264.             name=word3 ||                            -- Start with the path.
  265.                  leftstr('\',                        -- Append a '\', but only if path
  266.                          '\'<>rightstr(word3,1)) ||  -- doesn't end with one.
  267.                  filename                            -- Finally, the filename
  268.  compile if not E3  -- DOS (box) doesn't see new-format filenames
  269.             if pos(' ',name) then  -- enquote
  270.                name = '"'name'"'
  271.             endif
  272.  compile endif
  273.             if pos('<DIR>',line) then
  274.                'dir 'name
  275.             else
  276.                'e 'name
  277.             endif
  278.             return
  279.          endif
  280.       endif
  281.    endif
  282. compile endif  -- SHELL_USAGE | WANT_EPM_SHELL
  283.    parse value .filename with word1 word2 word3 .
  284.    if upcase(word1 word2) = '.DOS DIR' then
  285.       call psave_pos(save_pos)
  286. compile if EVERSION >= '4.12'
  287.       getsearch oldsearch
  288. compile endif
  289.       'xcom l /'DIRECTORYOF_STRING'/c-'
  290.       if not rc then
  291.          getline word3
  292.          parse value word3 with $QUOTED_DIR_STRING word3
  293. ;        parse value word3 with . . word3 .
  294.          if verify(word3,'?*','M') then  -- If wildcards - must be 4OS2 or similar shell
  295.             word3 = substr(word3, 1, lastpos(word3, '\')-1)
  296.          endif
  297.          word3 = strip(word3)
  298.       endif
  299. compile if EVERSION >= '4.12'
  300.       setsearch oldsearch
  301. compile endif
  302.       call prestore_pos(save_pos)
  303. compile if not E3  -- DOS (box) doesn't see new-format DIR listing
  304.       filename=substr(line,41)                 -- Support HPFS.  FAT dir's end at 40
  305.       if filename='' then                      -- Must be FAT.
  306. compile endif
  307.          filename=strip(substr(line,1,8))
  308.          word2=strip(substr(line,10,3))
  309.          if word2<>'' then filename=filename'.'word2; endif
  310. compile if not E3  -- DOS (box) doesn't see new-format DIR listing
  311.       endif
  312. compile endif
  313.       name=word3 ||                            -- Start with the path.
  314. compile if EVERSION >= '5.17'
  315.            leftstr('\',                        -- Append a '\', but only if path
  316.                    '\'<>rightstr(word3,1)) ||  -- doesn't end with one.
  317. compile else
  318.            substr('\', 1,                      -- Append a '\', but only if path
  319.                   '\'<>substr(word3,length(word3),1)) ||  -- doesn't end with one.
  320. compile endif
  321.            filename                            -- Finally, the filename
  322. compile if not E3  -- DOS (box) doesn't see new-format filenames
  323.       if pos(' ',name) then  -- enquote
  324.          name = '"'name'"'
  325.       endif
  326. compile endif
  327.       if pos('<DIR>',line) then
  328.          'dir 'name
  329.       else
  330.          'e 'name
  331.       endif
  332. compile if EVERSION >= 6.0  -- Herbert: EPM 5.51 doesn't know WANT_TREE
  333. compile if WANT_TREE
  334.    elseif .filename = '.tree' then
  335.       if substr(line,5,1)substr(line,8,1)substr(line,15,1)substr(line,18,1) = '--::' then
  336.          name = substr(line, 52)
  337.          if substr(line,31,1)='>' then
  338. ;           if isadefc('tree_dir') then
  339.                'tree_dir' name'\*.*'
  340. ;           else
  341. ;              'dir' name
  342. ;           endif
  343.          else
  344. compile if EVERSION >= '5.50'
  345.             'e "'name'"'
  346. compile else
  347.             'e' name
  348. compile endif
  349.          endif
  350.       endif
  351. compile endif  -- WANT_TREE
  352. compile endif  -- EVERSION >= 6.0
  353.    else  -- Not a DIR listing
  354. compile if not E3
  355.       parse value line with w1 rest
  356.       p=lastpos('(', w1)
  357.       if p then
  358.          filename = substr(w1, 1, p-1)
  359.          parse value substr(w1, p+1) with line ')'
  360.          parse value line with line ':' col
  361.          if pos('*', filename) then
  362.             if YES_CHAR<>askyesno(WILDCARD_WARNING__MSG, '', filename) then
  363.                return
  364.             endif
  365.          endif
  366.          'e 'filename
  367.          line
  368.          if col<>'' then .col = col; endif
  369.       else
  370.          if pos('*', line) then
  371.             if YES_CHAR<>askyesno(WILDCARD_WARNING__MSG, '', line) then
  372.                return
  373.             endif
  374.          endif
  375. compile endif
  376.          'e 'line
  377. compile if not E3
  378.       endif
  379. compile endif
  380.    endif
  381.  
  382. compile if WANT_WINDOWS
  383. def a_4=call psplit4()            -- routine defined in WINDOW.E
  384. compile endif
  385.  
  386. def a_a= call adjust_block_()
  387. defproc adjust_block_()
  388. compile if WANT_CHAR_OPS
  389.    call pcommon_adjust_overlay('A')
  390. compile else
  391.    adjustblock
  392. compile endif
  393.  
  394. def a_b = call mark_block_()
  395. defproc mark_block_()
  396.    markblock
  397. compile if EVERSION >= 5
  398.    'Copy2SharBuff'       /* Copy mark to shared text buffer */
  399. compile endif
  400.  
  401. def a_c = call copy_mark_()
  402. defproc copy_mark_()
  403. compile if EPM
  404.    if marktype() then
  405. compile endif
  406.       call pcopy_mark()
  407. compile if EPM
  408.    else                 /* If no mark, look to in Shared Text buffer */
  409.       'GetSharBuff'     /* see clipbrd.e for details                 */
  410.    endif
  411. compile endif
  412.  
  413. def a_d = call delete_block()
  414. defproc delete_block()
  415. compile if WANT_DM_BUFFER
  416.    'Copy2DMBuff'     -- see clipbrd.e for details
  417. compile endif
  418.    call pdelete_mark()
  419. compile if EVERSION > 5
  420.    'ClearSharBuff'       /* Remove Content in EPM shared text buffer */
  421. compile endif
  422.  
  423. def a_e = call end_of_mark()
  424. defproc end_of_mark()
  425.    call pend_mark()
  426.    if substr(marktype(),1,1)<>'L' then
  427.       right
  428.    endif
  429.  
  430. def a_equal=
  431.    'dolines'   -- Code is a separate command in STDCMDS.E.
  432.  
  433. def a_f = call fill_marked_area()
  434. defproc fill_marked_area()  /* Now accepts key from macro. */
  435.    call checkmark()
  436. compile if EVERSION < 5
  437.    k=mgetkey("Type a character, or Esc to cancel.")
  438.    if length(k)>1 then           -- Do something with extended keys.
  439.       if     k=esc      then ;   -- Let user abort w/o Ctrl-break.
  440.       elseif k=padstar  then k='*'
  441.       elseif k=padplus  then k='+'
  442.       elseif k=padminus then k='-'
  443.       else   k=substr(k,2,1)      endif
  444.    endif
  445.    if k<>esc then call pfill_mark(k); endif
  446. compile else
  447.    call pfill_mark()
  448. compile endif
  449.  
  450. def a_f1= call show_draw_chars()
  451. defproc show_draw_chars()
  452. keyin '║ ╠ ╔ ╚ ╩ ═ ╦ ╝ ╗ ╣ ╬ │ ├ ┌ └ ┴ ─ ┬ ┘ ┐ ┤ ┼ █ ▓ ▒ ░'
  453.  
  454. def a_f7,c_F7= call move_left()
  455. defproc move_left()   -- Can't use the old A_F7 in EPM.  PM uses it as an accelerator key.
  456.    shift_left
  457. compile if SHIFT_BLOCK_ONLY
  458.    if marktype()='BLOCK' then  -- code by Bob Langer
  459.       getmark fl,ll,fc,lc,fid
  460.       call pset_mark(fl,ll,lc,MAXCOL,'BLOCK',fid)
  461.       shift_right
  462.       call pset_mark(fl,ll,fc,lc,'BLOCK',fid)
  463.    endif
  464. compile endif
  465.  
  466. def a_f8,c_F8= call move_right()
  467. defproc move_right() -- Can't use the old A_F8 in EPM.  PM uses it as an accelerator key.
  468. compile if SHIFT_BLOCK_ONLY
  469.    if marktype()='BLOCK' then  -- code by Bob Langer
  470.       getmark fl,ll,fc,lc,fid
  471.       call pset_mark(fl,ll,lc,MAXCOL,'BLOCK',fid)
  472.       shift_left
  473.       call pset_mark(fl,ll,fc,lc,'BLOCK',fid)
  474.    endif
  475. compile endif
  476.    shift_right
  477.  
  478. def a_f10,c_P= call previous_file_()
  479. compile if EVERSION < 5
  480.  compile if EVERSION < '4.10'          -- Early E doesn't support enh. kbd.
  481. defproc previous_file_() call pprevfile()       -- routine defined in WINDOW.E
  482.  compile else
  483. defproc previous_file_() call pprevfile()       -- routine defined in WINDOW.E
  484.  compile endif
  485. compile else
  486. /* We can't use a_f10 for previous file any more, PM uses that key. */
  487. /* I like F11 and F12 to go back and forth.                         */
  488. defproc previous_file_()  -- a_F10 is usual E default; F11 for enh. kbd, c_P for EPM.
  489.    prevfile
  490. compile endif
  491.  
  492. compile if EPM32
  493. ; def a_F11 = 'prevview'
  494. def a_F12 = 'nextview'
  495. compile endif
  496.  
  497. def a_j=
  498.    call joinlines()
  499.  
  500. def a_l= call mark_line_()
  501. defproc mark_line_()
  502.    mark_line
  503. compile if EVERSION >= 5
  504.    'Copy2SharBuff'       /* Copy mark to shared text buffer */
  505. compile endif
  506.  
  507. def a_m= call move_mark_()
  508. defproc move_mark_()
  509. call pmove_mark()
  510. compile if UNMARK_AFTER_MOVE
  511.    unmark
  512.  compile if EVERSION > 5
  513.    'ClearSharBuff'       /* Remove Content in EPM shared text buffer */
  514.  compile endif
  515. compile endif
  516.  
  517. def a_minus = call circle_it()
  518. defproc circle_it()
  519.  compile if EOS2
  520.    display 0
  521.  compile endif
  522.  compile if EVERSION < '5.50'
  523.    sayat '', .cursory, .cursorx, WHITE + REDB + BLINK, 1
  524.  compile elseif EVERSION >= '5.60'
  525.    circleit 5, .line, .col-1, .col+1, 16777220
  526.  compile else
  527.    circleit 2, .line, .col-1, .col+1, WHITE + REDB + BLINK
  528.  compile endif
  529.  compile if EPM & EVERSION < '5.50'
  530.    call dynalink('DOSCALLS', '#32', atol_swap(1000))  -- 1 second DOSSLEEP
  531.    refresh
  532.  compile endif
  533.  compile if EOS2
  534.    k=getkey()
  535.    display 1
  536.    executekey k
  537.  compile endif
  538.  
  539. def a_n=  /* Type the full name of the current file. */
  540.   keyin .filename
  541.  
  542. def a_o= call overlay_marked_area()
  543. defproc overlay_marked_area()
  544. compile if EPM
  545.    if marktype() then
  546. compile endif
  547. compile if WANT_CHAR_OPS
  548.       call pcommon_adjust_overlay('O')
  549. compile else
  550.       overlay_block
  551. compile endif
  552. compile if EPM
  553.    else                 /* If no mark, look to in Shared Text buffer */
  554.       'GetSharBuff O'   /* see clipbrd.e for details                 */
  555.    endif
  556. compile endif
  557.  
  558. def a_p= call reformat_paragraph()
  559. defproc reformat_paragraph()
  560.    /* Protect the user from accidentally reflowing a marked  */
  561.    /* area not in the current file, and give a good message. */
  562.    mt = substr(marktype(), 1, 1)
  563.    if mt='B' or mt='L' then
  564.       getmark firstline,lastline,firstcol,lastcol,markfileid
  565.       getfileid fileid
  566.       if fileid<>markfileid then
  567.          sayerror CANT_REFLOW__MSG'  'OTHER_FILE_MARKED__MSG
  568.          return
  569.       endif
  570.    endif
  571.  
  572.    if mt<>' ' then
  573.       if not check_mark_on_screen() then
  574. compile if EVERSION < 5
  575.          do while testkey()/==''; call getkey(); end
  576.          sayerror MARK_OFF_SCRN_YN__MSG
  577.          loop
  578.             ch=upcase(getkey())
  579.             if ch=YES_CHAR then sayerror 0; leave; endif
  580.             if ch=NO_CHAR or ch=esc then sayerror 0; stop; endif
  581.          endloop
  582. compile else
  583.          sayerror MARK_OFF_SCREEN__MSG
  584.          stop
  585. compile endif
  586.       endif
  587.    endif
  588.  
  589.    if mt='B' then
  590.       'box r'
  591.    elseif mt='C' then
  592.       sayerror WRONG_MARK__MSG
  593.    elseif mt='L' then
  594.       reflow
  595.    else  -- Standard text reflow split into a separate routine.
  596.       call text_reflow()
  597.    endif
  598.  
  599. definit                         -- Variable is null if alt_R is not active.
  600.    universal alt_R_active       -- For E3/EOS2, it's 1 if alt_R is active.
  601.    alt_R_active = ''            -- For EPM, it's set to querycontrol(messageline).
  602.  
  603. def a_r=
  604.    universal alt_R_active,tempofid
  605. compile if EPM
  606.    universal alt_R_space
  607. compile endif
  608.  
  609.    if alt_R_active<>'' then
  610. compile if EPM
  611.       call pblock_reflow(1,alt_R_space,tempofid)     -- Complete the reflow.
  612.  compile if EVERSION < '5.21'
  613.       .messageline=''                        -- Turn off the message.
  614.  compile else
  615.        'setmessageline '\0
  616.  compile endif
  617.  compile if EVERSION >= '5.53'
  618.       'toggleframe 2 'alt_R_active           -- Restore status of messageline.
  619.  compile else
  620.       'togglecontrol 8 'alt_R_active         -- Restore status of messageline.
  621.  compile endif
  622.       alt_R_active = ''
  623.       return
  624. compile else
  625.       activatefile tempofid                  -- Release tempo
  626.       .modify=0
  627.       'xcom q'
  628. compile endif
  629.    endif
  630.    if pblock_reflow(0,alt_R_space,tempofid) then
  631.       sayerror PBLOCK_ERROR__MSG      /* HurleyJ */
  632.       return
  633.    endif
  634. ;  if marktype() <> 'BLOCK' then
  635.       unmark
  636. ;  endif
  637. compile if EPM
  638.  compile if EVERSION >= '5.53'
  639.    alt_R_active = queryframecontrol(2)         -- Remember if messageline on or off
  640.    'toggleframe 2 1'                    -- Force it on
  641.  compile else
  642.    alt_R_active = querycontrol(8)         -- Remember if messageline on or off
  643.    'togglecontrol 8 1'                    -- Force it on
  644.  compile endif
  645.  compile if EVERSION < '5.21'
  646.    .messageline = BLOCK_REFLOW__MSG
  647.  compile else
  648.    'setmessageline' BLOCK_REFLOW__MSG
  649.  compile endif
  650. compile else
  651.    alt_R_active = 1
  652.    sayerror BLOCK_REFLOW__MSG
  653.    loop
  654.       k=getkey()
  655.       if k==a_r then  /* Alt-R ? */
  656.          call pblock_reflow(1,alt_R_space,tempofid)
  657.          leave
  658.       endif
  659.       if k==esc then  /* Esc ? */
  660.          /* release tempo */
  661.          activatefile tempofid
  662.          .modify=0
  663.          'xcom q'
  664.          unmark
  665.          sayerror NOFLOW__MSG
  666.          leave
  667.       endif
  668.       executekey k
  669.    endloop
  670.    alt_R_active = ''
  671. compile endif
  672.  
  673. def a_s=
  674.    call splitlines()
  675.  
  676. def a_t = call pcenter_mark()
  677.  
  678. def a_u= call unmark_block()
  679. defproc unmark_block()
  680.    unmark
  681. compile if EVERSION > 5
  682.    'ClearSharBuff'       /* Remove Content in EPM shared text buffer */
  683. compile endif
  684.  
  685. def a_w = call pmark_word()
  686.  
  687. ;  EPM:  Haven't yet figured out a way to do Alt-X=escape.  It used a getkey().
  688. compile if EVERSION < 5
  689. def a_x=escape
  690. compile endif
  691.  
  692. def a_y= call pbegin_mark()
  693.  
  694. compile if WANT_CHAR_OPS
  695. def a_z= call mark_single_char()
  696. defproc mark_single_char()
  697. mark_char
  698.  compile if EVERSION > 5
  699.    'Copy2SharBuff'       /* Copy mark to shared text buffer */
  700.  compile endif
  701. compile endif
  702.  
  703. compile if EVERSION < 5
  704. def backspace= call do_backspace()
  705. defproc do_backspace()
  706. compile else
  707. def backspace, s_backspace = call do_backspace()
  708. defproc do_backspace()
  709. compile endif
  710.  compile if WANT_STREAM_MODE = 'SWITCH'
  711.    universal stream_mode
  712.  compile endif
  713.  compile if WANT_CUA_MARKING = 'SWITCH'
  714.    universal CUA_marking_switch
  715.    if CUA_marking_switch then
  716.  compile endif
  717.  compile if WANT_CUA_MARKING
  718.   compile if EVERSION < 5
  719.    if command_state() then rubout; return; endif
  720.   compile endif
  721.    if process_mark_like_cua() then return; endif
  722.  compile endif
  723.  compile if WANT_CUA_MARKING = 'SWITCH'
  724.    endif
  725.  compile endif
  726. compile if WANT_STREAM_MODE
  727.  compile if WANT_STREAM_MODE = 'SWITCH'
  728.    if .col=1 & .line>1 & stream_mode $NOT_CMD_STATE then
  729.  compile else
  730.    if .col=1 & .line>1 $NOT_CMD_STATE then
  731.  compile endif
  732.       up
  733.       l=length(textline(.line))
  734.       join
  735.       .col=l+1
  736.    else
  737. compile endif
  738. compile if EVERSION >= '5.50'
  739.       old_level = .levelofattributesupport
  740.  compile if EVERSION >= '6.01b'
  741.       if old_level & not (old_level bitand 2) then
  742.  compile else
  743.       if old_level & not (old_level%2 - 2*(old_level%4)) then
  744.  compile endif
  745.          .levelofattributesupport = .levelofattributesupport + 2
  746.          .cursoroffset = -300
  747.       endif
  748. compile endif
  749.       rubout
  750. compile if EVERSION >= '5.50'
  751.       .levelofattributesupport = old_level
  752. compile endif
  753. compile if WANT_STREAM_MODE
  754.    endif
  755. compile endif
  756.  
  757. def c_2 = keyin \0                  -- C_2 enters a null.
  758. def c_6 = keyin \170                -- C_6 enters a "not" sign
  759. compile if EVERSION >= '5.50'
  760. def c_9 = keyin '{'
  761. def c_0 = keyin '}'
  762. compile endif
  763.  
  764. compile if WANT_WINDOWS
  765. def c_a= call pnextwindowstyle()  -- routine defined in WINDOW.E
  766. compile endif
  767.  
  768. compile if WANT_BOOKMARKS
  769. def c_B = 'listmark'
  770. compile endif
  771.  
  772. def c_backspace= call delete_line()
  773. defproc delete_line()
  774. compile if EVERSION >= '5.20'
  775.    undoaction 1, junk                -- Create a new state
  776. compile endif
  777. compile if EVERSION >= '5.50'
  778.    if .levelofattributesupport then
  779.       if (.line==.last and .line<>1) then       -- this is the last line
  780.          destinationLine=.line-1                -- and there is a previous line to store attributes on
  781.          getline prevline,DestinationLine
  782.          DestinationCol=length(prevline)+1      -- start search parameters
  783.                                                 -- destination of attributes
  784.          findoffset=-300                        -- start at the begin of the attr list
  785.          findline=.line                         -- of the first char on this line
  786.          findcolumn=1
  787.  
  788.          do forever        -- search until no more attr's (since this is last line)
  789.             FINDCLASS=0          -- 0 is anyclass
  790.             Attribute_action FIND_NEXT_ATTR_SUBOP, findclass, findoffset, findcolumn, findline
  791.             if not findclass or (findline<>.line) then  -- No attribute, or not on this line
  792.                leave
  793.             endif
  794.             query_attribute theclass,thevalue, thepush, findoffset, findcolumn, findline   -- push or pop?
  795.             if not thePush then       -- ..if its a pop attr and ..
  796.                matchClass=theClass
  797.                MatchOffset=FindOffset
  798.                MatchLine=FindLine
  799.                MatchColumn=FindColumn  -- ..and if its match is not on this line or at the destination
  800.                Attribute_Action FIND_MATCH_ATTR_SUBOP, MatchClass, MatchOffset, Matchcolumn, MatchLine
  801.                if ((Matchline==DestinationLine) and (Matchcolumn==destinationcol)) then
  802.                   -- then there is a cancellation of attributes
  803.                   Attribute_action Delete_ATTR_SUBOP, theclass, Findoffset, Findcolumn, Findline
  804.                   Attribute_action Delete_ATTR_SUBOP, Matchclass, Matchoffset, Matchcolumn, Matchline
  805.                elseif (MatchLine<>.line)  then
  806.                   -- .. then move attribute to destination (before attributes which have been scanned so its OK.)
  807.                   -- insert attr at the end of the attr list (offset=0)
  808.                   Insert_Attribute theclass, thevalue, 0, 0, DestinationCol, DestinationLine
  809.                   Attribute_action Delete_ATTR_SUBOP, theclass, Findoffset, Findcolumn, Findline
  810.                endif -- end if attr is on line or at destination
  811.             endif -- end if found attr is a pop
  812.          enddo  -- end search for attr's
  813.       elseif .line < .last then  -- put the attributes after the line since there may not
  814.                                  -- be a line before this line (as when .line==1)
  815.          DestinationCol=1
  816.          DestinationLine=.line+1         -- error point since this puts attr's after last line if .line=.last
  817.          findoffset=0                    -- cant make it .line-1 cause then present attributes there become
  818.          findline=.line                  -- after these attributes which is wrong
  819.          findcolumn=MAXCOL
  820.  
  821.          do forever
  822.             FINDCLASS=0
  823.             Attribute_action FIND_PREV_ATTR_SUBOP, findclass, findoffset, findcolumn, findline
  824.             if not findclass or (findline<>.line) then  -- No attribute, or not on this line
  825.                leave
  826.             endif
  827.              /* Move Attribute */
  828.             query_attribute theclass,thevalue, thepush, findoffset, findcolumn, findline
  829.             -- only move push/pop model attributes (tags are just deleted)
  830.             if ((thepush==0) or (thepush==1)) then
  831.                -- move attribute to destination, if cancellation delete both attributes
  832.                FastMoveAttrToBeg(theclass, thevalue, thepush, DestinationCol, DestinationLine, findcolumn, findline, findoffset)
  833.                findoffset=findoffset+1  -- since the attr rec was deleted and all attr rec's were shifted to fill the vacancy
  834.                                         -- and search is exclusive
  835.             endif
  836.          enddo
  837.       endif -- endif .line=.last and .line=1
  838.    endif -- .levelofattributesupport
  839. compile endif
  840.    delete
  841. compile if EVERSION >= '5.20'
  842.    undoaction 1, junk                -- Create a new state
  843. compile endif
  844. compile if EVERSION < 5
  845.    if command_state() then
  846.       begin_line
  847.    endif
  848. compile endif
  849.  
  850. def c_c= call change_next()
  851. defproc change_next()
  852. compile if EVERSION < 5
  853.   right
  854. compile else
  855.   'c'    -- EPM c_c is used for change next
  856. compile endif
  857.  
  858. ; Ctrl-D = word delete, thanks to Bill Brantley.
  859. def c_d = call delete_right_word()
  860. defproc delete_right_word()  /* delete from cursor until beginning of next word, UNDOable */
  861. compile if EVERSION < 5
  862.    if command_state() then
  863.       getcommand cmdline, begcur, cmdscrPos
  864.       lenCmdLine=length(cmdline)
  865.       if lenCmdLine >= begcur then
  866.          for i = begcur to lenCmdLine /* delete remainder of word */
  867.             if substr(cmdline,i,1)<>' ' then
  868.                deleteChar
  869.             else
  870.                leave
  871.             endif
  872.          endfor
  873.          for j = i to lenCmdLine /* delete delimiters following word */
  874.             if substr(cmdline,j,1)==' ' then
  875.                deleteChar
  876.             else
  877.                leave
  878.             endif
  879.          endfor
  880.       endif
  881.    else
  882. compile endif
  883.       getline line
  884.       begcur=.col
  885.       lenLine=length(line)
  886.       if lenLine >= begcur then
  887.          for i = begcur to lenLine /* delete remainder of word */
  888.             if substr(Line,i,1)<>' ' then
  889.                deleteChar
  890.             else
  891.                leave
  892.             endif
  893.          endfor
  894.          for j = i to lenLine /* delete delimiters following word */
  895.             if substr(Line,j,1)==' ' then
  896.                deleteChar
  897.             else
  898.                leave
  899.             endif
  900.          endfor
  901.       endif
  902. compile if EVERSION < 5
  903.    endif
  904. compile endif
  905.  
  906. compile if WANT_STACK_CMDS & not E3
  907. def c_down =
  908.    'pushpos'
  909. compile endif
  910.  
  911. compile if EVERSION >= '4.10'
  912. def c_e, c_del= erase_end_line  -- Ctrl-Del is the PM way.
  913. compile else
  914. def c_e= erase_end_line
  915. compile endif
  916.  
  917.  
  918.  
  919. compile if WANT_KEYWORD_HELP
  920. def c_h = 'kwhelp'
  921. compile endif
  922.  
  923. def c_end= call go_to_eof()
  924. defproc go_to_eof()
  925.  compile if WANT_STREAM_MODE = 'SWITCH'
  926.    universal stream_mode
  927. compile endif
  928. compile if WANT_CUA_MARKING
  929.    call begin_shift(startline, startcol, shift_flag)
  930. compile endif
  931. compile if WANT_STREAM_MODE = 'SWITCH'
  932.    if stream_mode then
  933. compile endif
  934. compile if WANT_STREAM_MODE
  935.       bottom; endline
  936. compile endif
  937. compile if WANT_STREAM_MODE = 'SWITCH'
  938.    else
  939. compile endif
  940. compile if WANT_STREAM_MODE <> 1
  941.       if .line=.last and .line then endline; endif
  942.       bottom
  943. compile endif
  944. compile if WANT_STREAM_MODE = 'SWITCH'
  945.    endif
  946. compile endif
  947. compile if WANT_CUA_MARKING
  948.    call end_shift(startline, startcol, shift_flag, 1)
  949. compile endif
  950.  
  951. compile if ENHANCED_ENTER_KEYS & C_ENTER_ACTION <> ''  -- define each key separately
  952. ; Nothing - defined below along with ENTER
  953. compile else
  954.  compile if EVERSION >= '4.10'
  955. def c_enter, c_pad_enter=     -- 4.10:  new key for enhanced keyboard
  956.  compile else
  957. def c_enter=
  958.  compile endif
  959.    call my_c_enter()
  960.  compile if E3 and SHOW_MODIFY_METHOD
  961.    call show_modify()
  962.  compile endif
  963. compile endif
  964.  
  965. def c_f= call find_next()
  966. defproc find_next()
  967. compile if defined(HIGHLIGHT_COLOR)
  968.    universal search_len
  969.  compile if EOS2
  970.    universal inKstring
  971.  compile endif
  972. compile endif
  973. compile if EVERSION > 5
  974.    sayerror 0
  975. compile endif
  976.    repeat_find       /* find next */
  977. compile if EVERSION < 5
  978.    if not rc then
  979.       cursor_data
  980.  compile if defined(HIGHLIGHT_COLOR)
  981.       refresh
  982.       sayat '', .windowy+.cursory-1,.windowx+.cursorx-1,
  983.             HIGHLIGHT_COLOR, min(search_len, .windowwidth - .cursorx + 1)
  984.   compile if EOS2
  985.       if inKstring <=0 then
  986.          k=mgetkey()
  987.          executekey k
  988.       endif
  989.   compile endif
  990.  compile endif
  991.    endif
  992. compile elseif defined(HIGHLIGHT_COLOR)
  993.    if not rc then
  994.  compile if EVERSION < '5.50'
  995.       refresh
  996.       sayat '', .cursory, .cursorx, HIGHLIGHT_COLOR, min(search_len, .windowwidth - .cursorx + 1)
  997.  compile elseif EVERSION >= '6.02'
  998.       col = getpminfo(EPMINFO_SEARCHPOS)
  999.       circleit LOCATE_CIRCLE_STYLE, .line, col, col+getpminfo(EPMINFO_LSLENGTH)-1, LOCATE_CIRCLE_COLOR1, LOCATE_CIRCLE_COLOR2
  1000.  compile elseif EVERSION >= '5.60'
  1001.       circleit LOCATE_CIRCLE_STYLE, .line, .col, .col+getpminfo(EPMINFO_LSLENGTH)-1, LOCATE_CIRCLE_COLOR1, LOCATE_CIRCLE_COLOR2
  1002.  compile elseif EVERSION >= '5.51'
  1003.       circleit LOCATE_CIRCLE_STYLE, .line, .col, .col+getpminfo(EPMINFO_LSLENGTH)-1, HIGHLIGHT_COLOR
  1004.  compile else
  1005.       circleit LOCATE_CIRCLE_STYLE, .line, .col, .col+search_len-1, HIGHLIGHT_COLOR
  1006.  compile endif
  1007.    endif
  1008. compile endif
  1009.  
  1010. def c_f1= call upcase_word()
  1011. defproc upcase_word()
  1012. compile if EVERSION < 5
  1013.    call init_operation_on_commandline()
  1014. compile endif
  1015.    call psave_mark(save_mark)
  1016.    call pmark_word()
  1017.    call puppercase()
  1018.    call prestore_mark(save_mark)
  1019. compile if EVERSION < 5
  1020.    call move_results_to_commandline()
  1021. compile endif
  1022.  
  1023. def c_f2= call locase_word()
  1024. defproc locase_word()
  1025. compile if EVERSION < 5
  1026.    call init_operation_on_commandline()
  1027. compile endif
  1028.    call psave_mark(save_mark)
  1029.    call pmark_word()
  1030.    call plowercase()
  1031.    call prestore_mark(save_mark)
  1032. compile if EVERSION < 5
  1033.    call move_results_to_commandline()
  1034. compile endif
  1035.  
  1036. def c_f3= call puppercase()
  1037.  
  1038. def c_f4= call plowercase()
  1039.  
  1040. def c_f5= call beg_word()
  1041. defproc beg_word()
  1042. compile if EVERSION < 5
  1043.    call init_operation_on_commandline()
  1044. compile endif
  1045.    call pbegin_word()
  1046. compile if EVERSION < 5
  1047.    call move_results_to_commandline()
  1048. compile endif
  1049.  
  1050. def c_f6= call end_word()
  1051. defproc end_word()
  1052. compile if EVERSION < 5
  1053.    call init_operation_on_commandline()
  1054. compile endif
  1055.    call pend_word()
  1056. compile if EVERSION < 5
  1057.    call move_results_to_commandline()
  1058. compile endif
  1059.  
  1060. compile if EPM
  1061. def c_g='ring_more'
  1062. compile endif
  1063.  
  1064. def c_home= call go_to_bof()
  1065. defproc go_to_bof()
  1066. compile if WANT_STREAM_MODE = 'SWITCH'
  1067.    universal stream_mode
  1068. compile endif
  1069. compile if WANT_CUA_MARKING
  1070.    call begin_shift(startline, startcol, shift_flag)
  1071. compile endif
  1072. compile if WANT_STREAM_MODE = 'SWITCH'
  1073.    if stream_mode then
  1074. compile endif
  1075. compile if WANT_STREAM_MODE
  1076.       top; begin_line
  1077. compile endif
  1078. compile if WANT_STREAM_MODE = 'SWITCH'
  1079.    else
  1080. compile endif
  1081. compile if WANT_STREAM_MODE <> 1
  1082.       if .line=1 then begin_line endif
  1083.       top
  1084. compile endif
  1085. compile if WANT_STREAM_MODE = 'SWITCH'
  1086.    endif
  1087. compile endif
  1088. compile if WANT_CUA_MARKING
  1089.    call end_shift(startline, startcol, shift_flag, 0)
  1090. compile endif
  1091.  
  1092. compile if WANT_WINDOWS
  1093. def c_h=call psplith()            -- routine defined in WINDOW.E
  1094. compile endif
  1095.  
  1096. def c_k= call dup_line()
  1097. defproc dup_line()     -- Duplicate a line
  1098.   getline line
  1099.   insertline line,.line+1
  1100.  
  1101. def c_l = call command_line()
  1102. defproc command_line()
  1103.    if .line then
  1104.       getline line
  1105. compile if EPM
  1106.       'commandline 'line
  1107. compile else
  1108.       if not command_state() then
  1109.          cursor_command
  1110.          begin_line;erase_end_line
  1111.       endif
  1112.       keyin line
  1113. compile endif
  1114.    endif
  1115.  
  1116. def c_left= call left_word()
  1117. defproc left_word()
  1118. compile if WANT_STREAM_MODE = 'SWITCH'
  1119.    universal stream_mode
  1120. compile endif
  1121. compile if EVERSION < 5
  1122.    call init_operation_on_commandline()
  1123. compile endif
  1124. compile if WANT_CUA_MARKING
  1125.    call begin_shift(startline, startcol, shift_flag)
  1126. compile endif
  1127. compile if WANT_STREAM_MODE
  1128.    if not .line then
  1129.       begin_line
  1130.  compile if WANT_STREAM_MODE = 'SWITCH'
  1131.    elseif .line>1 & .col=max(1,verify(textline(.line),' ')) & stream_mode $NOT_CMD_STATE then
  1132.  compile else
  1133.    elseif .line>1 & .col=max(1,verify(textline(.line),' ')) $NOT_CMD_STATE then
  1134.  compile endif
  1135.       up; end_line
  1136.    endif
  1137. compile endif
  1138.    backtab_word
  1139. compile if EVERSION < 5
  1140.    call move_results_to_commandline()
  1141. compile endif
  1142. compile if WANT_CUA_MARKING
  1143.    call end_shift(startline, startcol, shift_flag, 0)
  1144. compile endif
  1145.  
  1146. compile if WANT_BOOKMARKS
  1147. def c_m = 'setmark'
  1148. compile else  -- [The following doesn't apply to EPM.]
  1149. ; This C-M definition allows external cut-and-paste utilities to
  1150. ; feed text into E via the keyboard stream.  Most such utilities end each line
  1151. ; of text with ASCII character 13.  This definition is needed because E
  1152. ; distinguishes that as a different key (Ctrl-M) than Enter.
  1153. def c_m =
  1154.    insert
  1155. compile endif
  1156.  
  1157. def c_pgup= call beg_screen()
  1158. defproc beg_screen()
  1159. compile if WANT_CUA_MARKING
  1160.  compile if WANT_CUA_MARKING = 'SWITCH'
  1161.    universal CUA_marking_switch
  1162.    if CUA_marking_switch then
  1163.  compile endif
  1164.       unmark
  1165.  compile if WANT_CUA_MARKING = 'SWITCH'
  1166.    endif
  1167.  compile endif
  1168. compile endif
  1169.    .cursory=1
  1170.  
  1171. def c_pgdn= call end_screen()
  1172. defproc end_screen()
  1173. compile if WANT_CUA_MARKING
  1174.  compile if WANT_CUA_MARKING = 'SWITCH'
  1175.    universal CUA_marking_switch
  1176.    if CUA_marking_switch then
  1177.  compile endif
  1178.       unmark
  1179.  compile if WANT_CUA_MARKING = 'SWITCH'
  1180.    endif
  1181.  compile endif
  1182. compile endif
  1183.    .cursory=.windowheight
  1184.  
  1185. def c_r= call record_key_string()
  1186. compile if EVERSION < 5
  1187. /************************************************************/
  1188. /* Create a string of keys in Kstring variable.             */
  1189. /* All control keys have the same character (X'00') as the  */
  1190. /* first character of a two-character string.               */
  1191. /*                                                          */
  1192. /* The number of keys that may be stored is given by:       */
  1193. /*           256 > n + 2*e                                  */
  1194. /* where:                                                   */
  1195. /*       n are normal data keys (one byte from BIOS)        */
  1196. /*       e are extended code keys (two bytes from BIOS)     */
  1197. /************************************************************/
  1198. defproc record_key_string()
  1199.    universal Kstring,Kins_state,Kcom_state,inKstring
  1200.  
  1201.    inKstring=-1      /* Set recording flag; see defproc mgetkey(). */
  1202.    sayerror CTRL_R__MSG
  1203.    oldKins_state=Kins_state
  1204.    oldKstring   =Kstring
  1205.    oldKcom_state=Kcom_state
  1206.    Kins_state   =insert_state()
  1207.    Kstring      =''
  1208.    Kcom_state   =command_state()
  1209.    Kct=0
  1210.    loop
  1211.       k=getkey()
  1212.       if k==c_r then  /* Ctrl-R ? */
  1213.          sayerror REMEMBERED__MSG
  1214.          leave
  1215.       endif
  1216.       if k==c_t then  /* Ctrl-T ? */
  1217.          leave
  1218.       endif
  1219.       if k==c_c then  /* cancel? */
  1220.          Kstring   =oldKstring
  1221.          Kins_state=oldKins_state
  1222.          Kcom_state=oldKcom_state
  1223.          sayerror CANCELLED__MSG'  'OLD_KEPT__MSG
  1224.          leave
  1225.       endif
  1226.       Kstring=Kstring||k
  1227.       Kct=length(Kstring)
  1228.       executekey k         /* execute AFTER adding to string */
  1229.       if Kct > MAXCOL then
  1230.          sayerror CTRL_R_ABORT__MSG
  1231.          Kstring=oldKstring
  1232.          Kins_state=oldKins_state
  1233.          Kcom_state=oldKcom_state
  1234.          loop
  1235.             k=getkey()
  1236.             if k==esc or k==c_c then leave endif   /* accept either */
  1237.          endloop
  1238.          sayerror OLD_KEPT__MSG
  1239.          leave
  1240.       endif
  1241.    endloop
  1242.    inKstring=0       /* lower state flag */
  1243.    if k==c_t then    /* Was it Ctrl-T? */
  1244.       sayerror 0     /* refresh the function keys */
  1245.       executekey k
  1246.    endif
  1247. compile endif
  1248.  
  1249. compile if EPM
  1250. defproc record_key_string()
  1251.    -- Query to see if we are already in recording
  1252.    if windowmessage(1,  getpminfo(EPMINFO_EDITCLIENT),
  1253.                     5393,
  1254.                     0,
  1255.                     0)
  1256.    then
  1257.       call windowmessage(0,  getpminfo(EPMINFO_EDITCLIENT),
  1258.                          5392,
  1259.                          0,
  1260.                          0)
  1261.       sayerror REMEMBERED__MSG
  1262.    else
  1263.       sayerror CTRL_R__MSG
  1264.       call windowmessage(0,  getpminfo(EPMINFO_EDITCLIENT),
  1265.                          5390,
  1266.                          0,
  1267.                          0)
  1268.    endif
  1269. compile endif
  1270.  
  1271. def c_right= call right_word()
  1272. defproc right_word()
  1273. compile if WANT_STREAM_MODE = 'SWITCH'
  1274.    universal stream_mode
  1275. compile endif
  1276. compile if EVERSION < 5
  1277.    call init_operation_on_commandline()
  1278. compile endif
  1279. compile if WANT_CUA_MARKING
  1280.    call begin_shift(startline, startcol, shift_flag)
  1281. compile endif
  1282. compile if WANT_STREAM_MODE
  1283.    getline line
  1284.  compile if WANT_STREAM_MODE = 'SWITCH'
  1285.    if not .line | lastpos(' ',line)<.col & .line<.last & stream_mode $NOT_CMD_STATE then
  1286.  compile else
  1287.    if not .line | lastpos(' ',line)<.col & .line<.last $NOT_CMD_STATE then
  1288.  compile endif
  1289.       down
  1290.       call pfirst_nonblank()
  1291.    else
  1292. compile endif
  1293.       tab_word
  1294. compile if WANT_STREAM_MODE
  1295.    endif
  1296. compile endif
  1297. compile if EVERSION < 5
  1298.    call move_results_to_commandline()
  1299. compile endif
  1300. compile if WANT_CUA_MARKING
  1301.    call end_shift(startline, startcol, shift_flag, 1)
  1302. compile endif
  1303.  
  1304. -- Pop up Search dialog
  1305. compile if EVERSION > 5
  1306. def c_s=
  1307.    'searchdlg'
  1308. compile endif
  1309.  
  1310. def c_t= call put_recorded_keystring()
  1311. compile if EVERSION < 5
  1312. /************************************************************/
  1313. /* Execute the string of keys in Kstring variable.          */
  1314. /* All control keys have the same character (X'00') as the  */
  1315. /* first character of a two-character string                */
  1316. /*                                                          */
  1317. /* The number of keys that may be stored is given by:       */
  1318. /*           256 > n + 2*e                                  */
  1319. /* where:                                                   */
  1320. /*       n are normal data keys (one byte from BIOS)        */
  1321. /*       c are extended code keys (two bytes from BIOS)     */
  1322. /************************************************************/
  1323. defproc put_recorded_keystring()
  1324.    universal Kstring,Kins_state,Kcom_state,inKstring
  1325.  
  1326.    if Kstring=='' then
  1327.       sayerror NO_CTRL_R__MSG              /* HurleyJ */
  1328.       return
  1329.    endif   /* Has a string been recorded? */
  1330.    if Kins_state/==insert_state()   then  insert_toggle endif
  1331.    if Kcom_state/==command_state() then command_toggle endif
  1332.  
  1333.    inKstring=1    /* Set replaying flag; see defproc mgetkey(). */
  1334.    loop
  1335.       k=substr(Kstring,inKstring,1)
  1336.       ksize=1
  1337.       if k==substr(esc,1,1) then       /* extended key ? */
  1338.          k=substr(Kstring,inKstring,2) /* Yes, 2 bytes for extended key. */
  1339.          ksize=2
  1340.       endif
  1341.       inKstring=inKstring+ksize        /* bump index AFTER execution */
  1342.       executekey k
  1343.       if inKstring > length(Kstring) then leave endif
  1344.    endloop
  1345.    inKstring=0
  1346. compile endif
  1347.  
  1348. compile if EPM
  1349. defproc put_recorded_keystring()
  1350.    call windowmessage(0,  getpminfo(EPMINFO_EDITCLIENT),
  1351.                       5392,
  1352.                       0,
  1353.                       0)
  1354.    call windowmessage(0,  getpminfo(EPMINFO_EDITCLIENT),
  1355.                       5391,
  1356.                       0,
  1357.                       0)
  1358. compile endif
  1359.  
  1360. compile if not E3
  1361. def c_tab = keyin \9
  1362. compile endif
  1363.  
  1364. compile if EVERSION >= '5.20'
  1365. def c_u = 'undodlg'
  1366. compile endif
  1367.  
  1368. compile if WANT_STACK_CMDS & not E3
  1369. def c_up =
  1370.    'poppos'
  1371. compile endif
  1372.  
  1373. compile if WANT_WINDOWS
  1374. def c_v= call psplitv()           -- routine defined in WINDOW.E
  1375. def c_w= call pnextwindow()       -- routine defined in WINDOW.E
  1376. def c_z= call pzoom()             -- routine defined in WINDOW.E
  1377. compile endif
  1378.  
  1379. compile if EPM
  1380. def c_W= call mark_word_somehow_else()
  1381. defproc mark_word_somehow_else()
  1382.    if marktype()<>'' then
  1383.       sayerror -279  -- 'Text already marked'
  1384.       return
  1385.    endif
  1386.    if find_token(startcol, endcol) then
  1387.       getfileid fid
  1388.  compile if WANT_CHAR_OPS
  1389.       call pset_mark(.line, .line, startcol, endcol, 'CHAR', fid)
  1390.  compile else
  1391.       call pset_mark(.line, .line, startcol, endcol, 'BLOCK', fid)
  1392.  compile endif
  1393.       'Copy2SharBuff'       /* Copy mark to shared text buffer */
  1394.    endif
  1395. compile endif
  1396.  
  1397. compile if EVERSION >= '5.50'
  1398. def c_Y = 'fontlist'
  1399. compile endif
  1400.  
  1401. def del= call do_del()
  1402. defproc do_del()
  1403. compile if WANT_STREAM_MODE = 'SWITCH'
  1404.    universal stream_mode
  1405. compile endif
  1406. compile if WANT_CUA_MARKING & EPM
  1407.  compile if WANT_CUA_MARKING = 'SWITCH'
  1408.    universal CUA_marking_switch
  1409.    if marktype() & CUA_marking_switch then    -- If there's a mark, then
  1410.  compile else
  1411.    if marktype() then    -- If there's a mark, then
  1412.  compile endif
  1413.       if process_mark_like_cua() then return; endif
  1414.    endif
  1415. compile endif
  1416. compile if WANT_STREAM_MODE
  1417.    if .line then
  1418.       l=length(textline(.line))
  1419.    else
  1420.       l=.col    -- make the following IF fail
  1421.    endif
  1422.  compile if WANT_STREAM_MODE = 'SWITCH'
  1423.    if .col>l & stream_mode $NOT_CMD_STATE then
  1424.  compile else
  1425.    if .col>l $NOT_CMD_STATE then
  1426.  compile endif
  1427.       join
  1428.       .col=l+1
  1429.    else
  1430. compile endif  -- WANT_STREAM_MODE
  1431. compile if EVERSION >= '5.50'
  1432.       old_level = .levelofattributesupport
  1433.  compile if EVERSION >= '6.01b'
  1434.       if old_level & not (old_level bitand 2) then
  1435.  compile else
  1436.       if old_level & not (old_level%2 - 2*(old_level%4)) then
  1437.  compile endif
  1438.          .levelofattributesupport = .levelofattributesupport + 2
  1439.          .cursoroffset = 0
  1440.       endif
  1441. compile endif
  1442.       delete_char
  1443. compile if EVERSION >= '5.50'
  1444.       .levelofattributesupport = old_level
  1445. compile endif
  1446. compile if WANT_STREAM_MODE
  1447.    endif
  1448. compile endif
  1449.  
  1450. def down= call do_down()
  1451. defproc do_down()
  1452. compile if WANT_CUA_MARKING
  1453.  compile if WANT_CUA_MARKING = 'SWITCH'
  1454.    universal CUA_marking_switch
  1455.    if CUA_marking_switch then
  1456.  compile endif
  1457.       unmark
  1458.  compile if WANT_CUA_MARKING = 'SWITCH'
  1459.    endif
  1460.  compile endif
  1461. compile endif
  1462. compile if WANT_STREAM_MODE
  1463.    call updownkey(1)
  1464. compile else
  1465.    down
  1466. compile endif
  1467.  
  1468. compile if WANT_CUA_MARKING & EPM
  1469. def s_down= call mark_down()
  1470. defproc mark_down()
  1471.  compile if WANT_CUA_MARKING = 'SWITCH'
  1472.    universal CUA_marking_switch
  1473.  compile endif
  1474.    startline = .line; startcol = .col
  1475. compile if WANT_STREAM_MODE
  1476.    call updownkey(1)
  1477. compile else
  1478.    down
  1479. compile endif
  1480. ;compile if WANT_CUA_MARKING = 'SWITCH'
  1481. ;  if CUA_marking_switch then
  1482. ;compile endif
  1483.    if startline then call extend_mark(startline, startcol, 1); endif
  1484. ;compile if WANT_CUA_MARKING = 'SWITCH'
  1485. ;  endif
  1486. ;compile endif
  1487. compile endif
  1488.  
  1489. def end= call do_end()
  1490. defproc do_end()
  1491. compile if WANT_CUA_MARKING
  1492.  compile if WANT_CUA_MARKING = 'SWITCH'
  1493.    universal CUA_marking_switch
  1494.    if CUA_marking_switch then
  1495.  compile endif
  1496.       unmark
  1497.  compile if WANT_CUA_MARKING = 'SWITCH'
  1498.    endif
  1499.  compile endif
  1500. compile endif
  1501.    end_line
  1502.  
  1503. compile if WANT_CUA_MARKING & EPM
  1504. def s_end = call mark_to_eol()
  1505. defproc mark_to_eol()
  1506.    startline = .line; startcol = .col
  1507.    end_line
  1508.    call extend_mark(startline, startcol, 1)
  1509. compile endif
  1510.  
  1511. compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''  -- define each key separately
  1512. def enter =
  1513.    universal enterkey
  1514.  compile if WANT_EPM_SHELL & (EPM_SHELL_PROMPT = '@prompt epm: $p $g' | EPM_SHELL_PROMPT = '@prompt [epm: $p ]')
  1515.    call shell_enter_routine(enterkey)
  1516.  compile else
  1517.    call henter_common(enterkey)  --- herbert: changed this to my own routine!
  1518.  compile endif
  1519. def a_enter =
  1520.    universal a_enterkey
  1521.    call henter_common(a_enterkey)
  1522. def c_enter =
  1523.    universal c_enterkey
  1524.    call henter_common(c_enterkey)
  1525. def s_enter =
  1526.    universal s_enterkey
  1527.    call henter_common(s_enterkey)
  1528. def padenter =
  1529.    universal padenterkey
  1530.  compile if WANT_EPM_SHELL & (EPM_SHELL_PROMPT = '@prompt epm: $p $g' | EPM_SHELL_PROMPT = '@prompt [epm: $p ]')
  1531.    call shell_enter_routine(padenterkey)
  1532.  compile else
  1533.    call henter_common(padenterkey)
  1534.  compile endif
  1535. def a_padenter =
  1536.    universal a_padenterkey
  1537.    call henter_common(a_padenterkey)
  1538. def c_padenter =
  1539.    universal c_padenterkey
  1540.    call enter_common(c_padenterkey)
  1541. def s_padenter =
  1542.    universal s_padenterkey
  1543.    call henter_common(s_padenterkey)
  1544.  compile if WANT_EPM_SHELL & (EPM_SHELL_PROMPT = '@prompt epm: $p $g' | EPM_SHELL_PROMPT = '@prompt [epm: $p ]')
  1545. defproc shell_enter_routine(xxx_enterkey)
  1546.    if leftstr(.filename, 15) = ".command_shell_" then
  1547.       shellnum=substr(.filename,16)
  1548.       getline line
  1549.   compile if EPM_SHELL_PROMPT = '@prompt epm: $p $g'
  1550.       x = pos('>',line)
  1551.   compile else
  1552.       x = pos(']',line)
  1553.   compile endif
  1554.       text = substr(line,x+1)
  1555.   compile if EPM_SHELL_PROMPT = '@prompt epm: $p $g'
  1556.       if leftstr(line,5)='epm: ' & x & shellnum /*& text<>''*/ then
  1557.   compile else
  1558.       if leftstr(line,6)='[epm: ' & x & shellnum /*& text<>''*/ then
  1559.   compile endif
  1560.          if .line=.last then .col=x+1; erase_end_line; endif
  1561.          'shell_write' shellnum text
  1562.       else
  1563.          call henter_common(xxx_enterkey)
  1564.       endif
  1565.    else
  1566.       call henter_common(xxx_enterkey)
  1567.    endif
  1568.  compile endif  -- EPM_SHELL
  1569.  
  1570. compile else
  1571.  compile if EVERSION >= '4.10'
  1572.   compile if EVERSION < 5
  1573. def enter, pad_enter, a_enter, a_pad_enter=  --4.10: new enhanced keyboard keys
  1574.   compile else
  1575. def enter, pad_enter, a_enter, a_pad_enter, s_enter, s_padenter=
  1576.   compile endif
  1577.  compile else
  1578. def enter=
  1579.  compile endif
  1580.  compile if WANT_EPM_SHELL & (EPM_SHELL_PROMPT = '@prompt epm: $p $g' | EPM_SHELL_PROMPT = '@prompt [epm: $p ]')
  1581.    if leftstr(.filename, 15) = ".command_shell_" then
  1582.       shellnum=substr(.filename,16)
  1583.       getline line
  1584.   compile if EPM_SHELL_PROMPT = '@prompt epm: $p $g'
  1585.       x = pos('>',line)
  1586.   compile else
  1587.       x = pos(']',line)
  1588.   compile endif
  1589.       text = substr(line,x+1)
  1590.   compile if EPM_SHELL_PROMPT = '@prompt epm: $p $g'
  1591.       if leftstr(line,5)='epm: ' & x & shellnum /*& text<>''*/ then
  1592.   compile else
  1593.       if leftstr(line,6)='[epm: ' & x & shellnum /*& text<>''*/ then
  1594.   compile endif
  1595.          if .line=.last then .col=x+1; erase_end_line; endif
  1596.          'shell_write' shellnum text
  1597.       else
  1598.          call my_enter()
  1599.       endif
  1600.    else
  1601.  compile endif
  1602.    call my_enter()
  1603.  compile if E3 and SHOW_MODIFY_METHOD
  1604.    call show_modify()
  1605.  compile endif
  1606.  compile if WANT_EPM_SHELL & (EPM_SHELL_PROMPT = '@prompt epm: $p $g' | EPM_SHELL_PROMPT = '@prompt [epm: $p ]')
  1607.   endif
  1608.  compile endif
  1609. compile endif  -- ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''
  1610.  
  1611. compile if not defined(NO_ESCAPE)
  1612.    const NO_ESCAPE = 0
  1613. compile endif
  1614.  
  1615. compile if EVERSION < 5
  1616. def esc= call escape_key_()
  1617. defproc escape_key_()
  1618.    command_toggle
  1619.  compile if E3 and SHOW_MODIFY_METHOD
  1620.    call show_modify()
  1621.  compile endif
  1622. compile else  -- else EPM
  1623.  compile if NO_ESCAPE  -- Blame CUA  :-(
  1624. def esc= call escape_key_()
  1625. defproc escape_key_()
  1626.   compile if TOGGLE_ESCAPE
  1627.    universal ESCAPE_KEY
  1628.   compile endif
  1629.  compile else
  1630. def esc, c_i = call escape_key_()
  1631. defproc escape_key_()
  1632.  compile endif
  1633.    universal alt_R_active
  1634.  
  1635.    sayerror 0
  1636.    if alt_R_active<>'' then
  1637.  compile if EVERSION < '5.21'
  1638.       .messageline=''                        -- Turn off the message.
  1639.  compile else
  1640.        'setmessageline '\0
  1641.  compile endif
  1642.  compile if EVERSION >= '5.53'
  1643.       'toggleframe 2 'alt_R_active         -- Restore status of messageline.
  1644.  compile else
  1645.       'togglecontrol 8 'alt_R_active         -- Restore status of messageline.
  1646.  compile endif
  1647.       alt_R_active = ''
  1648.  compile if NO_ESCAPE
  1649.   compile if TOGGLE_ESCAPE
  1650.    elseif ESCAPE_KEY then
  1651.       'commandline'
  1652.   compile endif
  1653.    endif
  1654. def c_I='commandline'
  1655.  compile else
  1656.    else
  1657.       'commandline'
  1658.    endif
  1659.  compile endif  -- no Escape
  1660. compile endif  -- EPM
  1661.  
  1662. def f1= 'help'
  1663.  
  1664. def f2= call save_file()
  1665. defproc save_file()
  1666. compile if SMARTSAVE
  1667.    if .modify then           -- Modified since last Save?
  1668.       'Save'                 --   Yes - save it
  1669.    else
  1670.  compile if EPM
  1671.       'commandline Save '
  1672.  compile else
  1673.       if not command_state() then
  1674.          cursor_command
  1675.       endif
  1676.       begin_line;erase_end_line
  1677.       keyin 'Save '
  1678.  compile endif
  1679.       sayerror 'No changes.  Press Enter to Save anyway.'
  1680.    endif
  1681. compile else
  1682.    'Save'
  1683. compile endif
  1684.  
  1685. def f3= 'quit'
  1686.  
  1687. def f4= call save_and_quit_file()
  1688. defproc save_and_quit_file()
  1689. compile if SMARTFILE
  1690.    if .modify then           -- Modified since last Save?
  1691.       'File'                 --   Yes - save it and quit.
  1692.    else
  1693.       'Quit'                 --   No - just quit.
  1694.    endif
  1695. compile else
  1696.    'File'
  1697. compile endif
  1698.  
  1699. compile if EVERSION < 5
  1700. def f7= call change_filename()
  1701. defproc change_filename()
  1702. cursor_command; delete; begin_line; keyin 'Name '
  1703. def f8= call add_file()
  1704. defproc add_file()
  1705. cursor_command; delete; begin_line; keyin 'Edit '
  1706. compile else
  1707.                     /* keys by EPM */
  1708. def f5, c_O='OPENDLG'
  1709. def f7= call change_filename()
  1710. defproc change_filename()
  1711. 'rename'
  1712. def f8= call add_file()
  1713. defproc add_file()
  1714.  compile if RING_OPTIONAL
  1715.    universal ring_enabled
  1716.    if not ring_enabled then
  1717.       sayerror NO_RING__MSG
  1718.       return
  1719.    endif
  1720.  compile endif
  1721.    'OPENDLG EDIT'
  1722. compile endif
  1723.  
  1724. compile if EVERSION < 5
  1725. def f9=
  1726. compile else
  1727. def f9, a_backspace = 
  1728. compile endif
  1729. call simple_undo()
  1730. defproc simple_undo()
  1731. undo
  1732.  
  1733. compile if EVERSION < 5
  1734.  compile if EVERSION < '4.10'          -- Early E doesn't support enh. kbd.
  1735. def f10,c_N= call next_file_()
  1736. defproc next_file_()  call pnextfile()  -- routine defined in WINDOW.E
  1737.  compile else
  1738. def f10,f12,c_N= call next_file_()
  1739. defproc next_file_()  call pnextfile()  -- routine defined in WINDOW.E
  1740.  compile endif
  1741. compile else
  1742. def f10,f12,c_N= call next_file_()
  1743. defproc next_file_() -- F10 is usual E default; F12 for enhanced kbd, c_N for EPM.
  1744.    nextfile
  1745. compile endif
  1746.  
  1747.  
  1748. def home = call do_home()
  1749. defproc do_home()
  1750. compile if WANT_CUA_MARKING
  1751.  compile if WANT_CUA_MARKING = 'SWITCH'
  1752.    universal CUA_marking_switch
  1753.    if CUA_marking_switch then
  1754.  compile endif
  1755.       unmark
  1756.  compile if WANT_CUA_MARKING = 'SWITCH'
  1757.    endif
  1758.  compile endif
  1759. compile endif
  1760.    begin_line
  1761.  
  1762. compile if WANT_CUA_MARKING & EPM
  1763. def s_home = call mark_to_bol()
  1764. defproc mark_to_bol()
  1765.    startline = .line; startcol = .col
  1766.    begin_line
  1767.    call extend_mark(startline, startcol, 0)
  1768. compile endif
  1769.  
  1770. def ins= call toggle_insert()
  1771. defproc toggle_insert()
  1772. insert_toggle
  1773. compile if EVERSION >='5.50'
  1774.    call fixup_cursor()
  1775. compile endif
  1776.  
  1777. def left= call do_left()
  1778. defproc do_left()
  1779. compile if WANT_CUA_MARKING = 'SWITCH'
  1780.    universal CUA_marking_switch
  1781. compile endif
  1782. compile if WANT_STREAM_MODE = 'SWITCH'
  1783.    universal stream_mode
  1784.    if .line>1 & .col=1 & stream_mode $NOT_CMD_STATE then up; end_line; else left; endif
  1785. compile elseif WANT_STREAM_MODE
  1786.    if .line>1 & .col=1 $NOT_CMD_STATE then up; end_line; else left; endif
  1787. compile else
  1788.    left
  1789. compile endif
  1790. compile if WANT_CUA_MARKING
  1791.  compile if WANT_CUA_MARKING = 'SWITCH'
  1792.    if CUA_marking_switch then
  1793.  compile endif
  1794.       unmark
  1795.  compile if WANT_CUA_MARKING = 'SWITCH'
  1796.    endif
  1797.  compile endif
  1798. compile endif
  1799.  
  1800. compile if WANT_CUA_MARKING & EPM
  1801. def s_left = call mark_left()
  1802. defproc mark_left()
  1803.    startline = .line; startcol = .col
  1804.    if .line>1 & .col=1 then up; end_line; else left; endif
  1805.    call extend_mark(startline, startcol, 0)
  1806. compile endif
  1807.  
  1808. compile if EVERSION < 5
  1809. def padminus=keyin '-'
  1810. def padplus=keyin '+'
  1811.  compile if EVERSION >= '4.10'
  1812. def padslash, c_padslash =keyin '/'     -- 4.10 for enhanced keyboard
  1813.  compile endif
  1814. def padstar=keyin '*'
  1815. compile endif
  1816.  
  1817. def pgup = call do_pgup()
  1818. defproc do_pgup()
  1819. compile if WANT_CUA_MARKING
  1820.  compile if WANT_CUA_MARKING = 'SWITCH'
  1821.    universal CUA_marking_switch
  1822.    if CUA_marking_switch then
  1823.  compile endif
  1824.       unmark
  1825.  compile if WANT_CUA_MARKING = 'SWITCH'
  1826.    endif
  1827.  compile endif
  1828. compile endif
  1829.    page_up
  1830.  
  1831. def pgdn = call do_pgdn()
  1832. defproc do_pgdn()
  1833. compile if WANT_CUA_MARKING
  1834.  compile if WANT_CUA_MARKING = 'SWITCH'
  1835.    universal CUA_marking_switch
  1836.    if CUA_marking_switch then
  1837.  compile endif
  1838.       unmark
  1839.  compile if WANT_CUA_MARKING = 'SWITCH'
  1840.    endif
  1841.  compile endif
  1842. compile endif
  1843.    page_down
  1844.  
  1845. compile if EPM
  1846. def s_pgup= call mark_pgup()
  1847. defproc mark_pgup()
  1848.  compile if TOP_OF_FILE_VALID = 'STREAM' & WANT_STREAM_MODE = 'SWITCH'
  1849.    universal stream_mode
  1850.  compile endif
  1851.    startline = .line; startcol = .col
  1852.    page_up
  1853.    if .line then call extend_mark(startline, startcol, 0); endif
  1854.  compile if TOP_OF_FILE_VALID = 'STREAM' & WANT_STREAM_MODE = 'SWITCH'
  1855.    if not .line & stream_mode then '+1'; endif
  1856.  compile elseif not TOP_OF_FILE_VALID
  1857.    if not .line then '+1'; endif
  1858.  compile endif
  1859.  
  1860. def s_pgdn= call mark_pgdn()
  1861. defproc mark_pgdn()
  1862.    startline = .line; startcol = .col
  1863.    page_down
  1864.    if startline then call extend_mark(startline, startcol, 1); endif
  1865. compile endif
  1866.  
  1867. def right= call do_right()
  1868. defproc do_right()
  1869. compile if WANT_STREAM_MODE = 'SWITCH'
  1870.    universal stream_mode
  1871. compile endif
  1872. compile if WANT_CUA_MARKING
  1873.  compile if WANT_CUA_MARKING = 'SWITCH'
  1874.    universal CUA_marking_switch
  1875.    if CUA_marking_switch then
  1876.  compile endif
  1877.       unmark
  1878.  compile if WANT_CUA_MARKING = 'SWITCH'
  1879.    endif
  1880.  compile endif
  1881. compile endif
  1882. compile if WANT_STREAM_MODE
  1883.    if .line then l=length(textline(.line)); else l=.col; endif
  1884.  compile if WANT_STREAM_MODE = 'SWITCH'
  1885.    if .line<.last & .col>l & stream_mode $NOT_CMD_STATE then
  1886.  compile else
  1887.    if .line<.last & .col>l $NOT_CMD_STATE then
  1888.  compile endif
  1889.       down; begin_line
  1890.  compile if WANT_STREAM_MODE = 'SWITCH'
  1891.    elseif .line=.last & .col>l & stream_mode $NOT_CMD_STATE then   -- nop
  1892.  compile else
  1893.    elseif .line=.last & .col>l $NOT_CMD_STATE then  -- nop
  1894.  compile endif
  1895.    else
  1896.       right
  1897.    endif
  1898. compile else
  1899.    right
  1900. compile endif
  1901.  
  1902. compile if WANT_CUA_MARKING & EPM
  1903. def s_right = call mark_right()
  1904. defproc mark_right()
  1905.    startline = .line; startcol = .col
  1906.    if .line then l=length(textline(.line)); else l=.col; endif
  1907.    if .line<.last & .col>l then
  1908.       down; begin_line
  1909.    elseif .line<>.last | .col<=l then
  1910.       right
  1911.    endif
  1912.    call extend_mark(startline, startcol, 1)
  1913. compile endif
  1914.  
  1915.  
  1916. def s_f1= call scroll_left() /* scroll left */
  1917. defproc scroll_left()
  1918. compile if WANT_CUA_MARKING
  1919.  compile if WANT_CUA_MARKING = 'SWITCH'
  1920.    universal CUA_marking_switch
  1921.    if CUA_marking_switch then
  1922.  compile endif
  1923.       unmark
  1924.  compile if WANT_CUA_MARKING = 'SWITCH'
  1925.    endif
  1926.  compile endif
  1927. compile endif
  1928.    oldcursorx=.cursorx
  1929.    if .col-.cursorx then
  1930.       .col=.col-.cursorx
  1931.       .cursorx=oldcursorx
  1932.    elseif .cursorx>1 then
  1933.       left
  1934.    endif
  1935.  
  1936. def s_f2= call scroll_right() /* scroll right */
  1937. defproc scroll_right()
  1938. compile if WANT_CUA_MARKING
  1939.  compile if WANT_CUA_MARKING = 'SWITCH'
  1940.    universal CUA_marking_switch
  1941.    if CUA_marking_switch then
  1942.  compile endif
  1943.       unmark
  1944.  compile if WANT_CUA_MARKING = 'SWITCH'
  1945.    endif
  1946.  compile endif
  1947. compile endif
  1948.   oldcursorx=.cursorx
  1949.   a=.col+.windowwidth-.cursorx+1
  1950.   if a<=MAXCOL then
  1951.      .col=a
  1952.      .cursorx=oldcursorx
  1953.   elseif .col<MAXCOL then
  1954.      right
  1955.   endif
  1956.  
  1957. def s_f3= call scroll_up()  /* scroll up */
  1958. defproc scroll_up()
  1959. compile if WANT_CUA_MARKING
  1960.  compile if WANT_CUA_MARKING = 'SWITCH'
  1961.    universal CUA_marking_switch
  1962.    if CUA_marking_switch then
  1963.  compile endif
  1964.       unmark
  1965.  compile if WANT_CUA_MARKING = 'SWITCH'
  1966.    endif
  1967.  compile endif
  1968. compile endif
  1969.   oldcursory=.cursory
  1970.   if .line-.cursory>-1 then
  1971.      .cursory=1
  1972.      up
  1973.      .cursory=oldcursory
  1974.   elseif .line then
  1975.      up
  1976.   endif
  1977.  
  1978. def s_f4= call scroll_down() /* scroll down */
  1979. defproc scroll_down()
  1980. compile if WANT_CUA_MARKING
  1981.  compile if WANT_CUA_MARKING = 'SWITCH'
  1982.    universal CUA_marking_switch
  1983.    if CUA_marking_switch then
  1984.  compile endif
  1985.       unmark
  1986.  compile if WANT_CUA_MARKING = 'SWITCH'
  1987.    endif
  1988.  compile endif
  1989. compile endif
  1990.    oldcursory=.cursory
  1991.    if .line -.cursory+.windowheight<.last then
  1992.       .cursory=.windowheight
  1993.       down
  1994.       .cursory=oldcursory
  1995.    elseif .line<.last then
  1996.       down
  1997.    endif
  1998.  
  1999. def s_f5= call center_line_vert()  /* center current line */
  2000. defproc center_line_vert()
  2001. compile if WANT_CUA_MARKING
  2002.  compile if WANT_CUA_MARKING = 'SWITCH'
  2003.    universal CUA_marking_switch
  2004.    if CUA_marking_switch then
  2005.  compile endif
  2006.       unmark
  2007.  compile if WANT_CUA_MARKING = 'SWITCH'
  2008.    endif
  2009.  compile endif
  2010. compile endif
  2011.    oldline=.line
  2012.    .cursory=.windowheight%2
  2013.    oldline
  2014.  
  2015. compile if WANT_TAGS
  2016. def s_f6 = 'findtag'
  2017. def s_f7 = 'findtag *'
  2018. def s_f8 = 'tagsfile'
  2019. def s_f9 = 'maketags *'
  2020. compile endif -- WANT_TAGS
  2021.  
  2022. compile if EVERSION < 5
  2023. def s_pad5=keyin '5'
  2024. compile endif
  2025.  
  2026. def s_tab= call back_tab()
  2027. defproc back_tab()
  2028.    universal matchtab_on
  2029. compile if WANT_CUA_MARKING
  2030.  compile if WANT_CUA_MARKING = 'SWITCH'
  2031.    universal CUA_marking_switch
  2032.    if CUA_marking_switch then
  2033.  compile endif
  2034.       unmark
  2035.  compile if WANT_CUA_MARKING = 'SWITCH'
  2036.    endif
  2037.  compile endif
  2038. compile endif
  2039. compile if EVERSION < 5
  2040.    call init_operation_on_commandline()
  2041. compile endif
  2042.    if matchtab_on & .line>1 $NOT_CMD_STATE then
  2043.       up
  2044.       backtab_word
  2045.       down
  2046.    else
  2047.       backtab
  2048.    endif
  2049. compile if EVERSION < 5
  2050.    call move_results_to_commandline()
  2051. compile endif
  2052.  
  2053. compile if EPM
  2054. def space, s_space, c_space = call do_space()  /* New in EPM.  Space is a virtual key under PM.*/
  2055. defproc do_space()
  2056.  compile if WANT_CUA_MARKING
  2057.   compile if WANT_CUA_MARKING = 'SWITCH'
  2058.    universal CUA_marking_switch
  2059.    if CUA_marking_switch then
  2060.   compile endif
  2061.       call process_mark_like_cua()
  2062.   compile if WANT_CUA_MARKING = 'SWITCH'
  2063.    endif
  2064.   compile endif
  2065.  compile endif
  2066.  compile if EVERSION >= '5.20'
  2067.    k=lastkey(1)
  2068.  compile endif
  2069.    keyin ' '
  2070.  compile if EVERSION >= '5.20'
  2071.    if k<>' ' then
  2072.       undoaction 1, junk                -- Create a new state
  2073.    endif
  2074.  compile endif
  2075. compile endif
  2076.  
  2077. def tab= call do_tab()
  2078. defproc do_tab()
  2079. compile if WANT_STREAM_MODE = 'SWITCH'
  2080.    universal stream_mode
  2081. compile endif
  2082.    universal matchtab_on
  2083. compile if TOGGLE_TAB
  2084.    universal TAB_KEY
  2085. compile endif
  2086. compile if WANT_CUA_MARKING = 'SWITCH'
  2087.    universal CUA_marking_switch
  2088. compile endif
  2089. compile if WANT_DBCS_SUPPORT
  2090.    universal ondbcs
  2091. compile endif
  2092.                   -------Start of logic:
  2093. compile if TOGGLE_TAB
  2094.    if TAB_KEY then
  2095.  compile if WANT_CUA_MARKING
  2096.   compile if WANT_CUA_MARKING = 'SWITCH'
  2097.       if CUA_marking_switch then
  2098.   compile endif
  2099.           process_key(\9)
  2100.   compile if WANT_CUA_MARKING = 'SWITCH'
  2101.       else
  2102.   compile endif
  2103.  compile endif  -- WANT_CUA_MARKING
  2104.          keyin \9
  2105.  compile if WANT_CUA_MARKING = 'SWITCH'
  2106.       endif
  2107.  compile endif
  2108.    else
  2109. compile endif  -- TOGGLE_TAB
  2110. compile if WANT_CUA_MARKING
  2111.  compile if WANT_CUA_MARKING = 'SWITCH'
  2112.    if CUA_marking_switch then
  2113.  compile endif
  2114.       unmark
  2115.  compile if WANT_CUA_MARKING = 'SWITCH'
  2116.    endif
  2117.  compile endif
  2118. compile endif
  2119. compile if EVERSION < 5
  2120.    call init_operation_on_commandline()
  2121. compile endif
  2122.    oldcol=.col
  2123.    if matchtab_on and .line>1 $NOT_CMD_STATE then
  2124.       up
  2125. ;;    c=.col  -- Unused ???
  2126.       tab_word
  2127.       if oldcol>=.col then
  2128.          .col=oldcol
  2129.          tab
  2130.       endif
  2131.       down
  2132.    else
  2133.       tab
  2134.    endif
  2135. compile if WANT_STREAM_MODE | WANT_TAB_INSERTION_TO_SPACE
  2136.  compile if WANT_STREAM_MODE = 'SWITCH' and not WANT_TAB_INSERTION_TO_SPACE
  2137.    if insertstate() & stream_mode $NOT_CMD_STATE then
  2138.  compile else
  2139.    if insertstate() $NOT_CMD_STATE then
  2140.  compile endif
  2141.       numspc=.col-oldcol
  2142.  compile if WANT_DBCS_SUPPORT
  2143.       if ondbcs then                                           -- If we're on DBCS,
  2144.          if not (matchtab_on and .line>1 $NOT_CMD_STATE) then  -- and didn't do a matchtab,
  2145.   compile if EPM32
  2146.             if words(.tabs) > 1 then
  2147.   compile endif
  2148.                if not wordpos(.col, .tabs) then                   -- check if on a tab col.
  2149.                   do i=1 to words(.tabs)              -- If we got shifted due to being inside a DBC,
  2150.                      if word(.tabs, i) > oldcol then  -- find the col we *should* be in, and
  2151.                         numspc = word(.tabs, i) - oldcol  -- set numspc according to that.
  2152.                         leave
  2153.                      endif
  2154.                   enddo
  2155.                endif
  2156.   compile if EPM32
  2157.             elseif (.col // .tabs) <> 1 then
  2158.                numspc = .tabs - (oldcol+.tabs-1) // .tabs
  2159.             endif
  2160.   compile endif
  2161.          endif
  2162.       endif
  2163.  compile endif
  2164.       if numspc>0 then
  2165.          .col=oldcol
  2166.          keyin substr('',1,numspc)
  2167.       endif
  2168.    endif
  2169. compile endif
  2170. compile if EVERSION < 5
  2171.    call move_results_to_commandline()
  2172. compile endif
  2173. compile if TOGGLE_TAB
  2174.    endif
  2175. compile endif  -- TOGGLE_TAB
  2176.  
  2177.  
  2178. def up= call do_up()
  2179. defproc do_up()
  2180. compile if TOP_OF_FILE_VALID = 'STREAM' & WANT_STREAM_MODE = 'SWITCH'
  2181.    universal stream_mode
  2182. compile endif
  2183. compile if WANT_CUA_MARKING
  2184.  compile if WANT_CUA_MARKING = 'SWITCH'
  2185.    universal CUA_marking_switch
  2186.    if CUA_marking_switch then
  2187.  compile endif
  2188.       unmark
  2189.  compile if WANT_CUA_MARKING = 'SWITCH'
  2190.    endif
  2191.  compile endif
  2192. compile endif
  2193. compile if WANT_STREAM_MODE
  2194.    call updownkey(0)
  2195. compile else
  2196.    up
  2197. compile endif
  2198. compile if TOP_OF_FILE_VALID = 'STREAM' & WANT_STREAM_MODE = 'SWITCH'
  2199.    if not .line & stream_mode then '+1'; endif
  2200. compile elseif not TOP_OF_FILE_VALID
  2201.    if not .line then '+1'; endif
  2202. compile endif
  2203.  
  2204. compile if WANT_CUA_MARKING & EPM
  2205. def s_up= call mark_up()
  2206. defproc mark_up()
  2207.  compile if TOP_OF_FILE_VALID = 'STREAM' & WANT_STREAM_MODE = 'SWITCH'
  2208.    universal stream_mode
  2209.  compile endif
  2210.  compile if WANT_CUA_MARKING = 'SWITCH'
  2211.    universal CUA_marking_switch
  2212.  compile endif
  2213.    startline = .line; startcol = .col
  2214.  compile if WANT_STREAM_MODE
  2215.    call updownkey(0)
  2216.  compile else
  2217.    up
  2218.  compile endif
  2219. ;compile if WANT_CUA_MARKING = 'SWITCH'
  2220. ;  if CUA_marking_switch then
  2221. ;compile endif
  2222.    if .line then call extend_mark(startline, startcol, 0); endif
  2223. ;compile if WANT_CUA_MARKING = 'SWITCH'
  2224. ;  endif
  2225. ;compile endif
  2226.  compile if TOP_OF_FILE_VALID = 'STREAM' & WANT_STREAM_MODE = 'SWITCH'
  2227.    if not .line & stream_mode then '+1'; endif
  2228.  compile elseif not TOP_OF_FILE_VALID
  2229.    if not .line then '+1'; endif
  2230.  compile endif
  2231. compile endif
  2232.  
  2233. compile if EPM  -- Standard PM clipboard functions.
  2234. def s_del = 'cut'
  2235.  
  2236. def s_ins = call do_ins()
  2237. defproc do_ins()
  2238.  compile if WANT_CUA_MARKING = 'SWITCH'
  2239.    universal CUA_marking_switch
  2240.    if CUA_marking_switch then
  2241.  compile endif
  2242.  compile if WANT_CUA_MARKING
  2243.       call process_mark_like_cua()
  2244.  compile endif
  2245.  compile if WANT_CUA_MARKING = 'SWITCH'
  2246.    endif
  2247.  compile endif
  2248.    'paste' DEFAULT_PASTE
  2249.  
  2250. def c_ins = 'copy2clip'
  2251. compile endif
  2252.  
  2253. compile if WANT_STREAM_MODE
  2254. defproc updownkey(down_flag)
  2255.    universal save_cursor_column
  2256.  compile if WANT_STREAM_MODE = 'SWITCH'
  2257.    universal stream_mode
  2258.    if stream_mode then
  2259.  compile endif
  2260.       lk = lastkey(1)
  2261.  compile if EPM
  2262.       updn = pos(leftstr(lk,1),\x18\x16) & pos(substr(lk,2,1),\x02\x0A\x12)   -- VK_DOWN or VK_UP, plain or Shift or Ctrl
  2263.  compile else
  2264.       updn = substr(lk,1,1)=\0 & pos(substr(lk,2,1),\x48\x50\x98\xA0\x8d\x91) -- Up, down, a_up, a_down, c_up, c_down
  2265.  compile endif
  2266.       if not updn then save_cursor_column = .col; endif
  2267.  compile if WANT_STREAM_MODE = 'SWITCH'
  2268.    endif
  2269.  compile endif
  2270.  
  2271.    if down_flag then down else up endif
  2272.  
  2273.  compile if WANT_STREAM_MODE = 'SWITCH'
  2274.    if .line & stream_mode then
  2275.  compile else
  2276.    if .line then
  2277.  compile endif
  2278.       l = length(textline(.line))
  2279.       if updn & l>=save_cursor_column then
  2280.          .col = save_cursor_column
  2281.       elseif updn | l<.col then
  2282.          end_line
  2283.       endif
  2284.    endif
  2285. compile endif  -- WANT_STREAM_MODE
  2286.  
  2287. /* ------ Keys unused in standard E ------------------------------------------
  2288.  
  2289. a_2, a_3, a_5, a_6, a_7, a_8, a_9
  2290.  
  2291. a_f2, a_f3, a_f4, a_f5, a_f6, a_f9
  2292.  
  2293. a_g, a_h, a_i, a_k, a_q, a_v
  2294.  
  2295. c_6, c_minus, c_backslash
  2296.  
  2297. c_leftbracket, c_rightbracket, (EOS2 only:) a_leftbracket, a_rightbracket
  2298.  
  2299. c_f9, c_f10
  2300.  
  2301. c_g, c_i, c_j, c_prtsc, c_q, c_u
  2302.  
  2303. f5
  2304.  
  2305. s_f6, s_f7, s_f8, s_f9, s_f10
  2306.  
  2307. -----  The following is for EOS2 4.10 or above only.  -----
  2308.  
  2309. New keys that work on even older unenhanced AT keyboards:
  2310.    c_up, c_down
  2311.    pad5, c_pad5
  2312.    c_padminus, c_padplus, c_padstar
  2313.    c_ins, c_del
  2314.    c_tab, a_tab
  2315.    a_leftbracket, a_rightbracket
  2316.  
  2317. On an enhanced keyboard only:
  2318.    f11, f12, and c_,s_,a_
  2319.    pad_enter               is defined the same as enter
  2320.    a_enter and a_padenter are defined the same as enter
  2321.    c_pad_enter             is defined the same as c_enter
  2322.    pad_slash               is defined the same as '/'
  2323.    c_padslash              is defined the same as '/'
  2324.  
  2325. -----  The following is for EPM only.  -----
  2326.   * Since we are using only keys defined by PM (and not looking at
  2327.     scan codes), we no longer have the keys:
  2328.       padplus, c_padplus, c_padstar
  2329.       pad_slash, c_padslash
  2330.       pad5, c_pad5
  2331.    * We gained the new keys:
  2332.     - space, s_space, c_space, and a_space
  2333.          (The space bar is a virtual key to PM, not a character key.  If you
  2334.          want to bind an action to the space key, write  def space=  instead of
  2335.          the old  def ' '= .  The good news is that you get all the shift
  2336.          states of the space bar, although alt_space is preempted by PM.)
  2337.     - c_1 through c_0
  2338.          (So now we have a complete set of alt- and ctrl-digits.)
  2339. ---------------------------------------------------------------------------- */
  2340.  
  2341.