home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
AUTOSAVE.PEL
< prev
next >
Wrap
Text File
|
1995-02-10
|
6KB
|
203 lines
# $Header: P:\source\wmacros\autosave.pev 1.10 10 Feb 1995 12:30:28 PFHJXM0 $
##############################################################################
#
# 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: autosave.pel $: Support for automatically saving buffers
global autosave_time = 15 # every 15 seconds #PUBLIC #INT
global autosave_force_time = 0 # number of seconds before forcing an autosave
local autosave_on = FALSE # initially no autosave
local autosave_array
local accumulative_force_time # accumulative time since last forced autosave
local accumulative_save_time # accumulative time since last autosave
local autosave_files_id
local autosave_exit_id
local autosave_kbd_id
local AUTOSAVE_EXT_CHAR = "!" # extension character for autosave files
## autosave_active()
#
# returns a true value if autosave is activated, otherwise a false value
#
global function autosave_active()
{
return( autosave_on )
}
## autosave()
#
# Invoke or toggle autosaving.
# atime (if specified) is the number of seconds between autosaves
# ftime (if specified) is the number of seconds between forced saves
#
# If atime is not specified, autosave_time is used.
#
global function autosave( atime, ftime )
{
local prev_autosave = autosave_on;
#
# determine new setting
#
if( argcount() < 1 )
autosave_on = !autosave_on
else
{
if ( (autosave_on = 0+atime) )
autosave_time = autosave_on
}
accumulative_save_time = 0
accumulative_force_time = 0;
if ( autosave_on )
{
idle_threshold = 1; # always set to 1 and we'll figure
# out later whether autosave_time
# has been exceeded
if (argcount() == 2)
autosave_force_time = 0+ftime;
if (!prev_autosave)
{
autosave_files_id = function_id( "autosave_files" );
autosave_exit_id = function_id( "autosave_exit" );
autosave_kbd_id = function_id( "autosave_kbd_hit" );
attach_event_handler( EVENT.IDLE_THRESHOLD, autosave_files_id )
attach_event_handler( EVENT.EXIT_EDITOR, autosave_exit_id )
attach_event_handler( EVENT.KEYPRESS, autosave_kbd_id )
}
message( "Autosave is on." )
}
else
{
if (prev_autosave)
{
delete_event( EVENT.IDLE_THRESHOLD, autosave_files_id)
delete_event( EVENT.KEYPRESS, autosave_kbd_id)
}
message( "Autosave is off." )
}
}
#
# autosave_files()
#
# write all of the modified buffers to a new ".__!" file.
#
global function autosave_files()
{
local old_curnt_buffer = current_buffer
local asv_name
local fname;
local forcesave = 0;
local diff;
accumulative_save_time += 1;
accumulative_force_time += 1;
if (autosave_force_time && (accumulative_force_time >= autosave_force_time))
{
forcesave = 1;
accumulative_force_time = 0;
}
else if (accumulative_save_time < autosave_time)
{
return;
}
accumulative_save_time = 0;
do {
if (!(and(buffer_flags, BUFFER_SYSTEM)))
{
#
# see if the buffer has changed
#
if ( and( buffer_flags, BUFFER_AUTOSAVE_MODIFIED) )
{
if (buffer_filename)
{
asv_name = fname = buffer_filename;
asv_name = create_semaphore_fname( asv_name, AUTOSAVE_EXT_CHAR );
if (asv_name in autosave_array)
# delete the file first so no backups
# will be made
unlink( asv_name )
else
# new filename entry
autosave_array[ asv_name ] = asv_name;
# clear the autosave bit so we will know next time
# whether any more changes have occurred
buffer_flags = and(buffer_flags, not(BUFFER_AUTOSAVE_MODIFIED))
message( "Autosaving '" fname "'." );
write_buffer( asv_name )
#message( "'"fname"' saved." )
message( "Temp file '"asv_name"' autosaved." )
}
}
}
next_buffer( "", 1, 1) # must include system buffers in case we started in one
} while (old_curnt_buffer != current_buffer)
current_buffer = old_curnt_buffer;
}
function autosave_exit()
{
local i;
if ( !really_close )
return 0
for (i in autosave_array)
{
unlink( autosave_array[ i ] ); # delete the file
delete( autosave_array[ i ] ); # delete the array element
}
}
function autosave_kbd_hit()
{
accumulative_save_time = 0;
}
function autosave_settings( settings_index, settings_data )
{
local new_array;
if ( autosave_active() )
settings_data[ settings_index++ ] = sprintf( "autosave %d\n", autosave_time )
new_array.array = settings_data
new_array.index = settings_index
return new_array
}