home *** CD-ROM | disk | FTP | other *** search
- # $Header: P:/source/ppee/macros/brief.pev 1.166 20 Aug 1990 13:47:02 skipr $
-
- ##############################################################################
- #
- # Sage Software - POLYTRON Division
- # 1700 NW 167th Place
- # Beaverton, OR 97006
- #
- # Copyright 1990, Sage Software, Inc.
- #
- # Permission is hereby granted for licensed users of Sage Professional
- # Editor and PolyAwk to copy and modify this source code for their own
- # personal use. These derivative works may be distributed only to other
- # licensed Sage Professional Editor and PolyAwk users. All other usage
- # is prohibited without express written permission from Sage Software.
- #
- ##############################################################################
-
- #### $Workfile: brief.pel $: Key bindings for Brief compatibility
-
- local brief_keymap = -1
-
- ##
- ## BriefKeymap() - define Brief key bindings
- ##
-
- # key #- found in startup keymap
- # # already defined
- # # not implemented yet
-
- global function brief() #PUBLIC #VOID
- {
- emulation_mode = "brief";
- execute_event_handler( EVENT_EMULATION_CHANGED );
-
- default_window_flags = \
- nominal_border_flags = \
- WINDOW_PLAIN
-
- if ( !and(window_flags, WINDOW_SYSTEM )) {
- window_flags = default_window_flags
- }
-
-
- search_flags = \
- + SEARCH_MAXIMAL_MATCH \
- + SEARCH_FORWARD \
- + SEARCH_BLOCK \
- + SEARCH_REGEX \
- # + SEARCH_ADVANCE \
- # + SEARCH_IGNORE_CASE \
- # + SEARCH_WRAPS \
- # + SEARCH_HIGHLIGHT \
-
- toggle_auto_indent( 0 )
-
- if ( !dialog_window ) {
- toggle_dialog( 1 )
- }
-
- message_level = 0
-
-
-
- attach_event_handler( EVENT_NEW_EDIT_FILE, \
- function_id( "new_edit_file" ) );
-
- # Enable the keymap. Subsequent mods to the keymap will persist
- # through the end of the session.
- # Only one-time initialization should follow this point.
-
- if( brief_keymap >= 0 ){
- current_keymap = brief_keymap
- return
- }
-
- brief_keymap = current_keymap = create_keymap( factory_keymap )
-
-
- #--------------------------------------------------------------
- # Keypad arrows
- #--------------------------------------------------------------
- assign_key( "<Keypad-8>", "n_window")
- assign_key( "<Keypad-6>", "e_window")
- assign_key( "<Keypad-2>", "s_window")
- assign_key( "<Keypad-4>", "w_window")
-
- assign_key( "<Alt-Up>", "n_window")
- assign_key( "<Alt-Right>", "e_window")
- assign_key( "<Alt-Down>", "s_window")
- assign_key( "<Alt-Left>", "w_window")
-
-
- #--------------------------------------------------------------
- # Basic Text commands
- #--------------------------------------------------------------
-
- assign_key( "<Enter>", "auto_indent_cr" )
- #-assign_key( "<Ctrl-Enter>", "auto_indent_nl" )
- #-assign_key( "<Alt-D>", "delete_line" )
- #-assign_key( "<Del>", "delete_chars" )
- assign_key( "<Alt-K>", "delete_to_eol" )
- assign_key( "<Tab>", "indent_tab_maybe" )
- assign_key( "<Shift-Tab>", "outdent_tab_maybe" )
- # assign_key( "<Space>", "indent_outdent_space" )
- assign_key( "<Bksp>", "brief_backspace" )
- assign_key( "<Ctrl-Bksp>", "brief_backspace" )
-
-
- #--------------------------------------------------------------
- # Macros and keystroke recordings
- #--------------------------------------------------------------
- assign_key( "<Alt-F7>", "brief_load_key_file" )
- assign_key( "<Alt-F8>", "brief_write_key_file" )
- assign_key( "<F7>", "brief_record_macro" )
- assign_key( "<F8>", "brief_playback_macro" )
- assign_key( "<F9>", "system_key" )
- assign_key( "<F10>", "invoke_function" )
- assign_key( "<Shift-F7>", "brief_pause_recording" )
- # assign_key( "<Shift-F9>", "" )
-
-
- #--------------------------------------------------------------
- # Manipulating Buffers
- #--------------------------------------------------------------
- assign_key( "<Alt-B>", "buffer_list" )
- assign_key( "<Alt-E>", "edit_file_key" )
- assign_key( "<Alt-F>", "display_filename" )
- assign_key( "<Alt-Minus>", "prev_buffer_key" )
- assign_key( "<Alt-Keypad-Minus>", "prev_buffer_key" )
- assign_key( "<Ctrl-Minus>", "brief_delete_buffer" )
- assign_key( "<Ctrl-Keypad-Minus>", "brief_delete_buffer" )
- assign_key( "<Alt-R>", "read_file_key" )
- assign_key( "<Alt-O>", "change_output_name" )
- assign_key( "<Alt-N>", "next_buffer_key" )
- assign_key( "<Ctrl-X>", "write_and_exit" )
-
-
- #--------------------------------------------------------------
- # Windows
- #--------------------------------------------------------------
- assign_key( "<F1>", "brief_change_window" )
- assign_key( "<F2>", "adjust_window" )
- assign_key( "<F3>", "brief_create_window" )
- assign_key( "<F4>", "brief_delete_window" )
- assign_key( "<Alt-F1>", "toggle_borders" )
- assign_key( "<Alt-F2>", "toggle_window_zoom" )
-
-
- #--------------------------------------------------------------
- # Cursor Movement
- #--------------------------------------------------------------
- #-assign_key( "<Down>", "down" )
- #-assign_key( "<Left>", "left" )
- #-assign_key( "<Right>", "right" )
- #-assign_key( "<Up>", "up" )
- assign_key( "<Ctrl-Left>", "prev_word" )
- assign_key( "<Alt-Bksp>", "delete_word" )
- assign_key( "<Ctrl-Bksp>", "delete_prev_word" )
- assign_key( "<Ctrl-T>", "scroll_window_top" )
- assign_key( "<Home>", "home_key" )
- assign_key( "<End>", "end_key" )
- assign_key( "<Ctrl-Home>", "goto_window_top" )
- assign_key( "<Ctrl-End>", "goto_window_bottom" )
- # assign_key( "<Keypad-7>", "goto_window_left" )
- # assign_key( "<Keypad-1>", "goto_window_right" )
-
- #-assign_key( "<PgUp>", "page_up" )
- #-assign_key( "<PgDn>", "page_down" )
- assign_key( "<Alt-G>", "goto_line_key" )
- assign_key( "<Ctrl-C>", "center_cursor" )
- assign_key( "<Ctrl-Right>", "next_word" )
- assign_key( "<Ctrl-B>", "scroll_window_bottom")
- assign_key( "<Ctrl-U>", "scroll_down_1")
- assign_key( "<Ctrl-D>", "scroll_up_1" )
-
- assign_key( "<Ctrl-PgUp>", "goto_buffer_top" )
- assign_key( "<Ctrl-PgDn>", "goto_buffer_bottom" )
-
-
- #--------------------------------------------------------------
- # Marked Blocks
- #--------------------------------------------------------------
- assign_key( "<Alt-M>", "set_inclusive_mark" )
- assign_key( "<Alt-L>", "set_line_mark" )
- assign_key( "<Alt-C>", "set_column_mark" )
- assign_key( "<Alt-A>", "set_exclusive_mark" )
- assign_key( "<Keypad-+>", "copy_to_scrap_key" )
-
- assign_key( "<Alt-P>", "print_buffer" )
- assign_key( "<Alt-W>", "write_block_key" )
- #-assign_key( "<Ins>", "insert_scrap" )
- assign_key( "<Keypad-Minus>", "brief_delete_to_scrap")
-
-
- #--------------------------------------------------------------
- # Miscellaneous
- #--------------------------------------------------------------
-
- assign_key( "<Alt-1>", "place_bookmark 1")
- assign_key( "<Alt-2>", "place_bookmark 2")
- assign_key( "<Alt-3>", "place_bookmark 3")
- assign_key( "<Alt-4>", "place_bookmark 4")
- assign_key( "<Alt-5>", "place_bookmark 5")
- assign_key( "<Alt-6>", "place_bookmark 6")
- assign_key( "<Alt-7>", "place_bookmark 7")
- assign_key( "<Alt-8>", "place_bookmark 8")
- assign_key( "<Alt-9>", "place_bookmark 9")
- assign_key( "<Alt-0>", "place_bookmark 10")
- assign_key( "<Alt-J>", "goto_bookmark")
-
- assign_key( "<Ctrl-A>", "optional_function display_ascii_table" )
- assign_key( "<Ctrl-G>", "optional_function routines" )
- assign_key( "<Alt-X>", "done" )
- assign_key( "<Alt-I>", "toggle_insert_mode" )
- assign_key( "<Ctrl-N>", "goto_next_error" )
- assign_key( "<Ctrl-W>", "toggle_file_backup" )
- assign_key( "<Keypad-*>", "undo" )
- #-assign_key( "<Alt-U>", "undo" )
- assign_key( "<Alt-Y>", "redo" )
-
- assign_key( "<Alt-H>", "help")
- assign_key( "<Alt-Z>", "system" )
- assign_key( "<Alt-V>", "print_version" )
- assign_key( "<Ctrl-P>", "display_errors" )
-
- assign_key( "<Alt-Q>", "insert_quoted_key" )
- assign_key( "<Alt-F10>", "compile_buffer" )
- assign_key( "<Ctrl-R>", "repeat_key_action" )
- assign_key( "<Shift-F10>", "insert_keys" )
- assign_key( "#27", "expand_template" ) # Ctrl-[ or Esc
-
-
- #--------------------------------------------------------------
- # Searching and translating
- #--------------------------------------------------------------
- assign_key( "<Alt-S>", "search_forward" )
- assign_key( "<F5>", "search_forward" )
- assign_key( "<Alt-T>", "replace_forward" )
- assign_key( "<F6>", "replace_forward" )
- assign_key( "<Alt-F5>", "search_backward" )
- assign_key( "<Shift-F5>", "search_again" )
- assign_key( "<Ctrl-F5>", "toggle_search_case" )
- assign_key( "<Alt-F6>", "replace_backward" )
- assign_key( "<Shift-F6>", "replace_again" )
- assign_key( "<Ctrl-F6>", "toggle_search_regex" )
-
-
- #--------------------------------------------------------------
- # Mouse button codes
- #--------------------------------------------------------------
-
- assign_mouse_buttons()
- }
-
-
- #---------------------------------------------------------------#
- # #
- # Functions required to support the brief calls #
- # #
- #---------------------------------------------------------------#
-
- #------------- Basic text commands support ---------------------------------#
-
- function brief_backspace(){
- if ((current_column > 1) || (and(buffer_flags, BUFFER_WP_ENABLED))) {
- backspace()
- }
- }
-
- #------------- Playback/record and Macros functions unique to brief --------#
-
-
- global function brief_delete_to_scrap() {
- local status
-
- if (!region_type())
- drop_anchor( LINE_SELECTION )
-
- status = copy_to_scrap()
- delete_chars()
- raise_anchor()
- return status
- }
-
-
- #------------- Miscellaneous functions unique to brief ---------------------#
-
-
- function brief_delete_buffer(){
- delete_buffer_key("", 1);
- }
-
- #------------- Window functions unique to brief ---------------------#
-
- local NORTH = 0x1
- local EAST = 0x2
- local SOUTH = 0x4
- local WEST = 0x8
-
- local function get_window_direction( msg ) {
- local ch
-
-
- while (TRUE) {
- if (msg) {
- begin_dialog()
- notify( msg "(use arrow keys)." )
- ch = getchar()
- end_dialog()
- } else {
- ch = getchar()
- }
- if (ch == 0) {
- ch = getchar()
- if (ch == SCANCODE_UP) return NORTH
- else if (ch == SCANCODE_DOWN) return SOUTH
- else if (ch == SCANCODE_LEFT) return WEST
- else if (ch == SCANCODE_RIGHT) return EAST
- }
- return 0
- }
- }
-
-
-
- local function adjacent_window( direction ) {
- local x = window_text_x0 + distance_to_window_left()
- local y = window_text_y0 + distance_to_window_top()
- local NULL = 0
- local margin
- local i
- local win
- local savewin = current_window
- local wflags
-
- if (direction == NORTH) {
- margin = 0
- } else if (direction == EAST) {
- margin = display_width
- } else if (direction == SOUTH) {
- margin = display_height
- } else if (direction == WEST) {
- margin = 0
- } else {
- return NULL
- }
-
- if ( and(direction, SOUTH+NORTH) ) {
- direction = (margin == 0) ? -1 : 1
- for ( ; y != margin; y += direction) {
- win = window_containing( x, y )
- if ((win != NULL) && (win != current_window) ) {
- current_window = win
- wflags = window_flags
- if (savewin)
- current_window = savewin
- if (!(and(wflags,WINDOW_SYSTEM)) )
- return win
- }
- }
- } else {
- direction = (margin == 0) ? -1 : 1
- for ( ; x != margin; x += direction) {
- win = window_containing( x, y )
- if ((win != NULL) && (win != current_window)) {
- current_window = win
- wflags = window_flags
- if (savewin)
- current_window = savewin
- if (!(and(wflags,WINDOW_SYSTEM)) )
- return win
- }
- }
- }
- return NULL
- }
-
-
- global function n_window() {
- return move_to_adjacent_window( NORTH )
- }
- global function s_window() {
- return move_to_adjacent_window( SOUTH )
- }
- global function w_window() {
- return move_to_adjacent_window( WEST )
- }
- global function e_window() {
- return move_to_adjacent_window( EAST )
- }
-
- local function move_to_adjacent_window( direction ) {
- local win = adjacent_window( direction )
-
- if ( win ) {
- current_window = win
- display_filename()
- return TRUE
- } else {
- notify("No window found.")
- return FALSE
- }
- }
-
-
- ## brief-style window change
- #
- function brief_change_window( direction ) {
- local status = FALSE
-
- if (!argcount())
- direction = get_window_direction( "Select new current window " )
-
- if ( direction == NORTH ) status = n_window()
- else if (direction == SOUTH) status = s_window()
- else if (direction == WEST) status = w_window()
- else if (direction == EAST) status = e_window()
- else message( "" )
- return status
- }
-
- ## brief-style window resize (or as close to it as need be)
- #
- function brief_resize_window( ironside, amount ) {
- local direction
- local x0 = window_x0
- local y0 = window_y0
- local xExt = window_width
- local yExt = window_height
- local useAmount
-
- if (!argcount()) {
- ironside = get_window_direction( "Select side to move " )
- amount = 0;
- } else if ( (useAmount = (argcount() == 2)) ) {
- if (!amount)
- return;
- }
-
- if (ironside) {
- direction = (useAmount) \
- ? ironside \
- : get_window_direction( "Move window edge " )
-
- while (direction) {
- if (ironside == NORTH) {
- if (direction == NORTH) {
- if (y0 > 0)
- { y0--; yExt++; }
- } else if (direction == SOUTH) {
- if (yExt > 1)
- { y0++; yExt--; }
- }
- } else if (ironside == SOUTH) {
- if (direction == NORTH) {
- if (yExt > 1)
- yExt--
- } else if (direction == SOUTH) {
- if (yExt+y0 < display_height)
- yExt++
- }
- } else if (ironside == WEST) {
- if (direction == WEST) {
- if (x0 > 0)
- { x0--; xExt++; }
- } else if (direction == EAST) {
- if (xExt > 1)
- { x0++; xExt--; }
- }
- } else if (ironside == EAST) {
- if (direction == WEST) {
- if (xExt > 1)
- xExt--
- } else if (direction == EAST) {
- if (xExt+x0 < display_width)
- xExt++
- }
- }
-
- if (useAmount) {
- amount--;
- }
-
- if (amount == 0) {
- frame_window( x0, y0, xExt, yExt )
- display_update()
- if (useAmount) # are we done yet
- break;
- direction = get_window_direction( "" )
- }
- }
- }
- message( "" )
- }
-
-
- ## brief-style window creation
- #
- function brief_create_window( direction )
- {
- local ch
-
- if (!argcount()) {
- direction = get_window_direction( "Select side for new window ")
- message( "" )
- }
-
- if (direction) {
- if (and( direction, NORTH+SOUTH) ) {
- if (split_window_horizontal()) {
- if ( direction == NORTH )
- prev_window()
- return TRUE
- }
- } else { #direction = EAST or WEST
- if (split_window_vertical()) {
- if (direction == WEST)
- prev_window()
- return TRUE
- }
- }
- }
- return FALSE
- }
-
- ## brief-style window delete
- #
-
- function brief_delete_window( direction ){
- local w = current_window
- local ch
-
- if ( next_window() == w ) {
- warning( "Cannot delete last window" )
- return
- } else {
- if (w)
- current_window = w
- }
-
- if (!argcount()) {
- direction = get_window_direction( "Select edge to delete ")
- message( "" )
- }
-
- if (direction) {
- delete_window_edge( direction )
- } else if (current_key == 0x3E) # F4 - we used getchar(), remember
- delete_tiled_window()
- }
-
- ## delete a window's edge given the direction of the edge
- # the edge is not deleted unless an adjoining window can be found
-
- local function delete_window_edge( dir ){
- local x0 = window_x0
- local y0 = window_y0
- local x1 = x0 + window_width - 1
- local y1 = y0 + window_height - 1
- local cw = current_window;
- local cur;
-
- if (and(window_flags,WINDOW_SYSTEM))
- cur = next_window();
- else
- cur = cw;
-
- do {
- if( current_window != cur \
- && delete_adjacent_edge( dir, cur, x0, y0, x1, y1 )){
- delete_window_key()
- if (cw)
- current_window = cw
- return
- }
- next_window()
- } while( cur != current_window )
- if (cw)
- current_window = cw;
-
- warning( "Edge does not have exactly two adjoining windows" )
- }
-
- local function delete_adjacent_edge( dir, cur, x0, y0, x1, y1 ){
- local cx0 = window_x0
- local cy0 = window_y0
- local cx1 = cx0 + window_width - 1
- local cy1 = cy0 + window_height - 1
-
- if( x0 == cx0 && x1 == cx1 ){
- if( dir == NORTH && cy1 + 1 == y0 ){ # above
- frame_window( x0, cy0, window_width, y1 - cy0 + 1, cur )
- return 1
- } else if( dir == SOUTH && y1 + 1 == cy0 ){ # below
- frame_window( x0, y0, window_width, cy1 - y0 + 1, cur )
- return 1
- }
- } else if( y0 == cy0 && y1 == cy1 ){
- if( dir == WEST && cx1 + 1 == x0 ){ # left
- frame_window( cx0, cy0, x1 - cx0 + 1, window_height, cur )
- return 1
- } else if( dir == EAST && x1 + 1 == cx0 ){ # right
- frame_window( x0, y0, cx1 - x0 + 1, window_height, cur )
- return 1
- }
- }
-
- return 0
- }
-
-
- #
- # new_edit_file()
- #
- # Whenever a new edit file is created, the extension is stripped from
- # the file name and a function with that extension (preceded by "_")
- # is invoked. If the function does not exist, "default()" is called.
- #
- global function new_edit_file() {
- local ext = path_ext( buffer_filename );
- local lev = message_level;
- local def_name = "default"
- local id
-
- message_level = 3;
-
- if (ext) {
- if (substr( ext, 1, 1 ) == "." ) {
- ext = "_" substr( ext, 2 );
- id = function_id( ext );
- if ( id ) {
- message_level = lev;
- execute_function( ext );
- return;
- }
- }
- }
-
- id = function_id( def_name );
- message_level = lev;
- if ( id )
- execute_function( def_name );
-
- }
-
-
-
- global currentRecordString = "";
- local pausedRecordString = "";
- local recordingPaused = 0;
-
- function brief_pause_recording(){
- if (!recording && recordingPaused) {
- record();
- recordingPaused = 0;
- recording = 1;
- } else if (recording == 1) {
- pausedRecordString = pausedRecordString record();
- recordingPaused = 1;
- recording = 0;
- }
- }
-
-
- function brief_record_macro(){
- local str;
-
- if (playingback)
- return;
-
- if (recordingPaused ) {
- message( "Keystroke macro defined." );
- recordingPaused = 0;
- str = ""
- } else {
- str = record_key();
- }
-
- currentRecordString = pausedRecordString str;
- pausedRecordString = ""
- }
-
- function brief_playback_macro(){
- if (recordingPaused ) {
- message( "Playback while recording." );
- } else {
- if (currentRecordString)
- playback_macro( currentRecordString );
- else
- playback_macro();
- }
- }
-
- function brief_load_key_file(){
- local str = prompt_history( "RECORD", "Keystroke macro file: ", "",1 );
- local fid;
- local ch;
-
- if (str) {
- if ((fid = fopen( str, 0 )) > 0) {
- while ((ch = fgetc(fid)) >= 0) {
- currentRecordString = currentRecordString chr(ch);
- }
- fclose( fid );
- } else {
- notify( "Unable to open: " str );
- }
- }
- }
-
- function brief_write_key_file(){
- local str;
- local fid;
-
- if (currentRecordString) {
- str = prompt_history( "RECORD", "Save keystrokes as: ", "", 1 );
- if (str) {
- if ((fid = fopen( str, 1 )) > 0) {
- fprintf( fid, currentRecordString );
- fclose( fid );
- } else {
- notify( "Unable to open: " str );
- }
- }
- } else {
- notify( "No keystroke macro to save." );
- }
- }
-
-
-