cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

close hook/callback, goto_oid and pub caret PI placement

naglists
1-Newbie

close hook/callback, goto_oid and pub caret PI placement

Hi,
How do I capture an author's close of a file. I expected to be able to use a
close callback, but unless I'm missing something crazy-obvious, that
callback doesn't seem to exist. No close hook, either. Again, unless I'm
somehow tripping over my own feet. I found some references to the quit
callback but that captures when Editor is quit, not the document open in
Editor. Am I missing something?

This is related only because I am trying to solve the same problem prompting
the question above another way. I want to control the placement of the Caret?> processing instruction when a file is closed. I can control it on
save, however, I don't want to move the caret during an edit session. I have
tried to move the caret, save, and then return it to its original location,
but this seems to move the processing instruction even though
no new save is performed after that last move.

The code I'm using for this is:
local current_oid = oid_caret();
local current_pos = oid_caret_pos();
goto_oid(oid_root),'-2');
caret 1,0
save;
goto_oid(current_oid,current_pos);

If I comment the last line, the PI is placed near the top of the file as I
would expect. When the goto_oid process, however, it is moving the PI. What?
Why? Is this known (if undocumented) behavior?

--
Paul Nagai
2 REPLIES 2

Hi Paul-



Could the "destroy" doc callback be what you are looking for? According to
the help, "destroy is called whenever a document is unloaded from memory."
(Help 148.)



If that doesn't do it for you, you might have better luck using an event
listener via the AOM. Check out the DocumentClosed, DocumentUnload, and
DocumentSaving events-there are subtle differences among them, so you might
have to do some testing to determine which one is the right one for your
specific needs.



As for the Pub Caret PI, my understanding is that it shows up wherever the
caret currently is. So yes, calling goto_oid() would cause it to move. It's
not clear from your description if you are seeing the change in the saved
version of the document, i.e. the last goto_oid() is somehow moving the
caret before your save command is done executing. I can see how that would
be a problem-in that case, you might need to put some kind of delay in the
code to make sure the save finishes before you restore the caret to its
original position.



--Clay


Thanks, Clay. destroy is the one I needed. It should say that on the menu
... it would be so much more clear. File>Destroy!

I thought the Pub Caret would not be saved if the cursor moved *after* the
last save. Maybe that's true and I was still getting one more save than I
was expecting. In any case, I think I'll get where I'm going with destroy,
so I'm not probably going to pursue the pub caret subtleties at this point
...

Thanks again.

Announcements