Hooking into Open and Save

Get help with the installation and running of the Zeus IDE. Please do not post bug reports or feature requests here. When in doubt post your question here.
Post Reply
pwdiener
Posts: 134
Joined: Wed Jul 11, 2007 3:45 pm

Hooking into Open and Save

Post by pwdiener »

I'm looking for a way to hook in to the File Open and File Save functions. I've a program file that is generated by a tool, and then can be modified with an editor. The problem is that some of the code that is generated is simple program code, but it needs to be entered in the tool and is just copied in to the generated program file. This causes confusion and issues when the copied code is editted with Zeus. When the program file is re-generated, the changes to the copied portion are gone.

I've written a couple macros that can go get the copied code and put it back in the proper place so that it's there for re-generation, so part of the work is done.

What I'd like to do is to hook in to File Open to detect this particular kind of file and do the Get function, then hook in to File Save to put the (potentially modified) copied code section back. This would allow me to edit the program much more seamlessly that I can currently.

I could attach the Save to Ctrl-S for instance, but I've no idea if that would work if I used File/Save from the menu or if the file was saved automatically before a compile, etc.

Any ideas? Obviously I could just remember to execute the macros, but not having to remember sure would be nice.

Bill
JackR
Posts: 61
Joined: Fri Jun 16, 2006 8:50 pm

Post by JackR »

Any chance putting the generated code into an include file solves your problem?

Jack
pwdiener
Posts: 134
Joined: Wed Jul 11, 2007 3:45 pm

Post by pwdiener »

Unfortunately not. The laguage is COBOL, and the generation step actually merges generated code with the rest of the code and presents it as one source file. That's actually kind of desirable, since the generated code isn't separately compile-able, and it's quite common to have to edit both parts to resolve compilation errors. Also COBOL's include facilities are somewhat primitive.

I may just have to resign myself to the occassional memory lapse and hope it doesn't cost me too much when it happens.

Oh, well...
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Any ideas? Obviously I could just remember to execute the macros, but not having to remember sure would be nice.
At one time there where plans to add macro triggers to Zeus but these where never implemented :(

These triggers would be Zeus macros that provided they existed, would be run before/after specific Zeus events like File Open, File Save, File Close, Zeus Startup, Zeus Exit etc.

Would something like this be what you are looking for and if so which events would you need :?:

Cheers Jussi
pwdiener
Posts: 134
Joined: Wed Jul 11, 2007 3:45 pm

Post by pwdiener »

That would be perfect. File Open and File Save would be what I need to accomplish what I'd like to do.

Bill
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Bill,

The latest patch found here:

http://www.zeusedit.com/forum/viewtopic.php?t=1790

allows you to add macro hooks for the following events:

Code: Select all

[Triggers]
FileOpenPrefix=
FileOpenPostfix=
FileClosePrefix=
FileClosePostfix=
FileCloseAllPrefix=
FileCloseAllPostfix=
FileSavePrefix=
FileSavePostfix=
(1) These settings can be found in the zeus.ini file.

(2) The prefix hooks are called prior top the event and the postfix hooks are called after the event.

(3) The macros take zero or one argument as shown in the table below:

Code: Select all

Trigger              Argument
======================================
FileSavePrefix       Document Name
FileSavePostfix      Document Name

FileOpenPrefix       Document Name
FileOpenPostfix      Document Name

FileClosePrefix      Document Name
FileClosePostfix     None

FileCloseAllPrefix   None
FileCloseAllPostfix  None
(4) Here is an example of an open postfix Lua trigger macro:

Code: Select all

function key_macro()
    message_box(0, "This is open postfix macro!" .. "\n\nArguments: " .. argv(0), "Zeus Trigger Event")
end

key_macro() -- run the macro
Cheers Jussi
pwdiener
Posts: 134
Joined: Wed Jul 11, 2007 3:45 pm

Post by pwdiener »

Awesome! I'll give them a try tomorrow! Thanks much!

Bill
pwdiener
Posts: 134
Joined: Wed Jul 11, 2007 3:45 pm

Post by pwdiener »

Jussi,

I'm having trouble getting these to work. I have save.lua defined as:

-- save testing
function key_macro()
    message_box(0, "This is save postfix macro!" .. "\n\nArguments: " .. argv(0), "Zeus Trigger Event")
end

key_macro() -- run the macro

and saved in zScript.

I edit zeus.ini and change FileSavePostfix= to FileSavePostfix=save.lua

I then go to another open file and save it, expecting to see the message box. What I get is a status message saying the write was successful. Am I missing something?

Zeus also deletes the setting for FileSavePostfix, setting it back to the null string.

Bill
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Make sure you are using Zeus 3.96o. Also try coping your test script name into all the available trigger locations of the ini file.

I thought I tested all the options, but I might have missed something :?

Cheers Jussi
pwdiener
Posts: 134
Joined: Wed Jul 11, 2007 3:45 pm

Post by pwdiener »

I don't know what was wrong yesterday, but it's working now. I've got dummy macros plugged in for all the event except the 2 I'm using, so maybe it just likes to have all the names filled in.
pwdiener
Posts: 134
Joined: Wed Jul 11, 2007 3:45 pm

Post by pwdiener »

Jussi,

Whoops - spoke a little too soon. The macros are firing OK (per last post), but when I tried to compile a file that needed to be saved, I got an internal error. My live macro is hooked in to SavePostfix, and displays a status bar message on completion. I believe I saw it's message before the internal error popped up. I'm sending the log and dmp files to you via E-Mail. This appears to be repeatable, at least for me - it's done it 3 times in a row.

When I compile the same file without it's needing to be saved, it appears to go through the macro repeatedly until the compiler output window is displayed. I counted at least 10 times that I observed the completion message plus the file name tabs flashing while the macro did it's thing until the error list came up.

Bill
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Bill,
I don't know what was wrong yesterday, but it's working now.

Remember to not edit the zeus.ini using Zeus, because the INI file gets re-written on close, so your changes will be lost ;)
This appears to be repeatable, at least for me.
I tried to replicate this but could not :(

What I did was define a simple message box save prefix macro and turn it on in the ini file. Setup the compile options to do a save all before each compile and then ran the compile several times without error :(

But I did find out that the files where being saved twice for each compile so one minor bug has been fixed :)
it's done it 3 times in a row.
Once you get an internal error, Zeus will be in an unknown state, which means you generally get another internal error shortly after.

As a rule you should always restart Zeus after any internal error.

Cheers Jussi
pwdiener
Posts: 134
Joined: Wed Jul 11, 2007 3:45 pm

Post by pwdiener »

I was wondering about that - the first couple times I changed I used Zeus but then went to Notepad. Maybe I just didn't hit it right the day before.

On the internal error, I did shutdown Zeus and restart between each attempt, and it did it 3 times in a row. I'm not sure if it's my save macro or just save macros in general combined with my compile. I run a CMD file to do a compile - I've never had any trouble with it so I have no real reason to suspect that as part of the problem.

My save macro finds a block of code in the file being saved, copies it to the clipboard, then opens another file, finds the equivalent code in it, pastes the (possibly revised) code in its place, saves and closes the second file, and goes back to the file being saved. It occurs to me that the save in a save postfix macro could be a problem - any ideas on how I might get away from that and still accomplish what I want to do?

Bill
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

It occurs to me that the save in a save postfix macro could be a problem - any ideas on how I might get away from that and still accomplish what I want to do?
This is one of the problems with these types of hooks. They introduce new program flows that aren't always obvious, offer up chances for new race conditions and provide yet another way for things to go wrong :(

I will put a lock on the trigger so that a trigger can’t be called from a trigger, which will at least eliminate the chance of infinite loops.

See my reply to your e-mail for suggestions on how I think your save macro should be restructured ;)

Cheers Jussi
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

The tigger lock was added to the latest version.

Cheers Jussi
Post Reply