From: Sammy Mitchell
Stephane Gibier[SMTP:sgibier@hol.fr] wrote:
> I would like to implement the Auto-Save feature in TSE Pro 2.8. The
> idle time would be set in the ini file or something like that.
I have a simple macro (based on one by Jim Sewell) that I've been using =
with good success for a while. I am including it here. =20
I say simple because it does not check for out of disk space errors, =
won't handle filenames > 250 characters in length, and you have to =
change a few constants in the macro and recompile to configure it. But =
otherwise, it works for me!
Sammy Mitchell
SemWare Corp.
/************************************************************************=
**
A simple macro that saves changed files to: temp_dir + fn + save_ext
If you ever crash during a session, gather latest versions from your
tempdir.
tempdir is cleaned up upon normal program termination.
=
*************************************************************************=
*/
constant WAIT_TIME =3D 182 // about 10 seconds (18.2 is about 1 =
second)
string temp_dir[_MAXPATH_] =3D "c:\swappath\",
auto_save_ext[] =3D ".save"
integer idle_time, all_saved
string proc AutoSaveFn()
return (temp_dir + SplitPath(CurrFilename(), _NAME_|_EXT_) + =
auto_save_ext)
end
proc Idle()
integer id, i
if Query(IdleTime) < WAIT_TIME
return ()
endif
// See if we need to do anything
if Query(IdleTime) >=3D idle_time and all_saved
idle_time =3D Query(IdleTime)
return ()
endif
all_saved =3D FALSE
id =3D GetBufferId()
for i =3D 1 to NumFiles() + (BufferType() _NORMAL_)
if BufferType() =3D=3D _NORMAL_ and Length(CurrFilename()) and =
FileChanged()
SaveAs(AutoSaveFn(), _OVERWRITE_|_QUIET_)
endif
if KeyPressed()
break
endif
NextFile(_DONT_LOAD_)
endfor
GotoBufferId(id)
if i >=3D NumFiles()
all_saved =3D TRUE
endif
idle_time =3D Query(IdleTime)
end
proc KillAutosave()
EraseDiskFile(AutoSaveFn())
end
proc KillLotsOfAutosave()
integer i, id
id =3D GetBufferId()
for i =3D 1 to NumFiles() + (BufferType() _NORMAL_)
KillAutosave()
NextFile(_DONT_LOAD_)
endfor
GotoBufferId(id)
end
proc WhenPurged()
KillLotsOfAutosave()
end
proc WhenLoaded()
Hook(_IDLE_, Idle)
Hook(_NONEDIT_IDLE_, Idle)
Hook(_ON_FILE_SAVE_, KillAutosave)
Hook(_ON_FILE_QUIT_, KillAutosave)
Hook(_ON_ABANDON_EDITOR_, KillLotsOfAutosave)
end
---
---------------
* Origin: apana>>>>>fidonet [sawasdi.apana.org.au] (3:800/846.13)
|