home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
MOTION.PEL
< prev
next >
Wrap
Text File
|
1995-03-22
|
12KB
|
461 lines
# $Header: P:\source\wmacros\motion.pev 1.24 22 Mar 1995 11:00:30 pfhmlw0 $
##############################################################################
#
# Compuware Corporation
# 31440 Northwestern Highway
# Farmington Hills, Michigan 48334-2564
#
# This source code listing contains information that is
# proprietary to Compuware Corporation and may not be copied
# duplicated, translated, transmitted, stored, retrieved
# or in any manner or by any method conveyed or disclosed
# to a third party or parties without express written
# permission from Compuware Corporation.
#
#
##############################################################################
#### $Workfile: motion.pel $: support for cursor motion
local consecutive_homes = 0
local consecutive_ends = 0
# change current position so that it matches the indicated window extremity.
#
# see also: scroll_window_... in windows.pel, which change window
# orientation without affecting the current position.
#
global function goto_window_top() #PUBLIC #VOID
{
return up( distance_to_window_top() )
}
global function goto_window_right() #PUBLIC #VOID
{
return right( distance_to_window_right() )
}
global function goto_window_left() #PUBLIC #VOID
{
# return left( distance_to_window_left() )
return goto_pos(0, window_margin + 1)
}
global function goto_window_bottom() #PUBLIC #VOID
{
return down( distance_to_window_bottom() )
}
global function goto_window_middle() #PUBLIC #VOID
{
current_line += distance_to_window_middle()
}
# home_key()
#
# move the cursor depending on the number of consecutive times the
# <Home> key is typed:
# one time - move to the beginning of the current line
# two times - move to the upper left corner of the window
# three times - move to the beginning of the buffer
global function home_key(keycode)
{
if (argcount() ? (prev_key == keycode) \
: (prev_key == KEYCODE_HOME || prev_key == KEYCODE_NUM_HOME))
{
consecutive_homes++
if (linecommands_enabled && linenumber_width && \
!and(window_flags, WINDOW_ASCII_DUMP))
{
if (consecutive_homes == 2) # <Home><Home>
goto_bolc()
else if (consecutive_homes == 3) # <Home><Home><Home>
goto_window_top()
else # <Home><Home><Home><Home>
goto_buffer_top()
}
else
{
if (consecutive_homes == 2) # <Home><Home>
{
goto_window_top()
goto_bol()
}
else # <Home><Home><Home>
goto_buffer_top()
}
}
else
{
consecutive_homes = 1
goto_bol() # <Home>
}
}
# end_key()
#
# move the cursor depending on the number of consecutive times the
# <End> key is typed:
# one time - move to the end of the current line
# two times - move to the end of the last line in the window
# three times - move to the end of the buffer
global function end_key(keycode)
{
if (argcount() ? (prev_key == keycode) \
: (prev_key == KEYCODE_END || prev_key == KEYCODE_NUM_END))
{
if (++consecutive_ends == 2)
{
goto_window_bottom() # <End><End>
goto_eol()
}
else
goto_buffer_bottom() # <End><End><End>
}
else
{
consecutive_ends = 1
goto_eol() # <End>
}
}
## goto_line() -- move the cursor to column one of the specified line
#
global function goto_line( line ) #PUBLIC #INT
{
line += 0
if ( !argcount() )
line = current_line
else if ( line < 1)
line = 1
return goto_pos( line, 1 )
}
global function goto_line_key()
{
local str, i
str = prompt_history( "GOTOLINE", "Goto line: ", "", 1, 1, "linenum" )
if (!(str ~ "^[ \t]*$" ))
{
i = atoi(str)
if (i)
{
goto_line( i )
message( "" )
}
}
return TRUE
}
## prompt the user for a motion destination; and then go there
# digits are interpreted as a line number
# Alt-digit is interpreted as a mark location.
global function goto_line_or_mark()
{
local str, i
attach_event_handler( EVENT.INVALID_PCHAR, function_id( "maybe_goto_mark" ))
str = prompt( "Goto line: ", "", "goto_line_or_mark_dialog" )
if (str ~ "^[ \t]*$")
return
else
{
message( "" )
if( str ~ "^Mark #[0-9]$" )
{
i = atoi( substr( str, 7 ))
goto_bookmark( i ? i : 10 )
}
else if( str && ( i = atoi( str )))
goto_line( i )
else
goto_bookmark(str)
delete_event( EVENT.INVALID_PCHAR, function_id( "maybe_goto_mark" ))
}
}
function maybe_goto_mark()
{
local mid = alt_digit_p( current_key )
if( mid != -1 )
prompt_response = "Mark #" mid
}
function alt_digit_p( key )
{
if( key == KEYCODE_ALT_1 )
return 1
else if( key == KEYCODE_ALT_2 )
return 2
else if( key == KEYCODE_ALT_3 )
return 3
else if( key == KEYCODE_ALT_4 )
return 4
else if( key == KEYCODE_ALT_5 )
return 5
else if( key == KEYCODE_ALT_6 )
return 6
else if( key == KEYCODE_ALT_7 )
return 7
else if( key == KEYCODE_ALT_8 )
return 8
else if( key == KEYCODE_ALT_9 )
return 9
else if( key == KEYCODE_ALT_0 )
return 0
else
return -1
}
## word search functions
global function next_word( n, patt ) #PUBLIC #INT
{
search_count = ( n ? 0+n : 1 )
return search(( patt ? patt : "<" ), SEARCH_FWD_REGEX_ADV )
}
global function prev_word( n, patt ) #PUBLIC #INT
{
# to move past last character found
search_count = ( n ? 0+n : 1)
return search(( patt ? patt : "<" ), SEARCH_BKWD_REGEX_ADV )
}
## vertical "word" motion
global function up_whitespace() #PUBLIC #VOID
{
# Move up, in the same column, until we enter whitespace
while( !in_whitespace() && up() ){
}
# Move up, in the same column, until we leave whitespace
while( up() && in_whitespace() ){
}
}
global function down_whitespace() #PUBLIC #VOID
{
# Move down, in the same column, until we enter whitespace
while( !in_whitespace() && down() ){
}
# Move down, in the same column, until we leave whitespace
while( down() && in_whitespace() ){
}
}
# determine whether the cursor is in whitespace
global function in_whitespace()
{
return and( buffer_flags, BUFFER_IN_VIRTUAL_SPACE ) \
|| ( read_buffer(1) !~ /[^ \t]/ )
}
# Scroll to the right or left 1 page, while trying to keep the cursor
# in the same relative location within the window.
#
global function right_page() #PUBLIC #VOID
{
scroll_horizontal((window_text_width - linenumber_width), 1)
}
global function left_page() #PUBLIC #VOID
{
scroll_horizontal(-(window_text_width - linenumber_width), 1)
}
# Scroll to the right or left 1/2 page, while trying to keep the cursor
# in the same relative location within the window.
#
global function right_half_page() #PUBLIC #VOID
{
scroll_horizontal((window_text_width - linenumber_width) / 2, 1)
}
global function left_half_page() #PUBLIC #VOID
{
scroll_horizontal(-((window_text_width - linenumber_width) / 2), 1)
}
## next/previous line ala' VI: move to first non-blank character
function next_line( n ) #PUBLIC #VOID
{
if( !argcount())
n = 1
down( n )
skip_whitespace()
}
function prev_line( n ) #PUBLIC #VOID
{
if( !argcount())
n = 1
up( n )
skip_whitespace()
}
function skip_whitespace() #PUBLIC #VOID
{
local sflags = SEARCH_MAXIMAL_MATCH + SEARCH_FORWARD + SEARCH_REGEX
# next_word is similar, but fails on lines containing only whitespace
goto_bol()
search( "^[ \t]*\\c", sflags )
}
## rs_up(), rs_down(), rs_page_up(), rs_page_down()
# - vertical motion commands designed to operate in real space only.
# If the cursor is past the end of a line, or in virtual space past a
# tab, the cursor is moved left to the nearest "real" column, while the
# "virtual" column position is saved.
#
local vert_column # save the column we were in in the previous line
local vert_command # the previous vertical motion command
# move up one line and if in real space only, restore the column to
# what it was at the first consecutive up or down sequence of moves.
#
global function rs_up()
{
if ( prev_command != vert_command )
{
vert_column = current_column
up()
}
else
{
current_column = vert_column
up()
}
if ( and( buffer_flags, BUFFER_POSITION_IS_VIRTUAL ))
prev_char()
vert_command = current_command
}
# move up one line and if in real space only, restore the column to
# what it was at the first consecutive up or down sequence of moves.
#
global function rs_down()
{
if ( prev_command != vert_command )
{
vert_column = current_column
down()
}
else
{
down()
current_column = vert_column
}
if ( and( buffer_flags, BUFFER_POSITION_IS_VIRTUAL ))
prev_char()
vert_command = current_command
}
# move up one page and if in real space only, restore the column to
# what it was at the first consecutive up or down sequence of moves.
#
global function rs_page_up()
{
if ( prev_command != vert_command )
{
vert_column = current_column
page_up()
}
else
{
page_up()
current_column = vert_column
}
if ( and( buffer_flags, BUFFER_POSITION_IS_VIRTUAL ))
prev_char()
vert_command = current_command
}
# move up one page and if in real space only, restore the column to
# what it was at the first consecutive up or down sequence of moves.
#
global function rs_page_down()
{
if ( prev_command != vert_command )
{
vert_column = current_column
page_down()
}
else
{
page_down()
current_column = vert_column
}
if ( and( buffer_flags, BUFFER_POSITION_IS_VIRTUAL ))
prev_char()
vert_command = current_command
}
## keypad_motion()
#
# perform default cursor motion actions given the keycode for a keypad key
#
global function keypad_motion( keyCode )
{
if (keyCode == KEYCODE_UP || keyCode == KEYCODE_NUM_UP)
current_line--
else if (keyCode == KEYCODE_NUM_DOWN || keyCode == KEYCODE_DOWN)
current_line++
else if (keyCode == KEYCODE_NUM_LEFT || keyCode == KEYCODE_LEFT)
current_column--
else if (keyCode == KEYCODE_NUM_RIGHT || keyCode == KEYCODE_RIGHT)
current_column++
else if (keyCode == KEYCODE_NUM_HOME || keyCode == KEYCODE_HOME)
goto_bol()
else if (keyCode == KEYCODE_NUM_END || keyCode == KEYCODE_END)
goto_eol()
else if (keyCode == KEYCODE_NUM_PAGEUP || keyCode == KEYCODE_PAGEUP)
page_up()
else if (keyCode == KEYCODE_NUM_PAGEDOWN || keyCode == KEYCODE_PAGEDOWN)
page_down()
else if (keyCode == KEYCODE_CTRL_NUM_HOME || keyCode == KEYCODE_CTRL_NUM_HOME)
goto_window_top()
else if (keyCode == KEYCODE_CTRL_NUM_END || keyCode == KEYCODE_CTRL_END)
goto_window_bottom()
else if (keyCode == KEYCODE_CENTER )
center_cursor()
# else if (keyCode == KEYCODE_LEFT_PRESS )
# menu_mouse_key()
# else if (keyCode == KEYCODE_RIGHT_PRESS )
# {} # do nothing
else
return 0
return 1
}