home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / p2demo21.exe / PEL / BRIEF.PEL < prev    next >
Text File  |  1995-03-21  |  24KB  |  749 lines

  1. # $Header:   P:\source\wmacros\brief.pev   1.59   21 Mar 1995 09:02:34   WALKER  $
  2. ## $Tabs:4 7$
  3.  
  4. ##############################################################################
  5. #
  6. #       Compuware Corporation
  7. #         31440 Northwestern Highway
  8. #           Farmington Hills, Michigan 48334-2564
  9. #
  10. #   This source code listing contains information that is
  11. #   proprietary to Compuware Corporation and may not be copied
  12. #   duplicated, translated, transmitted, stored, retrieved
  13. #   or in any manner or by any method conveyed or disclosed
  14. #   to a third party or parties without express written
  15. #   permission from Compuware Corporation.
  16. #
  17. #  
  18. ##############################################################################
  19.  
  20. #### $Workfile:   brief.pel  $: Key bindings for Brief compatibility
  21.  
  22. local brief_keymap = -1
  23.  
  24. ##
  25. ## BriefKeymap() - define Brief key bindings
  26. ##
  27.  
  28. #       key     #- found in startup keymap
  29. #               #  already defined
  30. #               #       not implemented yet
  31.  
  32. global function brief()                                         #PUBLIC #VOID
  33. {
  34.    local prevPauseOnError
  35.  
  36.    if (emulation_mode == "brief")
  37.       return;
  38.  
  39.    emulation_mode = "brief"
  40.    execute_event_handler( EVENT.EMULATION_CHANGED )
  41.    
  42.    attach_event_handler(EVENT.EMULATION_CHANGED, function_id("brief_exit"))
  43.    
  44.    # pause if an error or warning occurs during initialization
  45.    prevPauseOnError = pause_on_error
  46.    pause_on_error   = 1
  47.    
  48.    create_brief_keymap()
  49.    brief_menu()
  50.    
  51.    pause_on_error = prevPauseOnError
  52. }
  53.  
  54. global function create_brief_keymap()
  55. {
  56.    # Enable the keymap.  Subsequent mods to the keymap will persist
  57.    #       through the end of the session.
  58.    # Only one-time initialization should follow this point.
  59.  
  60.    if( brief_keymap >= 0 )
  61.    {
  62.       current_keymap = brief_keymap
  63.       return
  64.    }
  65.    else
  66.    {
  67.       current_keymap = brief_keymap = create_keymap( factory_keymap )
  68.    
  69.       assign_brief_keys()
  70. #        assign_brief_f_keys()
  71. #        assign_brief_misc_keys()
  72.  
  73.       optional_function("local_keys")
  74.    }
  75. }
  76.  
  77. global function assign_brief_keys()
  78. {
  79.  
  80.    #--------------------------------------------------------------
  81.    # Alt key combinations on the main keyboard:
  82.    #--------------------------------------------------------------
  83.    assign_key( "<Alt-A>",               "set_exclusive_mark" )
  84.    assign_key( "<Alt-B>",               "buffer_list" )
  85.    assign_key( "<Alt-C>",               "set_column_mark" )
  86.    assign_key( "<Alt-D>",               "delete_line" )
  87. #   assign_key( "<Alt-E>",               "edit_file_key" )
  88.    assign_key( "<Alt-E>",               "create_buf_and_win_key" )
  89.  
  90.    assign_key( "<Alt-F>",               "display_filename" )
  91.    assign_key( "<Alt-G>",               "goto_line_key" )
  92.    assign_key( "<Alt-H>",               "display_help_item")
  93.    assign_key( "<Alt-I>",   function_id("toggle_buffer_flags", BUFFER_OVERTYPE_MODE))
  94.    assign_key( "<Alt-J>",               "goto_bookmark")
  95.    assign_key( "<Alt-K>",               "delete_to_eol" )
  96.    assign_key( "<Alt-L>",               "set_line_mark" )
  97.    assign_key( "<Alt-M>",               "set_inclusive_mark" )
  98.    assign_key( "<Alt-N>",               "next_buffer_mask" )
  99.    assign_key( "<Alt-O>",               "change_output_name" )
  100.    assign_key( "<Alt-P>",               "gui_print" )
  101.    assign_key( "<Alt-Q>",               "insert_quoted_key" )
  102.    assign_key( "<Alt-R>",               "read_file_key" )
  103.    assign_key( "<Alt-S>",               "search_forward" )
  104.    assign_key( "<Alt-T>",               "replace_forward" )
  105.    assign_key( "<Alt-U>",               "undo" )
  106.    assign_key( "<Alt-V>",               "print_version" )
  107.    assign_key( "<Alt-W>",               "write_block_key" )
  108.    assign_key( "<Alt-X>",               "done" )
  109.    assign_key( "<Alt-F4>",              "done2" )
  110.    assign_key( "<Alt-Y>",               "redo" )
  111.    assign_key( "<Alt-Z>",               "system" )
  112.  
  113.    #--------------------------------------------------------------
  114.    # Ctrl key combinations on the main keyboard:
  115.    #--------------------------------------------------------------
  116.    assign_key( "<Ctrl-A>",              "optional_function display_ascii_table" )
  117.    assign_key( "<Ctrl-B>",              "scroll_window_bottom")
  118.    assign_key( "<Ctrl-C>",              "center_cursor" )
  119.    assign_key( "<Ctrl-D>",              "scroll_up_1" )
  120.    assign_key( "<Ctrl-G>",              "optional_function routines" )
  121.    assign_key( "<Ctrl-N>",              "goto_next_error" )
  122. #  assign_key( "<Ctrl-P>",              "display_errors" )
  123.    assign_key( "<Ctrl-R>",              "optional_function repeat_key_action" )
  124.    assign_key( "<Ctrl-T>",              "scroll_window_top" )
  125.    assign_key( "<Ctrl-U>",              "scroll_down_1")
  126.    assign_key( "<Ctrl-W>",              "toggle_file_backup" )
  127.    assign_key( "<Ctrl-X>",              "write_and_exit" )
  128. #  }
  129.  
  130. #  global function assign_brief_f_keys()
  131. #  {
  132.    #--------------------------------------------------------------
  133.    # Function Key bindings
  134.    #--------------------------------------------------------------
  135. #  assign_key( "<F1>",                  "brief_change_window" )
  136. #  assign_key( "<F2>",                  "adjust_window" )
  137.   assign_key( "<F3>",                  "brief_create_window" )
  138.   assign_key( "<F4>",                  "brief_delete_window" )
  139.    assign_key( "<F5>",                  "search_forward" )
  140.    assign_key( "<F6>",                  "replace_forward" )
  141.    assign_key( "<F7>",                  "record_macro" )
  142.    assign_key( "<F8>",                  "playback_macro" )
  143.    assign_key( "<F9>",                  "system_key" )
  144.    assign_key( "<F10>",                 "invoke_function" )
  145.  
  146.    assign_key( "<Alt-F1>",              "toggle_borders" )
  147. #  assign_key( "<Alt-F2>",              "toggle_window_zoom" )
  148.    assign_key( "<Alt-F5>",              "search_backward" )
  149.    assign_key( "<Alt-F6>",              "replace_backward" )
  150.    assign_key( "<Alt-F7>",              "load_key_file" )
  151.    assign_key( "<Alt-F8>",              "write_key_file" )
  152.    assign_key( "<Alt-F10>",             "compile_buffer" )
  153.  
  154.    assign_key( "<Shift-F5>",            "search_again" )
  155.    assign_key( "<Shift-F6>",            "replace_again" )
  156.    assign_key( "<Shift-F7>",            "pause_recording" )
  157. #  assign_key( "<Shift-F9>",            "" )
  158.    assign_key( "<Shift-F10>",           "insert_keys" )
  159.  
  160.    assign_key( "<Ctrl-F1>",             "display_help_item" )
  161.    assign_key( "<Ctrl-F5>",    function_id("toggle_search_flags", SEARCH_CASE))
  162.    assign_key( "<Ctrl-F6>",    function_id("toggle_search_flags", SEARCH_REGEX))
  163. #}
  164. #
  165. #global function assign_brief_misc_keys()
  166. #{
  167.    #--------------------------------------------------------------
  168.    # Alt-digit codes:
  169.    #--------------------------------------------------------------
  170.    assign_key( "<Alt-1>",               "place_bookmark 1")
  171.    assign_key( "<Alt-2>",               "place_bookmark 2")
  172.    assign_key( "<Alt-3>",               "place_bookmark 3")
  173.    assign_key( "<Alt-4>",               "place_bookmark 4")
  174.    assign_key( "<Alt-5>",               "place_bookmark 5")
  175.    assign_key( "<Alt-6>",               "place_bookmark 6")
  176.    assign_key( "<Alt-7>",               "place_bookmark 7")
  177.    assign_key( "<Alt-8>",               "place_bookmark 8")
  178.    assign_key( "<Alt-9>",               "place_bookmark 9")
  179.    assign_key( "<Alt-0>",               "place_bookmark 10")
  180.  
  181.    #--------------------------------------------------------------
  182.    # Numpad keys
  183.    #--------------------------------------------------------------
  184. #  assign_key( "<Num-1>",               "goto_window_right" )
  185.    assign_key( "<Num-2>",               "insert_key")
  186.    assign_key( "<Num-4>",               "insert_key")
  187.    assign_key( "<Num-6>",               "insert_key")
  188. #  assign_key( "<Num-7>",               "goto_window_left" )
  189.    assign_key( "<Num-8>",               "insert_key")
  190.    assign_key( "<Num-+>",               "copy_to_scrap_key" )
  191.    assign_key( "<Num-->",               "delete_to_scrap")
  192.    assign_key( "<Num-*>",               "undo" )
  193.    assign_key( "<Num-/>",               "redo" )          # Extension to Brief
  194.    assign_key( "<Num-Enter>",           "auto_indent_cr" )
  195.  
  196.    assign_key( "<Alt-Num-->",           "prev_buffer_mask" )
  197.    assign_key( "<Ctrl-Num-->",          "brief_delete_buffer" )
  198.  
  199.    #--------------------------------------------------------------
  200.    # non-ASCII keys on main keyboard:
  201.    #--------------------------------------------------------------
  202.    assign_key( "<Esc>",                 "expand_template_key" )
  203.    assign_key( "<Enter>",               "auto_indent_cr" )
  204.    assign_key( "<Tab>",                 "indent_tab_maybe" )
  205.    assign_key( "<Space>",               "indent_space_maybe" )
  206.    assign_key( "<Backspace>",           "brief_backspace" )
  207.    assign_key( "<Shift-Backspace>",     "brief_backspace" )
  208.  
  209.    assign_key( "<Shift-Space>", "insert_key 32");
  210.    assign_key( "<Ctrl-Space>",  "insert_key 32");
  211.  
  212.    # use BackTab for OS2 and Shift-Tab for windows
  213.    assign_key( "<BackTab>",              "outdent_tab_maybe" )
  214.  
  215.    assign_key( "<Ctrl-->",              "brief_delete_buffer" )
  216.    assign_key( "<Alt-->",               "prev_buffer_mask" )
  217.  
  218.    #--------------------------------------------------------------
  219.    # keypad keys:
  220.    #--------------------------------------------------------------
  221.    assign_key( "<Insert>",              "insert_scrap" )
  222.    assign_key( "<Delete>",              "delete_chars" )
  223.    assign_key( "<Up>",                  "up" )
  224.    assign_key( "<PageUp>",              "page_up" )
  225.    assign_key( "<Home>",                "home_key" )
  226.    assign_key( "<End>",                 "end_key" )
  227.    assign_key( "<Num-Home>",            "home_key" )
  228.    assign_key( "<Num-End>",             "end_key" )
  229.    assign_key( "<Down>",                "down" )
  230.    assign_key( "<PageDown>",            "page_down" )
  231.    assign_key( "<Left>",                "left" )
  232.    assign_key( "<Right>",               "right" )
  233.    
  234.    assign_key( "<Ctrl-Left>",           "prev_word" )
  235.    assign_key( "<Ctrl-Right>",          "next_word" )
  236.    assign_key( "<Ctrl-Backspace>",      "delete_prev_word" )
  237.    assign_key( "<Ctrl-PageUp>",         "goto_buffer_top" )
  238.    assign_key( "<Ctrl-Home>",           "goto_window_top" )
  239.    assign_key( "<Ctrl-End>",            "goto_window_bottom" )
  240.    assign_key( "<Ctrl-PageDown>",       "goto_buffer_bottom" )
  241.    assign_key( "<Ctrl-Enter>",          "auto_indent_nl" )
  242.  
  243.    assign_key( "<Alt-Space>",           "outdent_space_maybe" )
  244.    assign_key( "<Alt-Backspace>",       "delete_word" )
  245.    assign_key( "<Alt-Up>",              "n_window")
  246.    assign_key( "<Alt-Right>",           "e_window")
  247.    assign_key( "<Alt-Down>",            "s_window")
  248.    assign_key( "<Alt-Left>",            "w_window")
  249. }
  250.  
  251. #
  252. # EVENT.EMULATION_CHANGED Occured - Brief Emulation is no longer active.
  253. #
  254. global function brief_exit()
  255. {
  256.    # delete event handlers
  257.    delete_event(EVENT.EMULATION_CHANGED, function_id("brief_exit"))
  258. }
  259.  
  260. # this function is used to customize the menu so that the keys you have
  261. # assigned to do the same thing as the menuitem will show on the menu
  262. # It should be global and start with the string inside emulation_mode
  263. function brief_menu()
  264. {
  265.    local menu = menu_info( 0 , MI_MENUHANDLE );
  266.    local temp_array[]
  267.  
  268.    temp_array[ IDM_ADDFILE    ].mapped = "create_buf_and_win_key"
  269.    temp_array[ IDM_SAVE       ].mapped = "write_block_key"
  270.    temp_array[ IDM_FIND       ].mapped = "search_forward"
  271.    temp_array[ IDM_FINDAGAIN  ].mapped = "search_again"
  272.    temp_array[ IDM_CHANGE     ].mapped = "replace_forward"
  273.    temp_array[ IDM_COMMAND    ].mapped = "invoke_function"
  274.    temp_array[ IDM_CLOSE      ].mapped = "brief_delete_buffer"
  275.    temp_array[ IDM_INSERTFILE ].mapped = "read_file_key"
  276.  
  277.    mapped_menu_functions = temp_array
  278.  
  279.    # add keys to menu that contain non-special-dialog box functions
  280. #   optional_function( "fix_menu_text", IDM_ADDFILE,      "create_buf_and_win_key" )
  281. #   optional_function( "fix_menu_text", IDM_SAVE,         "write_block_key" )
  282. #   optional_function( "fix_menu_text", IDM_FIND,         "search_forward" )
  283. #   optional_function( "fix_menu_text", IDM_FINDAGAIN,    "search_again" )
  284. #   optional_function( "fix_menu_text", IDM_CHANGE,       "replace_forward" )
  285. #   optional_function( "fix_menu_text", IDM_COMMAND,      "invoke_function" )
  286. #   optional_function( "fix_menu_text", IDM_CLOSE,        "brief_delete_buffer" )
  287. #   optional_function( "fix_menu_text", IDM_INSERTFILE,   "read_file_key" )
  288. }
  289.  
  290. #---------------------------------------------------------------#
  291. #                                                               #
  292. #       Functions required to support the brief calls           #
  293. #                                                               #
  294. #---------------------------------------------------------------#
  295.  
  296. #------------- Basic text commands support ---------------------------------#
  297.  
  298. function brief_backspace()
  299. {
  300.    if ((current_column > 1) || (and(buffer_flags, BUFFER_WP_ENABLED)))
  301.       backspace()
  302. }
  303.  
  304. #------------- Playback/record and Macros functions unique to brief --------#
  305.  
  306. #------------- Miscellaneous functions unique to brief ---------------------#
  307.  
  308.  
  309. function brief_delete_buffer()
  310. {
  311.    delete_buffer_key("", 1);
  312. }
  313.  
  314.  
  315. #------------- Window functions unique to brief ---------------------#
  316.  
  317. local NORTH = 0x1
  318. local EAST  = 0x2
  319. local SOUTH = 0x4
  320. local WEST  = 0x8
  321.  
  322. local function get_window_direction( msg )
  323. {
  324.    local   ch
  325.  
  326.    if (msg)
  327.    {
  328.       notify( msg "(use arrow keys)." )
  329.    }
  330.  
  331.    ch = getkey()
  332.  
  333.    if (ch == KEYCODE_UP || ch == KEYCODE_NUM_UP)            return NORTH
  334.    else if (ch == KEYCODE_DOWN  || ch == KEYCODE_NUM_DOWN)  return SOUTH
  335.    else if (ch == KEYCODE_LEFT  || ch == KEYCODE_NUM_LEFT)  return WEST
  336.    else if (ch == KEYCODE_RIGHT || ch == KEYCODE_NUM_RIGHT) return EAST
  337.  
  338.    return 0
  339. }
  340.  
  341. ## brief-style window resize (or as close to it as need be)
  342. #
  343. function brief_resize_window( ironside, amount )
  344. {
  345.    local   direction
  346.    local   x0 = window_x0
  347.    local   y0 = window_y0
  348.    local   xExt = window_width
  349.    local   yExt = window_height
  350.    local   useAmount
  351.    local minSize = 20
  352.  
  353.    if (!argcount())
  354.    {
  355.       ironside = get_window_direction( "Select side to move " )
  356.       amount = 10
  357.    }
  358.    else if ( argcount() != 2 )
  359.    {
  360.       amount = 10
  361.    }
  362.  
  363.    if (ironside)
  364.    {
  365.       direction = get_window_direction( "Move window edge " )
  366.  
  367.       while (direction)
  368.       {
  369.          if (ironside == NORTH)
  370.          {
  371.             if (direction == NORTH)
  372.             {
  373.                yExt += amount
  374.             }
  375.             else if (direction == SOUTH)
  376.             {
  377.                if (yExt > minSize)
  378.                {
  379.                   yExt -= amount;
  380.                }
  381.             }
  382.          }
  383.          else if (ironside == SOUTH)
  384.          {
  385.             if (direction == NORTH)
  386.             {
  387.                if (yExt > minSize)
  388.                   {
  389.                   yExt -= amount
  390.                   y0 += amount
  391.                   }
  392.             }
  393.             else if (direction == SOUTH)
  394.             {
  395.                if (y0 > 0)
  396.                   {
  397.                   yExt += amount
  398.                   y0 -= amount
  399.                   }
  400.             }
  401.          }
  402.          else if (ironside == WEST)
  403.          {
  404.             if (direction == WEST)
  405.             {
  406.                if (x0 > 0)
  407.                { 
  408.                   x0 -= amount
  409.                   xExt += amount
  410.                }
  411.             }
  412.             else if (direction == EAST)
  413.             {
  414.                if (xExt > minSize)
  415.                {
  416.                   x0 += amount
  417.                   xExt -= amount
  418.                }
  419.             }
  420.          }
  421.          else if (ironside == EAST)
  422.          {
  423.             if (direction == WEST)
  424.             {
  425.                if (xExt > minSize)
  426.                   xExt -= amount
  427.             }
  428.             else if (direction == EAST)
  429.             {
  430.                xExt += amount
  431.             }
  432.          }
  433.  
  434.          frame_window( x0, y0, xExt, yExt )
  435. #         display_update()
  436.          direction = get_window_direction( "Move window edge " )
  437.       }
  438.    }
  439.    message( "" )
  440. }
  441.  
  442.               
  443. function point_in_rect( x, y, left, right, bottom, top )
  444. {
  445.    if ( (x >= left) && (x <= right) &&
  446.         (y >= bottom) && (y <= top))
  447.       return TRUE
  448.    else
  449.       return FALSE
  450. }
  451.  
  452.  
  453. function window_containing_point( x, y )
  454. {
  455.    local cur_win = current_window
  456.    local w
  457.    local found_win = 0
  458.  
  459.    while ( !found_win && ( (w = next_window("", 0, 1)) != cur_win ) )
  460.       {
  461.       if (point_in_rect(x, y, window_x0, window_x0+window_width,
  462.                         window_y0, window_y0+window_height) )
  463.          found_win = w
  464.       }
  465.  
  466.    return found_win
  467. }
  468.  
  469.  
  470. ## Returns TRUE if the current window is intersected by a horizontal
  471. #  or vertical line. Returns FALSE if not.
  472. #
  473. #  Note: either input x or y must be zero.
  474. #
  475. function line_intersects_current_window( x, y )
  476. {
  477.    local w
  478.  
  479.       if (x)
  480.          {
  481.          if ( (x >= window_x0) && (x <= window_x0+window_width) )
  482.             return TRUE
  483.          }
  484.       else
  485.          {
  486.          if ( (y >= window_y0) && (y <= window_y0+window_height) )
  487.             return TRUE
  488.          }
  489.  
  490.    return FALSE
  491. }
  492.  
  493.  
  494.  
  495. function adjacent_window( direction ) 
  496. {
  497.    local line_x = 0
  498.    local line_y = 0
  499.    local NULL = 0
  500.    local savewin = current_window
  501.    local target_edge
  502.    local wflags
  503.  
  504.    local cur_win = current_window
  505.    local w
  506.    local found_win = 0
  507.    local margin = 10    # Minimum amount of target window visisble
  508.  
  509.    if (direction == NORTH )
  510.       {
  511.       line_x = window_x0 + (window_width/2)
  512. #      target_edge = window_y0 + window_height - margin
  513.       target_edge = window_y0 + margin
  514.       }
  515.    else if (direction == SOUTH)
  516.       {
  517.       line_x = window_x0 + (window_width/2)
  518. #      target_edge = window_y0   + margin
  519.       target_edge = window_y0 + window_height - margin
  520.       }
  521.    else if (direction == EAST)
  522.       {
  523.       line_y = window_y0 + (window_height/2)
  524. #      target_edge = window_x0 + window_width - margin
  525.       target_edge = window_x0 + margin
  526.       }
  527.    else
  528.       {
  529.       line_y = window_y0 + (window_height/2)
  530. #      target_edge = window_x0 + margin
  531.       target_edge = window_x0 + window_width - margin
  532.       }
  533.  
  534.  
  535.    while ( !found_win && ( (w = next_window("", 0, 1)) != savewin) )
  536.       {
  537.       if (line_intersects_current_window(line_x, line_y) )
  538.          {
  539.          if (direction == NORTH && window_y0 >= target_edge)
  540.             found_win = w
  541.          else if ( (direction == SOUTH) &&
  542.                    (window_y0+window_height <= target_edge) )
  543.             found_win = w
  544.          else if ( (direction == EAST) &&
  545.                    (window_x0 >= target_edge) )
  546.             found_win = w
  547.          else if ( (direction == WEST) &&
  548.                    (window_x0+window_width <= target_edge) )
  549.             found_win = w
  550.          }
  551.       }
  552.  
  553.    current_window = savewin
  554.    return found_win
  555. }
  556.  
  557.  
  558. global function n_window() {
  559.    return move_to_adjacent_window( NORTH )
  560. }
  561. global function s_window() {
  562.    return move_to_adjacent_window( SOUTH )
  563. }
  564. global function w_window() {
  565.    return move_to_adjacent_window( WEST )
  566. }
  567. global function e_window() {
  568.    return move_to_adjacent_window( EAST )
  569. }
  570.  
  571. local function move_to_adjacent_window( direction )
  572. {
  573.    local win = adjacent_window( direction )
  574.  
  575.    if ( win ) {
  576.       current_window = win
  577.       display_filename()
  578.       return TRUE
  579.    } else {
  580.       notify("No window found.")
  581.       return FALSE
  582.    }
  583. }
  584.  
  585.  
  586. ## brief-style window change
  587. #
  588. function brief_change_window( direction ) {
  589.    local status = FALSE
  590.  
  591.    if (!argcount())
  592.       direction = get_window_direction( "Select new current window " )
  593.  
  594.    if ( direction == NORTH )    status = n_window()
  595.    else if (direction == SOUTH) status = s_window()
  596.    else if (direction == WEST)  status = w_window()
  597.    else if (direction == EAST)  status = e_window()
  598.    else message( "" )
  599.    return status
  600. }
  601.  
  602. ## brief-style window creation
  603. #
  604. function brief_create_window( direction )
  605. {
  606.    local   ch
  607.  
  608.    if (!argcount())
  609.    {
  610.       direction = get_window_direction( "Select side for new window ")
  611.       message( "" )
  612.    }
  613.  
  614.    if (direction)
  615.    {
  616.       if (!mdi_mode)
  617.          toggle_window_mode()
  618.  
  619.       if (and( direction, NORTH+SOUTH) )
  620.       {
  621.          if (split_window_horizontal())
  622.          {
  623.             if ( direction == NORTH )
  624.                prev_window()
  625.  
  626.             return TRUE
  627.          }
  628.       }
  629.       else  # direction = EAST or WEST
  630.       {
  631.          if (split_window_vertical())
  632.          {
  633.             if (direction == WEST)
  634.                prev_window()
  635.  
  636.             return TRUE
  637.          }
  638.       }
  639.    }
  640.    return FALSE
  641. }
  642.  
  643. ## brief-style window delete
  644. #
  645.  
  646. function brief_delete_window( direction )
  647. {
  648.    local   w = current_window
  649.    local   ch
  650.  
  651.    if ( next_window("", 0, 1) == w )
  652.    {
  653.       warning( "Cannot delete last window" )
  654.       return
  655.    }
  656.    else
  657.    {
  658.       if (w)
  659.          current_window = w
  660.    }
  661.  
  662.    if (!argcount())
  663.    {
  664.       direction = get_window_direction( "Select edge to delete ")
  665.       message( "" )
  666.    }
  667.  
  668.    if (direction)
  669.       delete_window_edge( direction )
  670. }
  671.  
  672. ## delete a window's edge given the direction of the edge
  673. #       the edge is not deleted unless an adjoining window can be found
  674.  
  675. local function delete_window_edge( dir )
  676. {
  677.    local x0 = window_x0
  678.    local y0 = window_y0
  679.    local x1 = x0 + window_width - 1
  680.    local y1 = y0 + window_height - 1
  681.    local cw = current_window;
  682.    local cur;
  683.  
  684.    if (and(window_flags,WINDOW_SYSTEM))
  685.       cur = next_window("", 0, 1);
  686.    else
  687.       cur = cw;
  688.  
  689.    do
  690.    {
  691.       if( current_window != cur &&
  692.           delete_adjacent_edge( dir, cur, x0, y0, x1, y1 ))
  693.       {
  694.          delete_window_key()
  695.          if (cw)
  696.             current_window = cw
  697.  
  698.          return
  699.       }
  700.       next_window("", 0, 1)
  701.    } while( cur != current_window )
  702.  
  703.    if (cw)
  704.       current_window = cw;
  705.  
  706.    warning( "Edge does not have exactly two adjoining windows" )
  707. }
  708.  
  709. local function delete_adjacent_edge( dir, cur, x0, y0, x1, y1 )
  710. {
  711.    local cx0 = window_x0
  712.    local cy0 = window_y0
  713.    local cx1 = cx0 + window_width - 1
  714.    local cy1 = cy0 + window_height - 1
  715.    local margin = 2     # pixels window edges can be separated or overlap
  716.  
  717.    if( (cx0 >= x0 - margin) && (cx0 <= x0 + margin) && 
  718.        (cx1 >= x1 - margin) && (cx1 <= x1 + margin) )
  719.    {
  720.       if( (dir == SOUTH) && (cy1 >= y0 - margin) && (cy1 <= y0 + margin) )  # above
  721.       {
  722.          frame_window( x0, cy0, window_width, y1 - cy0 + 1, cur )
  723.          return 1
  724.       }
  725.       else if( dir == NORTH && (cy0 >= y1 - margin) && (cy0 <= y1 + margin) ) # below
  726.       {
  727.          frame_window( x0, y0, window_width, cy1 - y0 + 1, cur )
  728.          return 1
  729.       }
  730.    }
  731.    else if( (cy0 >= y0 - margin) && (cy0 <= y0 + margin) && 
  732.             (cy1 >= y1 - margin) && (cy1 <= y1 + margin) )
  733.    {
  734.       if( (dir == WEST) && (cx1 >= x0 - margin) && (cx1 <= x0 + margin) ) # left
  735.       {
  736.          frame_window( cx0, cy0, x1 - cx0 + 1, window_height, cur )
  737.          return 1
  738.       }
  739.       else if( (dir == EAST) && (cx0 >= x1 - margin) && (cx0 <= x1 + margin) ) # right
  740.       {
  741.          frame_window( x0, y0, cx1 - x0 + 1, window_height, cur )
  742.          return 1
  743.       }
  744.    }
  745.  
  746.    return 0
  747. }
  748.  
  749.