Hey folks,
I'm trying to work with named paste buffers in a callback to manipulate content before it is output to the current doc.
I'm finding that Arbortext is getting confused on which is the current doc depending upon what actions I'm performing.
For instance, if I do oid_delete(some_oid), it removes the oid from the buffer. However, if I do a change_tag, it wants to act upon the document currently open in the window. I thought this was perhaps an issue with commands versus functions, but goto_oid() also works in the document window rather than the buffer.
Here is a snippet of my code where I am setting things up with the named buffer.
buffer_create("_temp_");
set paste = "_temp_";
local bufstr;
buffer_clipboard_contents(bufstr);
insert_buffer(bufstr,1,"_temp_");
local pdoc = buffer_doc("_temp_");
local root = oid_first(pdoc);
The oid_first() function works OK. This would lead me to think that Arbortext has picked up on the named buffer as the current doc, but as I described, it gets flakey. I've tried a current_doc(pdoc), but no luck.
Any ideas are much appreciated!
Solved! Go to Solution.
Hi Jeff--
In a case like this, it pays to be explicit about the current doc.After you create your named buffer, add this:
local buffdoc = buffer_doc("_temp_");
local savedoc = current_doc(buffdoc);
Now the buffer document has been explicitly set as the current document. When you are done monkeying around with the buffer contents and want to switch back to the main document, use this:
current_doc(savedoc);
This idiom is used extensively in the Arbortext core ACL code.
--Clay
Hi Jeff--
In a case like this, it pays to be explicit about the current doc.After you create your named buffer, add this:
local buffdoc = buffer_doc("_temp_");
local savedoc = current_doc(buffdoc);
Now the buffer document has been explicitly set as the current document. When you are done monkeying around with the buffer contents and want to switch back to the main document, use this:
current_doc(savedoc);
This idiom is used extensively in the Arbortext core ACL code.
--Clay
BTW, the reason your oid_first() call works the way you expect is because you are explicitly telling it to act on the buffer document by passing the pdoc parameter. That method should also work for many other function calls, as long as they provide an optional parameter for specifying the doc ID. But some functions, and most commands, don't provide such a parameter, so it's safest to use the current_doc() function to set the current document.
--C
Hi Clay,
I tried something similar with current_doc but it still wanted to work with the doc window document.
In your sample, wouldn't you want local savedoc = current_doc(buffdoc); to the original document id rather than the buffer doc id?
-Jeff
Hi Jeff--
Taking things backwards, when you call current_doc() with a doc ID parameter, it does two things:
So, the code as written will do exactly what you suggest. Seriously, this idiom appears *all over* the base ACL code. Grep for "savedoc" in $ARBORTEXT/packages/* and you'll get zillions of hits.
For the first thing, I'm not sure what might have been going wrong there. (But maybe your second question indicates an incorrect understanding of how current_doc() works, such that you weren't actually setting it to the buffer document when you thought you were?) A few things to consider:
Hopefully something here will be helpful enough to get you over the hump.
--Clay
Thanks, Clay. I wasn't aware of the 2nd point where current_doc returns doc ID of the previous doc. I thought it returned the doc id of the doc that is being set.
Much thanks!