reopen stream-name indexer? open-modifier?


The reopen action is used to open an existing stream object that was previously closed using the close action. (The exception to this is built-in streams like #main-output, which are dynamically reopenable.) Unlike with the open action, the contents of the attached object are not erased when it is reopened.

For example, the first output action in the following process rule will output "of our discontent", and the second output action will output "Now is the winter of our discontent":

     local stream foo
     local stream bar
     open foo as buffer
     put foo "Now is the winter "
     close foo
     open bar as buffer
     put bar "Now is the winter "
     close bar
     open foo as buffer
     put foo "of our discontent"
     close foo
     reopen bar
     put bar "of our discontent"
     close bar
     output foo || "%n"
     output bar || "%n"

If the reopen new form is used, a new item is added to the specified stream shelf. The restrictions on this form of thereopen action are the same as those of the set new action. In this case, the attachment must be specified.

All of the open modifiers available for the open action are available for reopen except append, text-mode, binary-mode, buffered, and unbuffered.

When reopening a stream:

  • If the stream was already open, it remains open.
  • If the stream is closed, then whatever attachment it had when it was closed is reused.
  • If the stream was not attached, OmniMark reports an error.
  • The element content modifiers are processed in two ways. If they are specified, the specified modifiers are applied to the stream; if they are not specified, the format modifiers that previously applied to the stream are retained. To turn off all format modifiers, use the empty string: reopen s with "".
  • The break-width and binary modifiers are treated in two ways. If the modifier is specified, then it is applied to the stream; if the modifier is not specified, the default value is used. The previous settings are not retained.

Previous versions of OmniMark allowed an attachment to be specified when reopening a stream:

       local stream s
       reopen s as file "foo.txt"

This had the effect of opening the attachment in append mode. This form of the reopen action is deprecated and should no longer be used. In its place, the append modifier should be used with the open action:

         local stream s
         open s as file "foo.txt" with append