Skip to main content
1-Visitor
July 20, 2016
Solved

trouble with named paste buffers and current_doc

  • July 20, 2016
  • 1 reply
  • 1952 views

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!

Best answer by ClayHelberg

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

1 reply

18-Opal
July 20, 2016

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

18-Opal
July 20, 2016

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