changeset 13126:e39c76eb5fbd

Merge in Daniel's changes
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Sun, 11 Sep 2011 12:34:24 -0500
parents 34a49d076155 (current diff) 2ea1658ad049 (diff)
children 155d7a5e70f5
files
diffstat 27 files changed, 123 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/help/__makeinfo__.m
+++ b/scripts/help/__makeinfo__.m
@@ -17,8 +17,8 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {[@var{retval}, @var{status}] =} __makeinfo__ (@var{text})
-## @deftypefnx {Function File} {[@var{retval}, @var{status}] =} __makeinfo__ (@var{text}, @var{output_type})
+## @deftypefn  {Function File} {[@var{retval}, @var{status}] =} __makeinfo__ (@var{text}, @var{output_type})
+## @deftypefnx {Function File} {[@var{retval}, @var{status}] =} __makeinfo__ (@var{text}, @var{output_type}, @var{see_also})
 ## Undocumented internal function.
 ## @end deftypefn
 
@@ -33,6 +33,13 @@
 ## @t{"plain text"}. If @var{output_type} is @t{"texinfo"}, the @t{@@seealso}
 ## macro is expanded, but otherwise the text is unaltered.
 ##
+## If the optional argument @var{see_also} is present, it is used to expand the
+## Octave specific @t{@@seealso} macro. This argument must be a function handle,
+## that accepts a cell array of strings as input argument (each elements of the
+## array corresponds to the arguments to the @t{@@seealso} macro), and return
+## the expanded string. If this argument is not given, the @t{@@seealso} macro
+## will be expanded to the text
+##
 ## @example
 ## See also: arg1, arg2@, ...
 ## @end example
@@ -50,31 +57,49 @@
 ## The optional output argument @var{status} contains the exit status of the
 ## @code{makeinfo} program as returned by @code{system}.
 
-function [retval, status] = __makeinfo__ (text, output_type = "plain text", see_also = [])
+function [retval, status] = __makeinfo__ (text, output_type = "plain text", fsee_also)
 
   ## Check input
-  if (nargin < 1 || nargin > 2)
+  if (nargin < 1 || nargin > 3)
     print_usage ();
   endif
 
-  if (!ischar (text))
+  if (! ischar (text))
     error ("__makeinfo__: first input argument must be a string");
   endif
 
-  if (!ischar (output_type))
+  if (! ischar (output_type))
     error ("__makeinfo__: second input argument must be a string");
   endif
 
+  if (nargin < 3)  
+    if (strcmpi (output_type, "plain text"))
+      fsee_also = @(T) strcat ...
+          ("\nSee also:", sprintf (" %s,", T{:})(1:end-1), "\n");
+    else    
+      fsee_also = @(T) strcat ...
+          ("\nSee also:", sprintf (" @ref{%s},", T{:})(1:end-1), "\n");
+    endif
+  endif
+
+  if (! isa (fsee_also, "function_handle"))
+    error (["__makeinfo__: third input argument must ", ...
+            "be the empty matrix, or a function handle"]);
+  endif
+  
+
   ## It seems like makeinfo sometimes gets angry if the first character
   ## on a line is a space, so we remove these.
-  text = strrep (text, "\n ", "\n");
+  text = strrep (text, "\n ", "\n"); 
 
   ## Handle @seealso macro
-  if (strcmpi (output_type, "plain text")) 
-    text = regexprep (text, '@seealso *\{([^}]*)\}', "\nSee also: $1.\n\n");
-  else
-    text = regexprep (text, '@seealso *\{([^}]*)\}', "\nSee also: @ref{$1}.\n\n");
-  endif
+  see_also_pat = '@seealso *\{([^}]*)\}';
+  args = regexp (text, see_also_pat, 'tokens');
+  for ii = 1:numel (args)
+    expanded = fsee_also (strtrim (strsplit (args{ii}{:}, ',', true)));
+    text = regexprep (text, see_also_pat, expanded, 'once');
+  endfor
+
   ## Handle @nospell macro
   text = regexprep (text, '@nospell *\{([^}]*)\}', "$1");
 
@@ -90,7 +115,7 @@
   unwind_protect
     ## Write Texinfo to tmp file
     template = "octave-help-XXXXXX";
-    [fid, name, msg] = mkstemp (fullfile (P_tmpdir, template), true);
+    [fid, name] = mkstemp (fullfile (P_tmpdir, template), true);
     if (fid < 0)
       error ("__makeinfo__: could not create temporary file");
     endif
@@ -100,11 +125,11 @@
     ## Take action depending on output type
     switch (lower (output_type))
       case "plain text"
-         cmd = sprintf ("%s --no-headers --no-warn --force --no-validate %s",
-                        makeinfo_program (), name);
+        cmd = sprintf ("%s --no-headers --no-warn --force --no-validate %s",
+                       makeinfo_program (), name);
       case "html"
-         cmd = sprintf ("%s --no-headers --html --no-warn --no-validate --force %s",
-                        makeinfo_program (), name);
+        cmd = sprintf ("%s --no-headers --html --no-warn --no-validate --force %s",
+                       makeinfo_program (), name);
       otherwise
         error ("__makeinfo__: unsupported output type: '%s'", output_type);
     endswitch
--- a/scripts/plot/allchild.m
+++ b/scripts/plot/allchild.m
@@ -50,7 +50,7 @@
 endfunction
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   l = line;
 %!   assert(get(allchild(hf),'type'),{'axes'; 'uimenu'; 'uimenu'; 'uimenu'})
--- a/scripts/plot/ancestor.m
+++ b/scripts/plot/ancestor.m
@@ -76,7 +76,7 @@
 endfunction
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   l = line;
 %!   assert (ancestor (l, "axes"), gca);
--- a/scripts/plot/cla.m
+++ b/scripts/plot/cla.m
@@ -90,7 +90,7 @@
 endfunction
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect 
 %!   plot (1:10)
 %!   cla ()
--- a/scripts/plot/clf.m
+++ b/scripts/plot/clf.m
@@ -77,7 +77,7 @@
 endfunction
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   l = line;
 %!   assert (!isempty (get (gcf, "children")));
@@ -86,7 +86,7 @@
 %! end_unwind_protect
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   clf;
 %!   assert (isempty (get (gcf, "children")));
--- a/scripts/plot/close.m
+++ b/scripts/plot/close.m
@@ -79,3 +79,15 @@
   endwhile
 
 endfunction
+
+%!test
+%! hf = figure ("visible", "off");
+%! unwind_protect
+%!   close (hf);
+%!   objs = findobj ("type", "figure");
+%!   assert (isempty (intersect (objs, hf)));
+%! unwind_protect_cleanup
+%!   if (isfigure (hf))
+%!     close (hf);
+%!   endif
+%! end_unwind_protect
--- a/scripts/plot/findall.m
+++ b/scripts/plot/findall.m
@@ -44,7 +44,7 @@
 endfunction
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   h = findall (hf);
 %!   all_handles = {"uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "figure"};
--- a/scripts/plot/findobj.m
+++ b/scripts/plot/findobj.m
@@ -244,14 +244,13 @@
 endfunction
 
 %!test
-%! fign = 1232;
-%! hf = figure (fign, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   l = line;
 %!   obj = findobj (hf, "type", "line");
 %!   assert (l, obj);
 %!   assert (gca, findobj (hf, "type", "axes"));
-%!   assert (fign, findobj (hf, "type", "figure"));
+%!   assert (hf, findobj (hf, "type", "figure"));
 %!   assert (isempty (findobj (hf, "type", "xyzxyz")));
 %! unwind_protect_cleanup
 %!   close (hf);
--- a/scripts/plot/gca.m
+++ b/scripts/plot/gca.m
@@ -49,3 +49,12 @@
   endif
 
 endfunction
+
+%!test
+%! hf = figure ("visible", "off");
+%! ax = axes;
+%! unwind_protect  
+%!   assert (gca, ax);
+%! unwind_protect_cleanup
+%!   close (hf);
+%! end_unwind_protect
--- a/scripts/plot/gcbf.m
+++ b/scripts/plot/gcbf.m
@@ -31,3 +31,6 @@
   [dummy, fig] = gcbo ();
 
 endfunction
+
+%!test
+%! assert (isempty (gcbf ));
--- a/scripts/plot/gcbo.m
+++ b/scripts/plot/gcbo.m
@@ -41,3 +41,6 @@
   endif
 
 endfunction
+
+%!test
+%! assert (isempty (gcbo ));
--- a/scripts/plot/gcf.m
+++ b/scripts/plot/gcf.m
@@ -55,9 +55,9 @@
 endfunction
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
-%!   assert (gcf, 1232);
+%!   assert (gcf, hf);
 %! unwind_protect_cleanup
 %!   close (hf);
 %! end_unwind_protect
--- a/scripts/plot/ginput.m
+++ b/scripts/plot/ginput.m
@@ -42,3 +42,7 @@
   endif
 
 endfunction
+
+## Remove from test statistics.  No real tests possible.
+%!test
+%! assert (1);
--- a/scripts/plot/gtext.m
+++ b/scripts/plot/gtext.m
@@ -51,3 +51,6 @@
 
 endfunction
 
+## Remove from test statistics.  No real tests possible.
+%!test
+%! assert (1);
--- a/scripts/plot/hggroup.m
+++ b/scripts/plot/hggroup.m
@@ -41,3 +41,13 @@
   endif
 
 endfunction
+
+%!test
+%! hf = figure ("visible", "off");
+%! unwind_protect  
+%!   h = hggroup;
+%!   assert (findobj (hf, "type", "hggroup"), h);
+%!   assert (get (h, "type"), "hggroup");
+%! unwind_protect_cleanup
+%!   close (hf);
+%! end_unwind_protect
--- a/scripts/plot/isfigure.m
+++ b/scripts/plot/isfigure.m
@@ -34,3 +34,12 @@
   endif
 
 endfunction
+
+%!test
+%! hf = figure ("visible", "off");
+%! unwind_protect  
+%!   assert (isfigure (hf));
+%!   assert (!isfigure (-hf));
+%! unwind_protect_cleanup
+%!   close (hf);
+%! end_unwind_protect
--- a/scripts/plot/line.m
+++ b/scripts/plot/line.m
@@ -44,7 +44,7 @@
 endfunction
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   h = line;
 %!   assert (findobj (hf, "type", "line"), h);
--- a/scripts/plot/loglog.m
+++ b/scripts/plot/loglog.m
@@ -82,7 +82,7 @@
 %! xlabel ('loglog (a, abs (b))')
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   a = logspace (-5, 1, 10);
 %!   b = logspace (-5, 1, 10);
@@ -94,7 +94,7 @@
 %! end_unwind_protect
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   a = logspace (-5, 1, 10);
 %!   b =-logspace (-5, 1, 10);
--- a/scripts/plot/patch.m
+++ b/scripts/plot/patch.m
@@ -153,7 +153,7 @@
 %! view (-37.5, 30)
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   h = patch;
 %!   assert (findobj (hf, "type", "patch"), h);
--- a/scripts/plot/semilogx.m
+++ b/scripts/plot/semilogx.m
@@ -80,7 +80,7 @@
 %! xlabel ('semilogx (a, abs (b))')
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   a = logspace (-5, 1, 10);
 %!   b = logspace (-5, 1, 10);
@@ -92,7 +92,7 @@
 %! end_unwind_protect
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   a = logspace (-5, 1, 10);
 %!   b =-logspace (-5, 1, 10);
@@ -102,5 +102,3 @@
 %! unwind_protect_cleanup
 %! close (hf);
 %! end_unwind_protect
-
-
--- a/scripts/plot/semilogy.m
+++ b/scripts/plot/semilogy.m
@@ -81,7 +81,7 @@
 %! xlabel ('semilogy (a, abs (b))')
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   a = logspace (-5, 1, 10);
 %!   b = logspace (-5, 1, 10);
@@ -93,7 +93,7 @@
 %! end_unwind_protect
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   a = logspace (-5, 1, 10);
 %!   b =-logspace (-5, 1, 10);
--- a/scripts/plot/surface.m
+++ b/scripts/plot/surface.m
@@ -164,7 +164,7 @@
 ## surf.m, surfc.m, surfl.m, and pcolor.m
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   h = surface;
 %!   assert (findobj (hf, "type", "surface"), h);
--- a/scripts/plot/view.m
+++ b/scripts/plot/view.m
@@ -95,8 +95,7 @@
 endfunction
 
 %!test
-%! fign = 1232;
-%! hf = figure (fign, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   plot3 ([0,1], [0,1], [0,1]);
 %!   [az, el] = view;
@@ -112,8 +111,7 @@
 %! end_unwind_protect
 
 %!test
-%! fign = 1232;
-%! hf = figure (fign, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   line;
 %!   [az, el] = view;
--- a/scripts/plot/whitebg.m
+++ b/scripts/plot/whitebg.m
@@ -147,7 +147,7 @@
 %!test
 %! dac = get (0, "defaultaxescolor");
 %! dfc = get (0, "defaultfigurecolor");
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   l = line;
 %!   assert (get (hf, "color"), dfc);
--- a/scripts/plot/xlim.m
+++ b/scripts/plot/xlim.m
@@ -75,7 +75,7 @@
 
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   plot3 ([0,1], [0,1], [0,1]);
 %!   xlim ([0, 1.1]);
@@ -86,7 +86,7 @@
 %! end_unwind_protect
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   h = plot3 ([0,1.1], [0,1], [0, 1]);
 %!   assert (get (gca, "xlim"), [0, 1.4], eps);
--- a/scripts/plot/ylim.m
+++ b/scripts/plot/ylim.m
@@ -74,7 +74,7 @@
 %! assert (ylim ("mode"), "auto");
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   limy = [0, 1.1];
 %!   plot3 ([0,1], [0,1], [0,1]);
@@ -86,7 +86,7 @@
 %! end_unwind_protect
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   plot3 ([0,1], [0,1.1], [0, 1]);
 %!   assert (get (gca, "ylim"), [0, 1.4], eps);
--- a/scripts/plot/zlim.m
+++ b/scripts/plot/zlim.m
@@ -74,7 +74,7 @@
 %! assert (zlim ("mode"), "auto");
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   limz = [0, 1.1];
 %!   plot3 ([0,1], [0,1], [0,1]);
@@ -86,7 +86,7 @@
 %! end_unwind_protect
 
 %!test
-%! hf = figure (1232, "visible", "off");
+%! hf = figure ("visible", "off");
 %! unwind_protect  
 %!   plot3 ([0,1], [0,1], [0, 1.1]);
 %!   assert (get (gca, "zlim"), [0, 1.4], eps);