diff --git a/libinterp/corefcn/variables.cc b/libinterp/corefcn/variables.cc --- a/libinterp/corefcn/variables.cc +++ b/libinterp/corefcn/variables.cc @@ -1957,7 +1957,7 @@ bind_ans (const octave_value& val, bool symbol_table::force_assign (ans, val); if (print) - val.print_with_name (octave_stdout, ans); + feval ("display", ovl (val, ans)); } } } diff --git a/libinterp/octave-value/ov-class.cc b/libinterp/octave-value/ov-class.cc --- a/libinterp/octave-value/ov-class.cc +++ b/libinterp/octave-value/ov-class.cc @@ -1016,31 +1016,9 @@ octave_class::print_name_tag (std::ostre void octave_class::print_with_name (std::ostream& os, const std::string& name, - bool) + bool print_padding) { - octave_value fcn = symbol_table::find_method ("display", class_name ()); - - if (fcn.is_defined ()) - { - octave_value_list args; - - count++; - args(0) = octave_value (this); - - string_vector arg_names (1); - - arg_names[0] = name; - - args.stash_name_tags (arg_names); - - feval (fcn.function_value (), args); - } - else - { - indent (os); - os << name << " = "; - newline (os); - } + octave_base_value::print_with_name (os, name, print_padding); } // Loading a class properly requires an exemplar map entry for success. diff --git a/libinterp/octave-value/ov-classdef.cc b/libinterp/octave-value/ov-classdef.cc --- a/libinterp/octave-value/ov-classdef.cc +++ b/libinterp/octave-value/ov-classdef.cc @@ -945,24 +945,6 @@ octave_classdef::undef_subsasgn (const s void octave_classdef::print (std::ostream& os, bool) { - if (! called_from_builtin ()) - { - cdef_method meth = object.get_class ().find_method ("disp"); - - if (meth.ok ()) - { - octave_value_list args; - - count++; - args(0) = octave_value (this); - - indent (os); - meth.execute (args, 0, true, "disp"); - - return; - } - } - print_raw (os); } @@ -988,25 +970,7 @@ void octave_classdef::print_with_name (std::ostream& os, const std::string& name, bool print_padding) { - cdef_method meth = object.get_class ().find_method ("display"); - - if (meth.ok ()) - { - octave_value_list args; - - count++; - args(0) = octave_value (this); - - string_vector arg_names (1); - - arg_names[0] = name; - args.stash_name_tags (arg_names); - - indent (os); - meth.execute (args, 0, true, "display"); - } - else - octave_base_value::print_with_name (os, name, print_padding); + octave_base_value::print_with_name (os, name, print_padding); } bool diff --git a/libinterp/parse-tree/pt-assign.cc b/libinterp/parse-tree/pt-assign.cc --- a/libinterp/parse-tree/pt-assign.cc +++ b/libinterp/parse-tree/pt-assign.cc @@ -33,8 +33,9 @@ along with Octave; see the file COPYING. #include "input.h" #include "ovl.h" #include "oct-lvalue.h" +#include "ov.h" #include "pager.h" -#include "ov.h" +#include "parse.h" #include "pt-arg-list.h" #include "pt-bp.h" #include "pt-assign.h" @@ -117,8 +118,7 @@ tree_simple_assignment::rvalue1 (int) octave_value lhs_val = ult.value (); - lhs_val.print_with_name (octave_stdout, - lhs->name ()); + feval ("display", ovl (lhs_val, lhs->name ())); } } catch (octave::index_exception& e) @@ -330,7 +330,7 @@ tree_multi_assignment::rvalue (int) octave_value lhs_val = ult.value (); - lhs_val.print_with_name (octave_stdout, lhs_elt->name ()); + feval ("display", ovl (lhs_val, lhs_elt->name ())); } } diff --git a/libinterp/parse-tree/pt-id.cc b/libinterp/parse-tree/pt-id.cc --- a/libinterp/parse-tree/pt-id.cc +++ b/libinterp/parse-tree/pt-id.cc @@ -28,6 +28,7 @@ along with Octave; see the file COPYING. #include "ovl.h" #include "oct-lvalue.h" #include "pager.h" +#include "parse.h" #include "pt-bp.h" #include "pt-const.h" #include "pt-eval.h" @@ -95,7 +96,7 @@ tree_identifier::rvalue (int nargout, { if (print_result () && nargout == 0 && octave::tree_evaluator::statement_printing_enabled ()) - val.print_with_name (octave_stdout, name ()); + feval ("display", ovl (val, name ())); retval = val; } diff --git a/scripts/general/display.m b/scripts/general/display.m --- a/scripts/general/display.m +++ b/scripts/general/display.m @@ -42,22 +42,24 @@ ## @seealso{class, subsref, subsasgn} ## @end deftypefn -function display (obj) +function display (obj, name) - if (nargin != 1) + if (nargin < 1 || nargin > 2) print_usage (); endif - ## Only reason we got here is that there was no overloaded display function. - ## Rely on built-in functions to display whatever obj is. + if (nargin == 1) + name = inputname (1); + endif - varname = inputname (1); - if (! isempty (varname)) - evalin ("caller", varname); - else - disp (obj); + if (! isempty (name)) + printf ("%s =\n\n", name); endif + disp (obj); + + printf ("\n"); + endfunction