diff scripts/plot/ishold.m @ 12085:c5ab026894ef release-3-2-x

correctly toggle hold state
author John W. Eaton <jwe@octave.org>
date Mon, 07 Sep 2009 08:01:41 +0200
parents eb63fbe60fab
children 95c3e38098bf
line wrap: on
line diff
--- a/scripts/plot/ishold.m	Fri Sep 04 06:59:44 2009 +0200
+++ b/scripts/plot/ishold.m	Mon Sep 07 08:01:41 2009 +0200
@@ -1,4 +1,4 @@
-## Copyright (C) 2005, 2006, 2007, 2008 John W. Eaton
+## Copyright (C) 2005, 2006, 2007, 2008 2009 John W. Eaton
 ##
 ## This file is part of Octave.
 ##
@@ -22,12 +22,34 @@
 ## false if the plot device will be cleared before drawing the next line.
 ## @end deftypefn
 
-function retval = ishold ()
+function retval = ishold (h)
 
   if (nargin == 0)
-    retval = strcmpi (get (gca (), "nextplot"), "add");
+    ax = gca ();
+    fig = gcf ();
+  elseif (nargin == 1)
+    if (ishandle (h))
+      if (isfigure (h))
+	ax = get (h, "currentaxes");
+	if (isempty (ax))
+	  ax = __go_axes__ (h);
+	  set (h, "currentaxes", ax);
+	endif
+	fig = h;
+      elseif (strcmpi (get (h, "type"), "axes"))
+	ax = h;
+	fig = get (h, "parent");
+      else
+	error ("hold: expecting argument to be axes or figure graphics handle");
+      endif
+    else
+      error ("hold: expecting argument to be axes or figure graphics handle");
+    endif
   else
     print_usage ();
   endif
 
+  retval = (strcmpi (get (fig, "nextplot"), "add")
+	    && strcmpi (get (ax, "nextplot"), "add"));
+
 endfunction