Mercurial > hg > octave-lyh
diff src/ov.cc @ 4005:fc000ebb19df
[project @ 2002-07-25 21:01:16 by jwe]
author | jwe |
---|---|
date | Thu, 25 Jul 2002 21:01:16 +0000 |
parents | 95663a3a2682 |
children | a8621d87fbf5 |
line wrap: on
line diff
--- a/src/ov.cc +++ b/src/ov.cc @@ -59,6 +59,7 @@ #include "error.h" #include "gripes.h" #include "pager.h" +#include "parse.h" #include "pr-output.h" #include "utils.h" #include "variables.h" @@ -67,6 +68,10 @@ // make the grow_size large. DEFINE_OCTAVE_ALLOCATOR2(octave_value, 1024); +// If TRUE, turn off printing of results in functions (as if a +// semicolon has been appended to each statement). +static bool Vsilent_functions; + // If TRUE, allow assignments like // // octave> A(1) = 3; A(2) = 5 @@ -942,15 +947,19 @@ } void -octave_value::print_with_name (std::ostream& output_buf, const std::string& name, +octave_value::print_with_name (std::ostream& output_buf, + const std::string& name, bool print_padding) const { - bool pad_after = print_name_tag (output_buf, name); + if (! (evaluating_function_body && Vsilent_functions)) + { + bool pad_after = print_name_tag (output_buf, name); - print (output_buf); + print (output_buf); - if (print_padding && pad_after) - newline (output_buf); + if (print_padding && pad_after) + newline (output_buf); + } } static void @@ -1608,6 +1617,14 @@ } static int +silent_functions (void) +{ + Vsilent_functions = check_preference ("silent_functions"); + + return 0; +} + +static int struct_levels_to_print (void) { double val; @@ -1721,6 +1738,27 @@ control is returned to the top level. The default value is 1.\n\ @end defvr"); + DEFVAR (silent_functions, 0.0, silent_functions, + "-*- texinfo -*-\n\ +@defvr {Built-in Variable} silent_functions\n\ +If the value of @code{silent_functions} is nonzero, internal output\n\ +from a function is suppressed. Otherwise, the results of expressions\n\ +within a function body that are not terminated with a semicolon will\n\ +have their values printed. The default value is 0.\n\ +\n\ +For example, if the function\n\ +\n\ +@example\n\ +function f ()\n\ + 2 + 2\n\ +endfunction\n\ +@end example\n\ +\n\ +@noindent\n\ +is executed, Octave will either print @samp{ans = 4} or nothing\n\ +depending on the value of @code{silent_functions}.\n\ +@end defvr"); + DEFVAR (struct_levels_to_print, 2.0, struct_levels_to_print, "-*- texinfo -*-\n\ @defvr {Built-in Variable} struct_levels_to_print\n\