[ChangeSet] print.m: support for figure handles
Ben Abbott
bpabbott at mac.com
Fri Feb 29 17:58:47 CST 2008
On Feb 29, 2008, at 5:24 PM, John W. Eaton wrote:
> On 29-Feb-2008, Ben Abbott wrote:
>
> | On Friday, February 29, 2008, at 10:40AM, "Søren Hauberg" <soren at hauberg.org
> > wrote:
> | >
> | >fre, 29 02 2008 kl. 07:05 -0800, skrev Ben Abbott:
> | >> I modified print.m to support a figure handle as an input.
> | >>
> | >> It is a trivial change, but permits printing as is often done
> (by me) in Matlab. For example,
> | >>
> | >> print (gcf, '-pdf', 'foo.pdf')
> | >>
> | >> Please consider the attached changeset.
> | >I don't know how matlab works, but wouldn't it make sense to do
> | >something like
> | >
> | >if (ishandle (arg))
> | > old_fig = gcf();
> | > figure (arg);
> | >endif
> | >
> | >...
> | >
> | >if (ishandle(arg))
> | > figure(old_fig);
> | >endif
> | >
> | >such that the current figure is still the current figure after
> the call
> | >to 'print' ?
> | >
> | >Søren
> | >
> |
> | Good point. Matlab respects that behavior as well.
> |
> | I've attached the correct changeset.
>
> When you want to make a temporary change to some global state like the
> current figure, you should use unwind_protect to prevent the change
> from sticking in case an error occurs or an interrupt arrives while
> the setting is in the changed state. For example
>
> old_fig = get (0, 'currentfigure');
> unwind_protect
> figure (arg);
> ...
> unwind_protect_cleanup
> if (ishandle (old_fig))
> figure (old_fig)
> endif
> end_unwind_protect
>
> jwe
ahhh-ha ... very cool!
I'll make the change!
The indent between unwind_protect and the cleanup will mean nearly all
lines will be included in the changeset. Is that ok?
Ben
More information about the Octave-maintainers
mailing list