home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 16 / 16.iso / w / w055 / 4.ddi / SOURCES.LIF / EPSILON.PEL < prev    next >
Encoding:
Text File  |  1990-09-27  |  43.6 KB  |  2,193 lines

  1. # $Header:   P:/source/ppee/macros/epsilon.pev   1.17   13 Jul 1990 19:31:12   skipr  $
  2.  
  3. ##############################################################################
  4. #
  5. #           Sage Software - POLYTRON Division
  6. #             1700 NW 167th Place
  7. #               Beaverton, OR 97006
  8. #
  9. #   Copyright 1990, Sage Software, Inc.
  10. #
  11. #   Permission is hereby granted for licensed users of Sage Professional
  12. #   Editor and PolyAwk to copy and modify this source code for their own
  13. #   personal use.  These derivative works may be distributed only to other
  14. #   licensed Sage Professional Editor and PolyAwk users.  All other usage
  15. #   is prohibited without express written permission from Sage Software.
  16. #
  17. ##############################################################################
  18.  
  19. #### $Workfile:   epsilon.pel  $: Key bindings for Epsilon compatibility
  20.  
  21. # local variables:
  22.  
  23. local markx;
  24. local marky;
  25. local lastsearch;
  26. local epsacc = 0;
  27. local last_was_kill = FALSE;
  28. local keymac;
  29. local savedmacs;
  30. local killbuffers;
  31. local currentkill=0;
  32. local lastyankx1 = (-1);
  33. local lastyanky1 = (-1);
  34. local lastyankx2 = (-1);
  35. local lastyanky2 = (-1);
  36. local errfile;
  37. local makebuffer = 0;
  38. local eps_sta_file = 0;
  39. local eps_sta_name = "emeps.sta";
  40.  
  41. local ctrlx_keymap;
  42. local epsilon_keymap = -1;
  43.  
  44. # establish epsilon mode:
  45.  
  46. global function epsilon()
  47. {
  48.     local i;
  49.     markx = 0;
  50.     marky = 0;
  51.  
  52.     toggle_dialog(1);
  53.  
  54.     if (eps_read_state())
  55.         return
  56.  
  57.     emulation_mode = "epsilon"
  58.  
  59.     # Enable the keymap.  Subsequent mods to the keymap will persist
  60.     #    through the end of the session.
  61.     # Only one-time initialization should follow this point.
  62.  
  63.     if( epsilon_keymap >= 0 ){
  64.         current_keymap = epsilon_keymap
  65.         return
  66.     }
  67.  
  68.     for (i=0; i<6; i++)
  69.         killbuffers[i] = create_buffer( "killbuffer" i,
  70.             "", BUFFER_SYSTEM );
  71.  
  72.     ctrlx_keymap = current_keymap = create_keymap(empty_keymap);
  73.  
  74.     assign_key( "<Ctrl-B>", "eps_bufed" );
  75.     assign_key( "<Ctrl-C>", "eps_exit" );
  76.     assign_key( "<Ctrl-D>", "eps_kill_window" );
  77.     assign_key( "<Ctrl-E>", "eps_push" );
  78.     assign_key( "<Ctrl-F>", "eps_find_file" );
  79.     assign_key( "<Ctrl-I>", "eps_indent_rigidly" );
  80.     assign_key( "<Ctrl-M>", "eps_start_process" );
  81.     assign_key( "<Ctrl-N>", "eps_next_error" );
  82.     assign_key( "<Ctrl-O>", "eps_delete_blank_lines" );
  83.     assign_key( "<Ctrl-S>", "eps_save_file" );
  84.     assign_key( "<Ctrl-T>", "eps_transpose_lines" );
  85.     assign_key( "<Ctrl-V>", "eps_visit_file" );
  86.     assign_key( "<Ctrl-W>", "eps_write_file" );
  87.     assign_key( "<Ctrl-X>", "eps_exchange_point_and_mark" );
  88.     assign_key( "<Ctrl-Z>", "eps_exit" );
  89.  
  90.  
  91.     assign_key( "<Ctrl-^>b", "eps_bufed" );
  92.     assign_key( "<Ctrl-^>c", "eps_exit" );
  93.     assign_key( "<Ctrl-^>d", "eps_kill_window" );
  94.     assign_key( "<Ctrl-^>e", "eps_push" );
  95.     assign_key( "<Ctrl-^>f", "eps_find_file" );
  96.     assign_key( "<Ctrl-^>i", "eps_indent_rigidly" );
  97.     assign_key( "<Ctrl-^>m", "eps_start_process" );
  98.     assign_key( "<Ctrl-^>n", "eps_next_error" );
  99.     assign_key( "<Ctrl-^>o", "eps_delete_blank_lines" );
  100.     assign_key( "<Ctrl-^>s", "eps_save_file" );
  101.     assign_key( "<Ctrl-^>t", "eps_transpose_lines" );
  102.     assign_key( "<Ctrl-^>v", "eps_visit_file" );
  103.     assign_key( "<Ctrl-^>w", "eps_write_file" );
  104.     assign_key( "<Ctrl-^>x", "eps_exchange_point_and_mark" );
  105.     assign_key( "<Ctrl-^>z", "eps_exit" );
  106.  
  107.  
  108.     assign_key( "(", "eps_start_kbd_macro" );
  109.     assign_key( ")", "eps_end_kbd_macro" );
  110.     assign_key( "1", "eps_one_window" );
  111.     assign_key( "2", "eps_split_window" );
  112.     assign_key( "=", "eps_show_point" );
  113.     assign_key( "b", "eps_bufed" );
  114.     assign_key( "e", "eps_last_kbd_macro" );
  115.     assign_key( "f", "eps_set_fill_column" );
  116.     assign_key( "g", "eps_goto_line" );
  117.     assign_key( "i", "eps_insert_file" );
  118.     assign_key( "k", "eps_kill_buffer" );
  119.     assign_key( "l", "eps_count_lines" );
  120.     assign_key( "m", "eps_make" );
  121.     assign_key( "n", "eps_next_window" );
  122.     assign_key( "o", "eps_next_window" );
  123.     assign_key( "p", "eps_previous_window" );
  124.     assign_key( "r", "eps_redo" );
  125.     assign_key( "u", "eps_undo" );
  126.     assign_key( "w", "eps_write_region" );
  127.  
  128.     assign_key( "<Alt-B>", "eps_bufed" );
  129.     assign_key( "<Alt-N>", "name_macro" );
  130.  
  131.     assign_key( "<Esc>b", "eps_bufed" );
  132.     assign_key( "<Esc>n", "name_macro" );
  133.  
  134.  
  135.     epsilon_keymap = current_keymap = create_keymap( empty_keymap );
  136.  
  137.     for (i=32; i<128; i++) {
  138.         assign_key( int_to_key(i), "donormal" );
  139.     }
  140.  
  141.     # Normal keys that do extra things
  142.     assign_key( "]", "paren" );
  143.     assign_key( "}", "paren" );
  144.     assign_key( ")", "paren" );
  145.  
  146.     # Main keyboard special keys that do extra things
  147.     assign_key( "#8", "eps_bksp" );        # <Bksp> or <Ctrl-H>
  148.     assign_key( "<Enter>", "eps_insert_newline" );
  149.     assign_key( "<Alt-\\>", "altbackslash" );
  150.     assign_key( "<Alt-,>", "altcomma" );
  151.     assign_key( "<Alt-.>", "altdot" );
  152.     assign_key( "<Alt-/>", "altslash" );
  153.     assign_key( "<Ctrl-Minus>", "ctrlminus" );
  154.     assign_key( "<Alt-Bksp>", "altback" );
  155.     assign_key( "<Keypad-Center>", "eps_scroll_window_middle" );
  156.     assign_key( "<Ctrl-Up>", "eps_prev_sentence" );
  157.     assign_key( "<Ctrl-Down>", "eps_next_sentence" );
  158.     assign_key( "<Alt-[>", "eps_prev_paragraph" );
  159.     assign_key( "<Alt-]>", "eps_next_paragraph" );
  160.     assign_key( "<Ctrl-@>", "ctrl_at" );
  161.  
  162.     # alt keys (and ctrl-alt keys)
  163.     assign_key( "<Alt-0>", "alt0" );
  164.     assign_key( "<Alt-1>", "eps_acc 1" );
  165.     assign_key( "<Alt-2>", "alt2" );
  166.     assign_key( "<Alt-3>", "eps_acc 3" );
  167.     assign_key( "<Alt-4>", "eps_acc 4" );
  168.     assign_key( "<Alt-5>", "alt5" );
  169.     assign_key( "<Alt-6>", "eps_acc 6" );
  170.     assign_key( "<Alt-7>", "alt7" );
  171.     assign_key( "<Alt-8>", "alt8" );
  172.     assign_key( "<Alt-9>", "eps_acc 9" );
  173.     assign_key( "<Alt-A>", "eps_prev_sentence" );
  174.     assign_key( "<Alt-B>", "altb" );
  175.     assign_key( "<Alt-C>", "altc" );
  176.     assign_key( "<Alt-D>", "altd" );
  177.     assign_key( "<Alt-E>", "eps_next_sentence" );
  178.     assign_key( "<Alt-F>", "altf" );
  179.     assign_key( "<Alt-H>", "mark_para" );
  180.     assign_key( "<Alt-K>", "altk" );
  181.     assign_key( "<Alt-L>", "altl" );
  182.     assign_key( "<Alt-M>", "altm" );
  183.     assign_key( "<Alt-Q>", "eps_wrap_paragraph" );
  184.     assign_key( "<Alt-R>", "altr" );
  185.     assign_key( "<Alt-S>", "alts" );
  186.     assign_key( "<Alt-T>", "altt" );
  187.     assign_key( "<Alt-U>", "altu" );
  188.     assign_key( "<Alt-V>", "eps_page_up" );
  189.     assign_key( "<Alt-W>", "altw" );
  190.     assign_key( "<Alt-X>", "eps_invoke_function" );
  191.     assign_key( "<Alt-Y>", "eps_yankpop" );
  192.     assign_key( "<Alt-Z>", "eps_scroll_vertical_up" );
  193.  
  194.     # alt function keys
  195.     assign_key( "<Alt-F5>", "eps_toggle_display" );
  196.  
  197.     # normal control keys
  198.     assign_key( "<Ctrl-A>", "eps_goto_bol" );
  199.     assign_key( "<Ctrl-B>", "eps_prev_char" );
  200.     assign_key( "<Ctrl-D>", "eps_delete_chars" );
  201.     assign_key( "<Ctrl-E>", "eps_goto_eol" );
  202.     assign_key( "<Ctrl-F>", "eps_next_char" );
  203.     assign_key( "<Ctrl-K>", "ctrlk" );
  204.     assign_key( "<Ctrl-L>", "eps_scroll_window_middle" );
  205.     assign_key( "<Ctrl-N>", "eps_down" );
  206.     assign_key( "<Ctrl-O>", "eps_open_line" );
  207.     assign_key( "<Ctrl-P>", "eps_up" );
  208.     assign_key( "<Ctrl-Q>", "ctrlq" );
  209.     assign_key( "<Ctrl-R>", "search_e" );
  210.     assign_key( "<Ctrl-S>", "search_e" );
  211.     assign_key( "<Ctrl-T>", "ctrlt" );
  212.     assign_key( "<Ctrl-U>", "ctrlu" );
  213.     assign_key( "<Ctrl-V>", "eps_page_down" );
  214.     assign_key( "<Ctrl-W>", "ctrlw" );
  215.     assign_key( "<Ctrl-X>", "ctrlx" );
  216.     assign_key( "<Ctrl-Y>", "eps_insert_scrap" );
  217.     assign_key( "<Ctrl-Z>", "eps_scroll_vertical_down" );
  218.  
  219.     # ctrl function keys
  220.     assign_key( "<Ctrl-F3>", "eps_write_state" );
  221.     assign_key( "<Ctrl-F5>", "eps_toggle_display" );
  222.     assign_key( "<Ctrl-F8>", "showvar" );
  223.  
  224.     # ctrl cursor keys
  225.     assign_key( "<Ctrl-End>", "eps_goto_buffer_bottom" );
  226.     assign_key( "<Ctrl-Home>", "eps_goto_buffer_top" );
  227.     assign_key( "<Ctrl-Left>", "goto_bow" );
  228.     assign_key( "<Ctrl-Right>", "goto_eow" );
  229.  
  230.     # ctrl prefix equivalents
  231.  
  232.     assign_key( "<Ctrl-^>a", "eps_goto_bol" );
  233.     assign_key( "<Ctrl-^>b", "eps_prev_char" );
  234.     assign_key( "<Ctrl-^>d", "eps_delete_chars" );
  235.     assign_key( "<Ctrl-^>e", "eps_goto_eol" );
  236.     assign_key( "<Ctrl-^>f", "eps_next_char" );
  237.     assign_key( "<Ctrl-^>k", "ctrlk" );
  238.     assign_key( "<Ctrl-^>l", "eps_scroll_window_middle" );
  239.     assign_key( "<Ctrl-^>n", "eps_down" );
  240.     assign_key( "<Ctrl-^>o", "eps_open_line" );
  241.     assign_key( "<Ctrl-^>p", "eps_up" );
  242.     assign_key( "<Ctrl-^>q", "ctrlq" );
  243.     assign_key( "<Ctrl-^>r", "search_e" );
  244.     assign_key( "<Ctrl-^>s", "search_e" );
  245.     assign_key( "<Ctrl-^>t", "ctrlt" );
  246.     assign_key( "<Ctrl-^>u", "ctrlu" );
  247.     assign_key( "<Ctrl-^>v", "eps_page_down" );
  248.     assign_key( "<Ctrl-^>w", "ctrlw" );
  249.     assign_key( "<Ctrl-^>x", "ctrlx" );
  250.     assign_key( "<Ctrl-^>y", "eps_insert_scrap" );
  251.     assign_key( "<Ctrl-^>z", "eps_scroll_vertical_down" );
  252.     assign_key( "<Ctrl-^><Alt-\\>", "indent_region" );
  253.     assign_key( "<Ctrl-^><Esc>\\\\", "indent_region" );
  254.  
  255.     # ctrl-prefix function keys
  256.     assign_key( "<Ctrl-^><F3>", "eps_write_state" );
  257.     assign_key( "<Ctrl-^><F5>", "eps_toggle_display" );
  258.     assign_key( "<Ctrl-^><F8>", "showvar" );
  259.  
  260.     # ctrl-prefix cursor keys
  261.     assign_key( "<Ctrl-^><End>", "eps_goto_buffer_bottom" );
  262.     assign_key( "<Ctrl-^><Home>", "eps_goto_buffer_top" );
  263.     assign_key( "<Ctrl-^><Left>", "goto_bow" );
  264.     assign_key( "<Ctrl-^><Right>", "goto_eow" );
  265.  
  266.     # alt-prefix normal keys
  267.     assign_key( "<Esc>%", "alt5" );
  268.     assign_key( "<Esc>&", "alt7" );
  269.     assign_key( "<Esc>)", "alt0" );
  270.     assign_key( "<Esc>*", "alt8" );
  271.     assign_key( "<Esc>,", "altcomma" );
  272.     assign_key( "<Esc>.", "altdot" );
  273.     assign_key( "<Esc>/", "altslash" );
  274.     assign_key( "<Esc>0", "eps_acc 0" );
  275.     assign_key( "<Esc>1", "eps_acc 1" );
  276.     assign_key( "<Esc>2", "eps_acc 2" );
  277.     assign_key( "<Esc>3", "eps_acc 3" );
  278.     assign_key( "<Esc>4", "eps_acc 4" );
  279.     assign_key( "<Esc>5", "eps_acc 5" );
  280.     assign_key( "<Esc>6", "eps_acc 6" );
  281.     assign_key( "<Esc>7", "eps_acc 7" );
  282.     assign_key( "<Esc>8", "eps_acc 8" );
  283.     assign_key( "<Esc>9", "eps_acc 9" );
  284.     assign_key( "<Esc>>", "altdot" );
  285.     assign_key( "<Esc>?", "altslash" );
  286.     assign_key( "<Esc>@", "alt2" );
  287.     assign_key( "<Esc>a", "eps_prev_sentence" );
  288.     assign_key( "<Esc>b", "altb" );
  289.     assign_key( "<Esc>c", "altc" );
  290.     assign_key( "<Esc>d", "altd" );
  291.     assign_key( "<Esc>e", "eps_next_sentence" );
  292.     assign_key( "<Esc>f", "altf" );
  293.     assign_key( "<Esc>h", "mark_para" );
  294.     assign_key( "<Esc>k", "altk" );
  295.     assign_key( "<Esc>l", "altl" );
  296.     assign_key( "<Esc>m", "altm" );
  297.     assign_key( "<Esc>q", "eps_wrap_paragraph" );
  298.     assign_key( "<Esc>s", "alts" );
  299.     assign_key( "<Esc>t", "altt" );
  300.     assign_key( "<Esc>u", "altu" );
  301.     assign_key( "<Esc>v", "eps_page_up" );
  302.     assign_key( "<Esc>w", "altw" );
  303.     assign_key( "<Esc>x", "eps_invoke_function" );
  304.     assign_key( "<Esc>y", "eps_yankpop" );
  305.     assign_key( "<Esc>z", "eps_scroll_vertical_up" );
  306.     assign_key( "<Esc>[", "eps_prev_paragraph" );
  307.     assign_key( "<Esc>\\\\", "altbackslash" );
  308.     assign_key( "<Esc>\\<", "altcomma" );
  309.     assign_key( "<Esc>]", "eps_next_paragraph" );
  310.     assign_key( "<Esc>~", "eps_modified" );
  311.  
  312.     # alt-prefix function keys
  313.     assign_key( "<Esc><F5>", "eps_toggle_display" );
  314.  
  315.     # alt-prefix command keys
  316.     assign_key( "<Esc><Bksp>", "altback" );
  317.     assign_key( "<Esc><Down>", "eps_prev_paragraph" );
  318.     assign_key( "<Esc><Up>", "eps_prev_paragraph" );
  319.  
  320.     # normal function keys
  321.     assign_key( "<F1>", "eps_help" );
  322.     assign_key( "<F2>", "eps_invoke_function" );
  323.     assign_key( "<F4>", "bind_to_key" );
  324.     assign_key( "<F6>", "whatiskey" );
  325.     assign_key( "<F7>", "eps_cd" );
  326.     assign_key( "<F8>", "setvar" );
  327.     assign_key( "<F9>", "eps_undo" );
  328.     assign_key( "<F10>", "eps_redo" );
  329.  
  330.     # normal cursor keys
  331.     assign_key( "<Home>", "eps_goto_window_top" );
  332.     assign_key( "<End>", "eps_goto_window_bottom" );
  333.     assign_key( "<Left>", "eps_prev_char" );
  334.     assign_key( "<PgDn>", "eps_page_down" );
  335.     assign_key( "<PgUp>", "eps_page_up" );
  336.     assign_key( "<Right>", "eps_next_char" );
  337.     assign_key( "<Up>", "eps_up" );
  338.     assign_key( "<Down>", "eps_down" );
  339.     assign_key( "<Ins>", "eps_toggle_insert_mode" );
  340.     assign_key( "<Del>", "eps_delete_chars" );
  341.     assign_key( "<Tab>", "eps_indent" );
  342.  
  343.     assign_mouse_buttons()
  344. }
  345.  
  346. global function ctrlx()
  347. {
  348.     local gotchar,t,i,j, w, fname;
  349.  
  350.     message("C-X ");
  351.     push_keymap(ctrlx_keymap);
  352. }
  353.  
  354.  
  355. global function ctrlk()
  356. {
  357.     local i, count, t, has_arg;
  358.  
  359.     t = last_was_kill;
  360.     has_arg = epsacc;
  361.     count =  eps_num();
  362.  
  363.     drop_anchor();
  364.     for (i=0; i<count; i++) {
  365.         if (!goto_eol() || has_arg) next_char();
  366.     }
  367.     if (t) {
  368.         eps_append_to_scrap();
  369.         delete_chars();
  370.     }
  371.     else eps_delete_to_scrap();
  372.     last_was_kill = TRUE;
  373. }
  374.  
  375. global function altd()
  376. {
  377.     local i, j, t;
  378.  
  379.     t = last_was_kill;
  380.  
  381.     drop_anchor();
  382.  
  383.     j = eps_num();
  384.     for (i=0; i<j; i++) goto_eow();
  385.     if (t) {
  386.         eps_append_to_scrap();
  387.         delete_chars();
  388.     }
  389.     else eps_delete_to_scrap();
  390.     last_was_kill = TRUE;
  391. }
  392.  
  393. local function massage_string(instr,direction)
  394. {
  395.     local i,j, outstr;
  396.  
  397.     outstr = quote_regex(instr);
  398.  
  399.     if (direction) outstr = outstr "\\c"
  400.     return outstr;
  401. }
  402.  
  403. global function search_e()
  404. {
  405.     local    ESC  = 27,
  406.         BKSP = 8,
  407.         CTRLR = 18,
  408.         CTRLS = 19,
  409.         CTRLG = 7,
  410.         level = 0,
  411.         char,
  412.         ch,
  413.         pattern = "",
  414.         spattern = "",
  415.         flags = SEARCH_MAXIMAL_MATCH+SEARCH_FORWARD\
  416.             +SEARCH_IGNORE_CASE+SEARCH_REGEX,
  417.         safe_y = current_line,
  418.         safe_x = current_column,
  419.         dokey = FALSE,
  420.         direction = 1,
  421.         search_name,
  422.         key_to_do;
  423.  
  424.     eps_num();
  425.     search_name[0] = "Reverse I-Search";
  426.     search_name[1] = "I-Search";
  427.  
  428.     if (current_key == 4882) {
  429.         direction = 0;
  430.         flags = and(flags,not(SEARCH_FORWARD));
  431.     }
  432.     message(search_name[direction] " for:");
  433.     save_position();
  434.     while (TRUE) {
  435.         ch = getchar();
  436.         if (ch == 0) {
  437.             getchar();
  438.             dokey = TRUE;
  439.             key_to_do = prev_key;
  440.             break;
  441.         }
  442.         if (ch == ESC) break;
  443.         else if (ch == CTRLG) {
  444.             while (level) {
  445.                 restore_position(FALSE);
  446.                 level --;
  447.             }
  448.             restore_position(TRUE);
  449.             save_position();
  450.             break;
  451.         }
  452.         else if (ch == BKSP) {
  453.             if (level) {
  454.                 restore_position(TRUE);
  455.                 level --;
  456.             }
  457.             pattern = substr( pattern, 0, length( pattern ) - 1)
  458.             restore_position(TRUE);
  459.             save_position();
  460.             spattern = massage_string(pattern,direction);
  461.             if (search(spattern,flags)) {
  462.                 message(search_name[direction] " for: %s",pattern);
  463.             }
  464.             else {
  465.                 message("Failing " search_name[direction] " for: %s",pattern);
  466.             }
  467.         }
  468.         else if (ch == CTRLS) {
  469.             if (pattern == "") pattern = lastsearch;
  470.             direction = 1;
  471.             flags = or(flags,SEARCH_FORWARD);
  472.             save_position();
  473.             spattern = massage_string(pattern,direction);
  474.             if (search(spattern, flags)) {
  475.                 message(search_name[direction] " for: %s",pattern);
  476.                 level++;
  477.             }
  478.             else {
  479.                 message("Failing " search_name[direction] " for: %s",pattern);
  480.                 restore_position(TRUE);
  481.             }
  482.             safe_y = current_line;
  483.             safe_x = current_column;
  484.         }
  485.         else if (ch == CTRLR) {
  486.             if (pattern == "") pattern = lastsearch;
  487.             direction = 0;
  488.             flags = and(flags, not(SEARCH_FORWARD));
  489.             save_position();
  490.             spattern = massage_string(pattern,direction);
  491.             if (search(spattern, flags+SEARCH_ADVANCE)) {
  492.                 message(search_name[direction] " for: %s",pattern);
  493.                 level++;
  494.             }
  495.             else {
  496.                 message("Failing " search_name[direction] " for: %s",pattern);
  497.                 restore_position(TRUE);
  498.             }
  499.             safe_y = current_line;
  500.             safe_x = current_column;
  501.         }
  502.         else if (isprint(chr(ch))) {
  503.             restore_position(TRUE);
  504.             save_position();
  505.             char = chr(ch);
  506.             spattern = massage_string(pattern char,direction);
  507.             if (search(spattern, flags)) {
  508.                 safe_y = current_line;
  509.                 safe_x = current_column;
  510.                 message(search_name[direction] " for: %s",pattern char);
  511.             }
  512.             else {
  513.                 current_line = safe_y;
  514.                 current_column = safe_x;
  515.                 message("Failing " search_name[direction] " for: %s",pattern char);
  516.             }
  517.             pattern = pattern char
  518.         }
  519.         else {
  520.             dokey = TRUE;
  521.             key_to_do = current_key;
  522.             break;
  523.         }
  524.         display_update();
  525.     }
  526.     while (level) {
  527.         restore_position(FALSE);
  528.         level --;
  529.     }
  530.     restore_position(FALSE);
  531.     lastsearch = pattern;
  532.     message("");
  533.     last_was_kill = FALSE;
  534.     if (dokey) {
  535.         execute_key_action(int_to_key(key_to_do));
  536.     }
  537. }
  538.  
  539. global function ctrl_at()
  540. {
  541.     eps_num();
  542.     message("Mark set");
  543.     marky = current_line;
  544.     markx = current_column;
  545.     last_was_kill = FALSE;
  546. }
  547.  
  548. global function altw()
  549. {
  550.     if (and(keyboard_flags,4)) {
  551.         last_was_kill = TRUE;
  552.         return;
  553.     }
  554.  
  555.     eps_num();
  556.     save_position();
  557.     drop_anchor();
  558.     current_line = marky;
  559.     current_column = markx;
  560.     if (last_was_kill) {
  561.         eps_append_to_scrap();
  562.     }
  563.     else {
  564.         eps_copy_to_scrap();
  565.     }
  566.     raise_anchor();
  567.     restore_position(TRUE);
  568.     last_was_kill = TRUE;
  569. }
  570.  
  571. global function ctrlw()
  572. {
  573.     eps_num();
  574.     drop_anchor();
  575.     current_line = marky;
  576.     current_column = markx;
  577.     if (last_was_kill) {
  578.         eps_append_to_scrap();
  579.         delete_chars();
  580.     }
  581.     else {
  582.         eps_delete_to_scrap();
  583.     }
  584.     last_was_kill = TRUE;
  585. }
  586.  
  587. global function forward_level()
  588. {
  589.     local target, match, found, level=1, i, j;
  590.  
  591.     j = eps_num();
  592.     last_was_kill = FALSE;
  593.  
  594.     for (i=0; i<j; i++) {
  595.         if (!search("[\\[\\{\\(]",SEARCH_FORWARD+SEARCH_REGEX))
  596.             return FALSE;
  597.         target = read_buffer(1);
  598.         if (target == "[") match = "]";
  599.         else if (target == "{") match = "}";
  600.         else match = ")";
  601.  
  602.         while (TRUE) {
  603.             if (!search("[\\" target "\\" match "]",
  604.                 SEARCH_FORWARD+SEARCH_REGEX+SEARCH_ADVANCE))
  605.                 return FALSE;
  606.             found = read_buffer(1);
  607.             if (found == target) level++;
  608.             else level--;
  609.             if (!level) {
  610.                 next_char();
  611.                 return TRUE;
  612.             }
  613.         }
  614.     }
  615. }
  616.  
  617. global function backward_level()
  618. {
  619.     local target, match, found, level=1, i, j;
  620.  
  621.     j = eps_num();
  622.     last_was_kill = FALSE;
  623.  
  624.     for (i=0; i<j; i++) {
  625.         if (!search("[\\]\\}\\)]",SEARCH_REGEX))
  626.             return FALSE;
  627.         target = read_buffer(1);
  628.         if (target == "]") match = "[";
  629.         else if (target == "}") match = "{";
  630.         else match = "(";
  631.  
  632.         while (TRUE) {
  633.             if (!search("[\\" target "\\" match "]",
  634.                 SEARCH_REGEX+SEARCH_ADVANCE))
  635.             return FALSE;
  636.             found = read_buffer(1);
  637.             if (found == target) level++;
  638.             else level--;
  639.             if (!level) {
  640.                 prev_char();
  641.                 return TRUE;
  642.             }
  643.         }
  644.     }
  645. }
  646.  
  647. global function goto_eow()
  648. {
  649.     local i, j;
  650.  
  651.     j = eps_num();
  652.     last_was_kill = FALSE;
  653.  
  654.     for (i=0; i<j; i++) {
  655.         if (!search("[A-Za-z0-9_]+\\c",
  656.             SEARCH_FORWARD+SEARCH_REGEX+SEARCH_MAXIMAL_MATCH)) {
  657.             return FALSE;
  658.         }
  659.     }
  660.     return TRUE;
  661. }
  662.  
  663. global function altf()
  664. {
  665.     local i, j;
  666.  
  667.     j = eps_num();
  668.  
  669.     for (i=0; i<j; i++) {
  670.         if (and(keyboard_flags,4)) forward_level();
  671.         else goto_eow();
  672.     }
  673.     last_was_kill = FALSE;
  674. }
  675.  
  676. global function goto_bow()
  677. {
  678.     local i,j;
  679.  
  680.     j = eps_num();
  681.     last_was_kill = FALSE;
  682.  
  683.     for (i=0; i<j; i++) {
  684.         if (!search("[A-Za-z0-9_]+",
  685.             SEARCH_ADVANCE+SEARCH_REGEX+SEARCH_MAXIMAL_MATCH)) {
  686.             return FALSE;
  687.         }
  688.     }
  689.     return TRUE;
  690. }
  691.  
  692.  
  693. global function altb()
  694. {
  695.     local i,j;
  696.  
  697.     j = eps_num();
  698.  
  699.     for (i=0; i<j; i++) {
  700.         if (and(keyboard_flags,4)) backward_level();
  701.         else goto_bow();
  702.     }
  703.     last_was_kill = FALSE;
  704. }
  705.  
  706. global function altk()
  707. {
  708.     local i, j, t;
  709.  
  710.     j = eps_num();
  711.  
  712.     if (and(keyboard_flags,4)) {
  713.         for (i=0; i<j; i++) kill_forward_level();
  714.     }
  715.  
  716.     else {
  717.         drop_anchor();
  718.         t = last_was_kill;
  719.         for (i=0; i<j; i++)
  720.             next_sentence();
  721.         if (t) {
  722.             eps_append_to_scrap();
  723.             delete_chars();
  724.         }
  725.         else eps_delete_to_scrap();
  726.         raise_anchor();
  727.     }
  728.     last_was_kill = TRUE;
  729. }
  730.  
  731. global function kill_forward_level()
  732. {
  733.     local i,j,t;
  734.  
  735.     j = eps_num();
  736.     drop_anchor();
  737.  
  738.     t = last_was_kill;
  739.  
  740.     for (i=0; i<j; i++) {
  741.         if (!forward_level()) {
  742.             raise_anchor();
  743.             return;
  744.         }
  745.     }
  746.     if (t) {
  747.         eps_append_to_scrap();
  748.         delete_chars();
  749.     }
  750.     else {
  751.         eps_delete_to_scrap();
  752.     }
  753.     raise_anchor();
  754.     last_was_kill = TRUE;
  755. }
  756.  
  757. global function ctrlq()
  758. {
  759.     local i,j;
  760.  
  761.     message("Quote:");
  762.  
  763.     while(!getchar()) {
  764.         beep();
  765.         getchar();
  766.     }
  767.  
  768.     j = eps_num();
  769.  
  770.     for (i=0; i<j; i++) insert_key(current_key);
  771.     message("");
  772.     last_was_kill = FALSE;
  773. }
  774.  
  775. global function ctrlt()
  776. {
  777.     local char, goleft;
  778.  
  779.     eps_num();
  780.     last_was_kill = FALSE;
  781.     if (current_line_length < 2) return;
  782.  
  783.     goleft = !left(1);
  784.     char = read_buffer(1);
  785.     delete_chars(1);
  786.     right(1);
  787.     insert_string(char);
  788.     left(1);
  789.     if (goleft) left(1);
  790. }
  791.  
  792. global function ctrlminus()
  793. {
  794.     eps_num();
  795.     last_was_kill = FALSE;
  796.     if (and(keyboard_flags,3)) help();
  797. }
  798.  
  799. global function altback()
  800. {
  801.     local i,j;
  802.  
  803.     save_position();
  804.  
  805.     j = eps_num();
  806.  
  807.     for (i=0; i<j; i++) {
  808.         search("[A-Za-z0-9_]+",SEARCH_REGEX+SEARCH_MAXIMAL_MATCH);
  809.     }
  810.     drop_anchor();
  811.     restore_position(TRUE);
  812.     if (last_was_kill) {
  813.         insert_scrap();
  814.         eps_delete_to_scrap();
  815.     }
  816.     else eps_delete_to_scrap();
  817.     last_was_kill = TRUE;
  818. }
  819.  
  820. global function altc()
  821. {
  822.     local i,j;
  823.  
  824.     drop_anchor();
  825.  
  826.     j = eps_num();
  827.     for (i=0; i<j; i++) {
  828.         goto_eow();
  829.     }
  830.     capitalize();
  831.     raise_anchor();
  832.     last_was_kill = FALSE;
  833. }
  834.  
  835. global function altu()
  836. {
  837.     local i,j;
  838.  
  839.     drop_anchor();
  840.     j = eps_num();
  841.     for (i=0; i<j; i++) {
  842.         goto_eow();
  843.     }
  844.     upper();
  845.     raise_anchor();
  846.     last_was_kill = TRUE;
  847. }
  848.  
  849. global function altl()
  850. {
  851.     local i,j;
  852.  
  853.     drop_anchor();
  854.  
  855.     j = eps_num();
  856.     for (i=0; i<j; i++) {
  857.         goto_eow();
  858.     }
  859.     lower();
  860.     raise_anchor();
  861.     last_was_kill = FALSE;
  862. }
  863.  
  864. global function alts()
  865. {
  866.     local s,e,c;
  867.     local ft;
  868.  
  869.     eps_num();
  870.  
  871.     if (and(keyboard_flags,4)) {
  872.         toggle_search_regex(TRUE);
  873.         search_forward();
  874.         return;
  875.     }
  876.     goto_bol();
  877.     if (!search("[^ \t]",SEARCH_FORWARD+SEARCH_REGEX)) return;
  878.     s = current_column;
  879.     goto_eol();
  880.     search("[^ \t]",SEARCH_REGEX);
  881.     e = current_column;
  882.     c = 40-((s + e)/2);
  883.     current_column = s;
  884.     ft = first_tab_distance();
  885.     indent_tabs(c/ft);
  886.     indent_columns(c%ft);
  887.     last_was_kill = FALSE;
  888. }
  889.  
  890. global function altbackslash()
  891. {
  892.     if (and(keyboard_flags,4)) {
  893.         indent_region();
  894.         return;
  895.     }
  896.  
  897.     eps_num();
  898.     while (read_buffer(1) ~ "[ \t]") delete_chars(1);
  899.     left();
  900.     while (read_buffer(1) ~ "[ \t]") {
  901.         delete_chars(1);
  902.         left();
  903.     }
  904.     last_was_kill = FALSE;
  905. }
  906.  
  907. global function altcomma()
  908. {
  909.     eps_num();
  910.     if (and(keyboard_flags,3)) goto_buffer_top();
  911.     else goto_window_top();
  912.     last_was_kill = FALSE;
  913. }
  914.  
  915. global function altdot()
  916. {
  917.     eps_num();
  918.     if (and(keyboard_flags,3)) goto_buffer_bottom();
  919.     else goto_window_bottom();
  920.     last_was_kill = FALSE;
  921. }
  922.  
  923. global function altslash()
  924. {
  925.     eps_num();
  926.     if (and(keyboard_flags,3)) help();
  927.     last_was_kill = FALSE;
  928. }
  929.  
  930. global function alt2()
  931. {
  932.     if (and(keyboard_flags,3)) {
  933.         eps_num();
  934.         ctrl_at();
  935.         last_was_kill = FALSE;
  936.     }
  937.     else eps_acc(2);
  938. }
  939.  
  940. global function show_matching()
  941. {
  942.     eps_num();
  943.     save_position();
  944.     backward_level();
  945.     display_update();
  946.     play("______");
  947.     restore_position(TRUE);
  948.     last_was_kill = FALSE;
  949. }
  950.  
  951. global function alt0()
  952. {
  953.     if (and(keyboard_flags,3)) {
  954.         eps_num();
  955.         show_matching();
  956.         last_was_kill = FALSE;
  957.     }
  958.     else eps_acc(0);
  959. }
  960.  
  961. global function bind_to_key()
  962. {
  963.     local key, comm;
  964.  
  965.     eps_num();
  966.     comm = prompt_history("BIND", "Bind command:", "");
  967.     if (comm != "") {
  968.         message("To key:");
  969.         if (!getchar()) getchar();
  970.         if (comm in savedmacs) {
  971.             assign_key(int_to_key(current_key),"replay "comm);
  972.         }
  973.         else
  974.             assign_key(int_to_key(current_key),comm);
  975.     }
  976.     message("");
  977.     last_was_kill = FALSE;
  978. }
  979.  
  980. global function paren()
  981. {
  982.     local i,j;
  983.  
  984.     j = eps_num();
  985.  
  986.     for (i=0; i<j; i++) {
  987.         insert_key(current_key);
  988.         show_matching();
  989.     }
  990.     last_was_kill = FALSE;
  991. }
  992.  
  993. global function altt()
  994. {
  995.     local s1,e1,s2,e2, save1, save2;
  996.  
  997.     eps_num();
  998.     goto_eow();
  999.     e1 = current_column;
  1000.     goto_bow();
  1001.     s1 = current_column;
  1002.     save1 = read_buffer(e1-s1);
  1003.  
  1004.     goto_bow();
  1005.  
  1006.     goto_eow();
  1007.     e2 = current_column;
  1008.     goto_bow();
  1009.     s2 = current_column;
  1010.     save2 = read_buffer(e2-s2);
  1011.  
  1012.     current_column = s1;
  1013.     delete_chars(e1-s1);
  1014.     insert_string(save2);
  1015.  
  1016.     current_column = s2;
  1017.     delete_chars(e2-s2);
  1018.     insert_string(save1);
  1019.     last_was_kill = FALSE;
  1020. }
  1021.  
  1022. global function cd()
  1023. {
  1024.     eps_num();
  1025.     chdir(prompt_history("CHDIR", "Change directory to:",""));
  1026.     last_was_kill = FALSE;
  1027. }
  1028.  
  1029. global function mark_para()
  1030. {
  1031.     local i,j;
  1032.  
  1033.     j = eps_num();
  1034.     prev_paragraph();
  1035.     ctrl_at();
  1036.     for (i=0; i<j; i++) {
  1037.         next_paragraph();
  1038.     }
  1039.     last_was_kill = FALSE;
  1040. }
  1041.  
  1042. global function alt5()
  1043. {
  1044.     if (and(keyboard_flags,3)) {
  1045.         eps_num();
  1046.         sf_replace();
  1047.         last_was_kill = FALSE;
  1048.     }
  1049.     else eps_acc(5);
  1050. }
  1051.  
  1052. global function alt7()
  1053. {
  1054.     if (and(keyboard_flags,3)) {
  1055.         eps_num();
  1056.         sf_replace();
  1057.         last_was_kill = FALSE;
  1058.     }
  1059.     else eps_acc(7);
  1060. }
  1061.  
  1062. global function alt8()
  1063. {
  1064.     if (and(keyboard_flags,3)) {
  1065.         eps_num();
  1066.         sf_replace();
  1067.         last_was_kill = FALSE;
  1068.     }
  1069.     else eps_acc(8);
  1070. }
  1071.  
  1072. global function altm()
  1073. {
  1074.     eps_num();
  1075.     goto_bol();
  1076.     search("[^ \t]|\\n", SEARCH_FORWARD+SEARCH_REGEX);
  1077.     last_was_kill = FALSE;
  1078. }
  1079.  
  1080. global function eps_delete_chars()
  1081. {
  1082.     if (epsacc || last_was_kill) {
  1083.         drop_anchor();
  1084.         next_char(eps_num());
  1085.         if (last_was_kill) {
  1086.             eps_append_to_scrap();
  1087.             delete_chars();
  1088.         }
  1089.         else eps_delete_to_scrap();
  1090.         last_was_kill = TRUE;
  1091.     }
  1092.     else {
  1093.         delete_chars(eps_num());
  1094.         last_was_kill = FALSE;
  1095.     }
  1096. }
  1097.  
  1098. global function eps_down()
  1099. {
  1100.     down(eps_num());
  1101.     last_was_kill = FALSE;
  1102. }
  1103.  
  1104. global function eps_insert_newline()
  1105. {
  1106.     local i, j;
  1107.  
  1108.     j = eps_num();
  1109.     for (i = 0; i < j; i ++) {
  1110.         auto_indent_cr()
  1111.     }
  1112.     last_was_kill = FALSE;
  1113. }
  1114.  
  1115. global function eps_open_line()
  1116. {
  1117.     save_position()
  1118.     eps_insert_newline()
  1119.     restore_position(1)
  1120. }
  1121.  
  1122. global function eps_insert_scrap()
  1123. {
  1124.     local i, j;
  1125.  
  1126.     j = eps_num();
  1127.  
  1128.     lastyankx1 = current_column;
  1129.     lastyanky1 = current_line;
  1130.  
  1131.     for (i = 0; i < j; i ++) {
  1132.         insert_scrap()
  1133.     }
  1134.  
  1135.     lastyankx2 = current_column;
  1136.     lastyanky2 = current_line;
  1137.  
  1138.     last_was_kill = FALSE;
  1139. }
  1140.  
  1141. global function eps_next_char()
  1142. {
  1143.     next_char(eps_num())
  1144.     last_was_kill = FALSE;
  1145. }
  1146.  
  1147. global function eps_next_paragraph()
  1148. {
  1149.     next_paragraph(eps_num())
  1150.     last_was_kill = FALSE;
  1151. }
  1152.  
  1153. global function eps_next_sentence()
  1154. {
  1155.     next_sentence(eps_num())
  1156.     last_was_kill = FALSE;
  1157. }
  1158.  
  1159. global function eps_page_down()
  1160. {
  1161.     local i,j;
  1162.  
  1163.     j = eps_num();
  1164.  
  1165.     for (i=0; i<j; i++) page_down()
  1166.     last_was_kill = FALSE;
  1167. }
  1168.  
  1169. global function eps_page_up()
  1170. {
  1171.     local i,j;
  1172.  
  1173.     j = eps_num();
  1174.  
  1175.     for (i=0; i<j; i++) page_up()
  1176.     last_was_kill = FALSE;
  1177. }
  1178.  
  1179. global function eps_prev_char()
  1180. {
  1181.     prev_char(eps_num())
  1182.     last_was_kill = FALSE;
  1183. }
  1184.  
  1185. global function eps_prev_paragraph()
  1186. {
  1187.     prev_paragraph(eps_num())
  1188.     last_was_kill = FALSE;
  1189. }
  1190.  
  1191. global function eps_prev_sentence()
  1192. {
  1193.     prev_sentence(eps_num())
  1194.     last_was_kill = FALSE;
  1195. }
  1196.  
  1197. global function eps_scroll_vertical_up()
  1198. {
  1199.     scroll_vertical(-eps_num())
  1200.     last_was_kill = FALSE;
  1201. }
  1202.  
  1203. global function eps_scroll_vertical_down()
  1204. {
  1205.     scroll_vertical(eps_num())
  1206.     last_was_kill = FALSE;
  1207. }
  1208.  
  1209. global function eps_up()
  1210. {
  1211.     up(eps_num())
  1212.     last_was_kill = FALSE;
  1213. }
  1214.  
  1215. global function eps_bksp()
  1216. {
  1217.     local i,j;
  1218.  
  1219.     if (epsacc || last_was_kill) {
  1220.         save_position();
  1221.         prev_char(eps_num());
  1222.         drop_anchor()
  1223.         restore_position(TRUE);
  1224.         if (last_was_kill) {
  1225.             insert_scrap();
  1226.         }
  1227.         eps_delete_to_scrap();
  1228.         last_was_kill = TRUE;
  1229.     }
  1230.     else {
  1231.         j = eps_num();
  1232.         for (i=0; i<j; i++)
  1233.             backspace();
  1234.         last_was_kill = FALSE;
  1235.     }
  1236. }
  1237.  
  1238. global function eps_num()
  1239. {
  1240.     local i;
  1241.  
  1242.     i = ((epsacc) ? epsacc : 1);
  1243.     epsacc = 0;
  1244.     if (last_message != " ")
  1245.         message(" ");
  1246.     return i;
  1247. }
  1248.  
  1249. global function ctrlu()
  1250. {
  1251.     if (!epsacc) epsacc++;
  1252.     epsacc *= 4;
  1253.     message("Argument %d",epsacc);
  1254. }
  1255.  
  1256. global function eps_acc(n)
  1257. {
  1258.     local    ch;
  1259.  
  1260.     epsacc *= 10;
  1261.     epsacc += n;
  1262.     message("Argument %d",epsacc);
  1263.  
  1264.     ch = getkey();
  1265.     while (isdigit( chr(and(ch, 0x00FF)) )){
  1266.         n = and(ch, 0x00FF) - ord("0");
  1267.  
  1268.         epsacc *= 10;
  1269.         epsacc += n;
  1270.         message("Argument %d",epsacc);
  1271.  
  1272.         ch = getkey();
  1273.     }
  1274.     ungetkey( ch );
  1275. }
  1276.  
  1277. global function donormal()
  1278. {
  1279.     local i, j;
  1280.  
  1281.     j = eps_num();
  1282.     for (i=0; i<j; i++) {
  1283.         insert_key(current_key);
  1284.     }
  1285.     last_was_kill = FALSE;
  1286. }
  1287.  
  1288. global function eps_cd()
  1289. {
  1290.     eps_num();
  1291.     last_was_kill = FALSE;
  1292.     cd();
  1293. }
  1294.  
  1295. global function eps_help()
  1296. {
  1297.     eps_num();
  1298.     last_was_kill = FALSE;
  1299.     help();
  1300. }
  1301.  
  1302. global function eps_invoke_function()
  1303. {
  1304.     local comm;
  1305.  
  1306.     eps_num();
  1307.     last_was_kill = FALSE;
  1308.  
  1309.     comm = prompt_history("XMACRO","Command: ","");
  1310.  
  1311.     if (comm in savedmacs) {
  1312.         replay(comm);
  1313.     }
  1314.     else invoke_function(comm);
  1315. }
  1316.  
  1317. global function eps_redo()
  1318. {
  1319.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1320.     eps_num();
  1321.     last_was_kill = FALSE;
  1322.     redo();
  1323. }
  1324.  
  1325. global function eps_scroll_window_middle()
  1326. {
  1327.     eps_num();
  1328.     last_was_kill = FALSE;
  1329.     scroll_window_middle();
  1330. }
  1331.  
  1332. global function eps_toggle_insert_mode()
  1333. {
  1334.     eps_num();
  1335.     last_was_kill = FALSE;
  1336.     toggle_insert_mode();
  1337. }
  1338.  
  1339. global function eps_undo()
  1340. {
  1341.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1342.  
  1343.     eps_num();
  1344.     last_was_kill = FALSE;
  1345.     undo();
  1346. }
  1347.  
  1348. global function eps_goto_bol()
  1349. {
  1350.     eps_num();
  1351.     last_was_kill = FALSE;
  1352.     goto_bol();
  1353. }
  1354.  
  1355. global function eps_goto_eol()
  1356. {
  1357.     eps_num();
  1358.     last_was_kill = FALSE;
  1359.     goto_eol();
  1360. }
  1361.  
  1362. global function eps_goto_buffer_bottom()
  1363. {
  1364.     eps_num();
  1365.     last_was_kill = FALSE;
  1366.     goto_buffer_bottom();
  1367. }
  1368.  
  1369. global function eps_goto_buffer_top()
  1370. {
  1371.     eps_num();
  1372.     last_was_kill = FALSE;
  1373.     goto_buffer_top();
  1374. }
  1375.  
  1376. global function eps_goto_window_bottom()
  1377. {
  1378.     eps_num();
  1379.     last_was_kill = FALSE;
  1380.     goto_window_bottom();
  1381. }
  1382.  
  1383. global function eps_goto_window_top()
  1384. {
  1385.     eps_num();
  1386.     last_was_kill = FALSE;
  1387.     goto_window_top();
  1388. }
  1389.  
  1390. global function name_macro()
  1391. {
  1392.     local s;
  1393.  
  1394.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1395.  
  1396.     if (keymac == "") return;
  1397.  
  1398.     s = prompt("Macro name:");
  1399.  
  1400.     if (s == "") return;
  1401.  
  1402.     savedmacs[s] = keymac;
  1403.  
  1404.     message("");
  1405. }
  1406.  
  1407. global function replay(comm)
  1408. {
  1409.     local s;
  1410.  
  1411.     eps_num();
  1412.     last_was_kill = FALSE;
  1413.  
  1414.     s = savedmacs[comm];
  1415.     playback(substr(s, 1, length(s) -1));
  1416. }
  1417.  
  1418. global function eps_indent()
  1419. {
  1420.     local ft;
  1421.     local start_column, column, new_column, line, i, j;
  1422.  
  1423.     last_was_kill = FALSE;
  1424.     j = eps_num();
  1425.  
  1426.     start_column = current_column;
  1427.     altm();
  1428.     if (current_column >= start_column) {    #should we re_indent
  1429.         line = current_line;
  1430.         goto_bol();
  1431.         if (prev_char() && search("[^ \t\n]",SEARCH_REGEX)) {
  1432.             altm();
  1433.             column = current_column;
  1434.             ft = first_tab_distance();
  1435.             new_column = max(column,start_column+ft) - 1;
  1436.             current_line = line;
  1437.             goto_bol();
  1438.             altbackslash();
  1439.             indent_columns( new_column%ft );
  1440.             indent_tabs( new_column/ft );
  1441.             altm();
  1442.         }
  1443.         else {
  1444.             current_column = start_column;
  1445.             current_line = line;
  1446.             insert_string("\t");
  1447.         }
  1448.     }
  1449.     else {
  1450.         current_column = start_column;
  1451.         for (i=0; i<j; i++) insert_string("\t");
  1452.     }
  1453.     last_was_kill = FALSE;
  1454. }
  1455.  
  1456. global function whatiskey()
  1457. {
  1458.     local key,binding;
  1459.  
  1460.     eps_num();
  1461.     last_was_kill = FALSE;
  1462.     message("What is key: ");
  1463.  
  1464.     if (!getchar()) {
  1465.         getchar();
  1466.         key = key_name(prev_key);
  1467.     }
  1468.     else {
  1469.         key = key_name(current_key);
  1470.     }
  1471.     binding = keymap_binding(key);
  1472.     if (binding == "") {
  1473.         message("Key " key " is not bound to any command");
  1474.     }
  1475.     else {
  1476.         message("Key " key " runs the command " binding);
  1477.     }
  1478. }
  1479.  
  1480. global function max(a,b)
  1481. {
  1482.     return (a>b) ? a : b;
  1483. }
  1484.  
  1485. global function eps_toggle_display()
  1486. {
  1487.     eps_num();
  1488.     last_was_kill = FALSE;
  1489.     toggle_display();
  1490. }
  1491.  
  1492. global function eps_wrap_paragraph()
  1493. {
  1494.     eps_num();
  1495.     last_was_kill = FALSE;
  1496.     wrap_paragraph();
  1497. }
  1498.  
  1499. global function eps_yankpop()
  1500. {
  1501.     local thisbuffer = current_buffer;
  1502.  
  1503.     eps_num();
  1504.     last_was_kill = FALSE;
  1505.  
  1506.     if (current_column != lastyankx2) return;
  1507.     if (current_line != lastyanky2) return;
  1508.  
  1509.     drop_anchor();
  1510.  
  1511.     current_column = lastyankx1;
  1512.     current_line = lastyanky1;
  1513.  
  1514.     delete_chars();
  1515.     raise_anchor();
  1516.  
  1517.     prevkillbuf();
  1518.  
  1519.     current_buffer = killbuffers[currentkill];
  1520.  
  1521.     goto_buffer_top();
  1522.     drop_anchor();
  1523.     goto_buffer_bottom();
  1524.     copy_to_scrap();
  1525.     raise_anchor();
  1526.  
  1527.     current_buffer = thisbuffer;
  1528.  
  1529.     lastyankx1 = current_column;
  1530.     lastyanky1 = current_line;
  1531.  
  1532.     insert_scrap();
  1533.  
  1534.     lastyankx2 = current_column;
  1535.     lastyanky2 = current_line;
  1536. }
  1537.  
  1538. global function eps_delete_to_scrap()
  1539. {
  1540.     local thisbuffer;
  1541.  
  1542.     thisbuffer = current_buffer;
  1543.  
  1544.     delete_to_scrap();
  1545.  
  1546.     nextkillbuf();
  1547.  
  1548.     delete_buffer(killbuffers[currentkill]);
  1549.     killbuffers[currentkill] = create_buffer("killbuffer" currentkill,
  1550.         "", BUFFER_SYSTEM);
  1551.  
  1552.     current_buffer = killbuffers[currentkill];
  1553.     insert_scrap();
  1554.  
  1555.     current_buffer = thisbuffer;
  1556. }
  1557.  
  1558. global function eps_append_to_scrap()
  1559. {
  1560.     local thisbuffer;
  1561.  
  1562.     thisbuffer = current_buffer;
  1563.  
  1564.     append_to_scrap();
  1565.  
  1566.     delete_buffer(killbuffers[currentkill]);
  1567.     killbuffers[currentkill] = create_buffer("killbuffer" currentkill,
  1568.         "", BUFFER_SYSTEM);
  1569.  
  1570.     current_buffer = killbuffers[currentkill];
  1571.     insert_scrap();
  1572.  
  1573.     current_buffer = thisbuffer;
  1574. }
  1575.  
  1576. global function eps_copy_to_scrap()
  1577. {
  1578.     local thisbuffer;
  1579.  
  1580.     thisbuffer = current_buffer;
  1581.  
  1582.     copy_to_scrap();
  1583.  
  1584.     nextkillbuf();
  1585.  
  1586.     delete_buffer(killbuffers[currentkill]);
  1587.     killbuffers[currentkill] = create_buffer("killbuffer" currentkill,
  1588.         "", BUFFER_SYSTEM);
  1589.  
  1590.     current_buffer = killbuffers[currentkill];
  1591.     insert_scrap();
  1592.  
  1593.     current_buffer = thisbuffer;
  1594. }
  1595.  
  1596. global function nextkillbuf()
  1597. {
  1598.     currentkill ++;
  1599.     currentkill %= 6;
  1600. }
  1601.  
  1602. global function prevkillbuf()
  1603. {
  1604.     currentkill += 5;
  1605.     currentkill %= 6;
  1606. }
  1607.  
  1608. global function eps_modified()
  1609. {
  1610.     eps_num();
  1611.     last_was_kill = FALSE;
  1612.  
  1613.     buffer_flags = xor(buffer_flags, BUFFER_MODIFIED);
  1614.  
  1615.     if (and(buffer_flags,BUFFER_MODIFIED)) {
  1616.         message("Buffer is marked changed");
  1617.     }
  1618.     else {
  1619.         message("Buffer is marked unchanged");
  1620.     }
  1621. }
  1622.  
  1623. global function altr()
  1624. {
  1625.     eps_num();
  1626.  
  1627.     last_was_kill = FALSE;
  1628.  
  1629.     if (and(keyboard_flags,4)) {
  1630.         toggle_search_regex(TRUE);
  1631.         search_backward();
  1632.     }
  1633.     else beep();
  1634. }
  1635.  
  1636. global function showvar()
  1637. {
  1638.     local showme;
  1639.  
  1640.     eps_num();
  1641.     last_was_kill = FALSE;
  1642.  
  1643.     showme = prompt_history("XMACRO","Show variable: ","");
  1644.     message(showme " == " execute_function(showme));
  1645. }
  1646.  
  1647. global function setvar()
  1648. {
  1649.     local setme;
  1650.     local to;
  1651.  
  1652.     eps_num();
  1653.     last_was_kill = FALSE;
  1654.  
  1655.     setme = prompt_history("XMACRO","set variable: ","");
  1656.     to = prompt("to: ");
  1657.     message(setme " == " execute_function(setme"="to));
  1658. }
  1659.  
  1660. global function eps_copytofile()
  1661. {
  1662.     local t;
  1663.  
  1664.     t = and(buffer_flags,BUFFER_MODIFIED);
  1665.  
  1666.     write_buffer(prompt_history("EDITFILE","Copy to file: ",""));
  1667.  
  1668.     buffer_flags = set_flag_bits(buffer_flags, BUFFER_MODIFIED, t);
  1669. }
  1670.  
  1671. global function eps_bufed()
  1672. {
  1673.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1674.  
  1675.     eps_num();
  1676.     last_was_kill = FALSE;
  1677.     buffer_list();
  1678. }
  1679.  
  1680. global function eps_count_lines()
  1681. {
  1682.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1683.  
  1684.     eps_num();
  1685.     last_was_kill = FALSE;
  1686.  
  1687.     message("%d lines, point on line %d",buffer_last_line,
  1688.         current_line);
  1689. }
  1690.  
  1691. global function eps_delete_blank_lines()
  1692. {
  1693.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1694.  
  1695.     eps_num();
  1696.     last_was_kill = FALSE;
  1697.  
  1698.     goto_bol();
  1699.  
  1700.     save_position();
  1701.     while (up() && isblank(read_buffer())) {
  1702.         restore_position(FALSE);
  1703.         save_position();
  1704.     }
  1705.     restore_position(TRUE);
  1706.     drop_anchor();
  1707.  
  1708.     save_position();
  1709.     while (isblank(read_buffer()) && down()) {
  1710.         restore_position(FALSE);
  1711.         save_position();
  1712.     }
  1713.     restore_position(TRUE);
  1714.  
  1715.     delete_chars();
  1716. }
  1717.  
  1718. global function eps_end_kbd_macro()
  1719. {
  1720.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1721.  
  1722.     eps_num();
  1723.     last_was_kill = FALSE;
  1724.  
  1725.     keymac=record(0);
  1726.     message("Done Recording");
  1727. }
  1728.  
  1729. global function eps_exchange_point_and_mark()
  1730. {
  1731.     local t;
  1732.  
  1733.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1734.  
  1735.     eps_num();
  1736.     last_was_kill = FALSE;
  1737.     t = markx;
  1738.     markx = current_column;
  1739.     current_column = t;
  1740.     t = marky;
  1741.     marky = current_line;
  1742.     current_line = t;
  1743. }
  1744.  
  1745. global function eps_exit()
  1746. {
  1747.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1748.  
  1749.     eps_num();
  1750.     last_was_kill = FALSE;
  1751.     quit();
  1752. }
  1753.  
  1754. global function eps_find_file()
  1755. {
  1756.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1757.  
  1758.     eps_num();
  1759.     last_was_kill = FALSE;
  1760.  
  1761.     edit_file(prompt_history("EDITFILE", "Find file: ", ""));
  1762.     message("");
  1763. }
  1764.  
  1765. global function eps_goto_line()
  1766. {
  1767.     local t, j;
  1768.  
  1769.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1770.  
  1771.     t = epsacc;
  1772.     j = eps_num();
  1773.  
  1774.     last_was_kill = FALSE;
  1775.     goto_line(t ? j : atoi(prompt("Goto line:")));
  1776. }
  1777.  
  1778. global function eps_indent_rigidly()
  1779. {
  1780.     local i, j, t;
  1781.  
  1782.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1783.  
  1784.     t = epsacc;
  1785.     j = eps_num();
  1786.  
  1787.     drop_anchor();
  1788.     current_column = markx;
  1789.     current_line = marky;
  1790.     indent_columns((t) ? j : first_tab_distance());
  1791.     raise_anchor();
  1792.  
  1793.     last_was_kill = FALSE;
  1794. }
  1795.  
  1796. global function eps_insert_file()
  1797. {
  1798.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1799.  
  1800.     eps_num();
  1801.     last_was_kill = FALSE;
  1802.  
  1803.     markx = current_column;
  1804.     marky = current_line;
  1805.     read_file(prompt_history("EDITFILE","Insert file: ",""));
  1806. }
  1807.  
  1808. global function eps_kill_buffer()
  1809. {
  1810.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1811.  
  1812.     eps_num();
  1813.     last_was_kill = FALSE;
  1814.     delete_buffer_key();
  1815. }
  1816.  
  1817. global function eps_kill_window()
  1818. {
  1819.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1820.  
  1821.     eps_num();
  1822.     last_was_kill = FALSE;
  1823.     delete_window();
  1824. }
  1825.  
  1826. global function eps_last_kbd_macro()
  1827. {
  1828.     local i, j;
  1829.  
  1830.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1831.  
  1832.     j = eps_num();
  1833.     last_was_kill = FALSE;
  1834.     for (i=0; i<j; i++) {
  1835.         playback(substr(keymac,1,length(keymac)-1));
  1836.     }
  1837. }
  1838.  
  1839. global function eps_make()
  1840. {
  1841.     local status;
  1842.     local old_window = current_window, old_buffer = current_buffer;
  1843.  
  1844.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1845.  
  1846.     eps_num();
  1847.     last_was_kill = FALSE;
  1848.  
  1849.     if (makebuffer) delete_buffer(makebuffer);
  1850.  
  1851.     if (buffers_modified && toupper(prompt("Save buffers?")) == "Y") {
  1852.         write_all_buffers();
  1853.     }
  1854.  
  1855.     errfile=create_temp_name();
  1856.     current_window =
  1857.         create_window(3,8,display_width-6,display_height-16,
  1858.             WINDOW_MENU0);
  1859.     window_cursor_x = 0;
  1860.     window_cursor_y = 0;
  1861.     display_update();
  1862.     status = dos_window("make >& "errfile);
  1863.     makebuffer = current_buffer =
  1864.         create_buffer("", errfile, BUFFER_SYSTEM + BUFFER_NO_UNDO);
  1865.     attach_window_buffer(current_window, current_buffer);
  1866.     goto_buffer_bottom();
  1867.     goto_eol();
  1868.     display_update();
  1869.     confirm( "Press <ENTER> to continue.", "" );
  1870.     goto_buffer_top();
  1871.     goto_bol();
  1872.     delete_window();
  1873.     current_buffer = old_buffer;
  1874.     if (old_window)
  1875.         current_window = old_window;
  1876.     display_redraw();
  1877.     unlink(errfile);
  1878.     message("make returns %d",status);
  1879. }
  1880.  
  1881. global function eps_next_error()
  1882. {
  1883.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1884.  
  1885.     eps_num();
  1886.     last_was_kill = FALSE;
  1887.  
  1888.     goto_next_error( errorSrcName );
  1889. }
  1890.  
  1891. global function eps_next_window()
  1892. {
  1893.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1894.  
  1895.     eps_num();
  1896.     last_was_kill = FALSE;
  1897.     next_window();
  1898. }
  1899.  
  1900. global function eps_one_window()
  1901. {
  1902.     local    w;
  1903.     local    cw;
  1904.  
  1905.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1906.  
  1907.     eps_num();
  1908.     last_was_kill = FALSE;
  1909.     restore_window();
  1910.     expand_window();
  1911.     cw = current_window;
  1912.     while (cw) {
  1913.         w = next_window();
  1914.         if (w == cw)
  1915.             break;
  1916.         delete_window();
  1917.     }
  1918.     if (cw)
  1919.         current_window = cw;
  1920. }
  1921.  
  1922. global function eps_previous_window()
  1923. {
  1924.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1925.  
  1926.     eps_num();
  1927.     last_was_kill = FALSE;
  1928.     prev_window();
  1929. }
  1930.  
  1931. global function eps_push()
  1932. {
  1933.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1934.  
  1935.     eps_num();
  1936.     last_was_kill = FALSE;
  1937.     system("p");
  1938. }
  1939.  
  1940. global function eps_save_file()
  1941. {
  1942.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1943.  
  1944.     eps_num();
  1945.     last_was_kill = FALSE;
  1946.  
  1947.     write_buffer();
  1948.     message("File saved.");
  1949. }
  1950.  
  1951. global function eps_set_fill_column()
  1952. {
  1953.     local t, j;
  1954.  
  1955.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1956.  
  1957.     t = epsacc;
  1958.     j = eps_num();
  1959.  
  1960.     last_was_kill = FALSE;
  1961.     wp_right_margin = (t) ? j : current_column;
  1962. }
  1963.  
  1964. global function eps_show_point()
  1965. {
  1966.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1967.  
  1968.     eps_num();
  1969.     last_was_kill = FALSE;
  1970.     message("%d Characters, point at %d",buffer_size,
  1971.         buffer_offset);
  1972. }
  1973.  
  1974. global function eps_split_window()
  1975. {
  1976.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1977.  
  1978.     eps_num();
  1979.     last_was_kill = FALSE;
  1980.     create_tiled_window();
  1981. }
  1982.  
  1983. global function eps_start_kbd_macro()
  1984. {
  1985.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1986.  
  1987.     eps_num();
  1988.     last_was_kill = FALSE;
  1989.     record(1);
  1990.     message("Recording");
  1991. }
  1992.  
  1993. global function eps_start_process()
  1994. {
  1995.     if (current_keymap == ctrlx_keymap) pop_keymap();
  1996.  
  1997.     eps_num();
  1998.     last_was_kill = FALSE;
  1999.     system("");
  2000. }
  2001.  
  2002. global function eps_transpose_lines()
  2003. {
  2004.     if (current_keymap == ctrlx_keymap) pop_keymap();
  2005.  
  2006.     eps_num();
  2007.     last_was_kill = FALSE;
  2008.     up(1);
  2009.     goto_bol();
  2010.     drop_anchor();
  2011.     down(1);
  2012.     eps_delete_to_scrap();
  2013.     down(1);
  2014.     insert_scrap();
  2015.     raise_anchor();
  2016.     up(1);
  2017. }
  2018.  
  2019. global function eps_visit_file()
  2020. {
  2021.     local name;
  2022.  
  2023.     if (current_keymap == ctrlx_keymap) pop_keymap();
  2024.  
  2025.     eps_num();
  2026.     last_was_kill = FALSE;
  2027.     edit_file(prompt_history("EDITFILE","Visit file :",buffer_filename));
  2028.     if (and(buffer_flags,BUFFER_MODIFIED)) {
  2029.         if (toupper(prompt("Write changes to disk first?"))=="Y") {
  2030.             write_buffer();
  2031.         }
  2032.         else {
  2033.             name = buffer_filename;
  2034.             buffer_flags = xor(buffer_flags,BUFFER_MODIFIED);
  2035.             delete_buffer();
  2036.             edit_file(name);
  2037.         }
  2038.     }
  2039. }
  2040.  
  2041. global function eps_write_file()
  2042. {
  2043.     if (current_keymap == ctrlx_keymap) pop_keymap();
  2044.  
  2045.     eps_num();
  2046.     last_was_kill = FALSE;
  2047.     write_buffer(prompt("Write to file: "));
  2048.     message("File written.");
  2049. }
  2050.  
  2051. global function eps_write_region()
  2052. {
  2053.     if (current_keymap == ctrlx_keymap) pop_keymap();
  2054.  
  2055.     eps_num();
  2056.     last_was_kill = FALSE;
  2057.  
  2058.     save_position();
  2059.     drop_anchor();
  2060.     current_column = markx;
  2061.     current_line = marky;
  2062.     write_marked_block(prompt("Write region to file: "));
  2063.     raise_anchor();
  2064.     restore_position(TRUE);
  2065. }
  2066.  
  2067. local function isblank(s)
  2068. {
  2069.     local i;
  2070.  
  2071.     if (s == "") return TRUE;
  2072.  
  2073.     for (i=1; i<=length(s); i++) {
  2074.         if (substr(s,i,1) !~ "[ \t]") return FALSE;
  2075.     }
  2076.  
  2077.     return TRUE;
  2078. }
  2079.  
  2080. global function indent_region()
  2081. {
  2082.     local oldcurrent, swapt = FALSE;
  2083.  
  2084.     eps_num();
  2085.     last_was_kill = FALSE;
  2086.  
  2087.     if (current_line < marky) {
  2088.         eps_exchange_point_and_mark();
  2089.         swapt = TRUE;
  2090.     }
  2091.     save_position();
  2092.  
  2093.     oldcurrent = current_line;
  2094.  
  2095.     for (current_line=marky; current_line<=oldcurrent; current_line++) {
  2096.         goto_bol();
  2097.         eps_indent();
  2098.     }
  2099.     restore_position(TRUE);
  2100.  
  2101.     if (swapt) eps_exchange_point_and_mark();
  2102. }
  2103.  
  2104. global function eps_write_state()
  2105. {
  2106.     local i;
  2107.  
  2108.     eps_num();
  2109.     last_was_kill = FALSE;
  2110.  
  2111.     eps_sta_file = fopen(eps_sta_name,1)
  2112.     if (!eps_sta_file) {
  2113.         message("Cannot open state file");
  2114.         return;
  2115.     }
  2116.  
  2117.     if (lastsearch != "")
  2118.         fprintf(eps_sta_file,"lastsearch="lastsearch"\n");
  2119.  
  2120.  
  2121.     if (keymac != "")
  2122.         fprintf(eps_sta_file,"keymac="keymac"\n");
  2123.         # !! this doesn't always work right
  2124.  
  2125.     for (i in savedmacs) {
  2126.         fprintf(eps_sta_file,"savedmacs["i"]="i"\n");
  2127.         # !! this also doesn't always work right
  2128.     }
  2129.     # !! fprintf(eps_sta_file,"push_keymap ctrlx_keymap\n");
  2130.     # !! save ctrlx keymap here as a set of assign_key commands
  2131.     # !! fprintf(eps_sta_file,"pop_keymap\n");
  2132.     # !! save normal keymap here as a set of assign_key commands
  2133.     fclose(eps_sta_file);
  2134.     message("State file written.");
  2135. }
  2136.  
  2137. global function eps_read_state()
  2138. {
  2139.     local oldbuffer = current_buffer,cf,cmd;
  2140.  
  2141.     cf = create_buffer("",eps_sta_name, BUFFER_SYSTEM+BUFFER_NO_UNDO);
  2142.  
  2143.     # !! create the ctrlx keymap (should be put in when keymaps are saved)
  2144.     # !!
  2145.     # !! ctrlx_keymap=create_keymap(empty_keymap);
  2146.     # !!
  2147.  
  2148.     # !! create and activate the main keymap (should be put in when
  2149.     # !! keymaps are saved)
  2150.     # !!
  2151.     # !! push_keymap(create_keymap(empty_keymap));
  2152.  
  2153.     if (cf) {
  2154.         current_buffer = cf;
  2155.         goto_buffer_top();
  2156.         do {
  2157.             cmd = read_buffer();
  2158.             if (cmd) execute_function(cmd);
  2159.             next_line();
  2160.         } while (cmd);
  2161.         delete_buffer(cf);
  2162.         current_buffer = oldbuffer;
  2163.     }
  2164.     else return FALSE;
  2165.  
  2166.     return FALSE; # !! this should return true when the keymap stuff is
  2167.               # !! built. My problem is saving all the maps including
  2168.               # !! multiple keystroke sequences
  2169. }
  2170.  
  2171.  
  2172. local eps_tab_distance;
  2173. local eps_tab_string;
  2174.  
  2175. ## first_tab_distance()
  2176. #
  2177. # Determine the column where the first Tab in a row would be positioned.
  2178. #
  2179. global function first_tab_distance(){
  2180.  
  2181.     if (eps_tab_string != buffer_tabs) {
  2182.         eps_tab_string = buffer_tabs;
  2183.         buffer_flags = and(buffer_flags, not(BUFFER_REAL_SPACE_ONLY))
  2184.         save_position()
  2185.         goto_bol()
  2186.         goto_next_tab();
  2187.         eps_tab_distance = current_column - 1;
  2188.         restore_position(1);
  2189.         buffer_flags = or(buffer_flags, BUFFER_REAL_SPACE_ONLY)
  2190.     }
  2191.     return eps_tab_distance;
  2192. }
  2193.