# HG changeset patch # User jwe # Date 1037248279 0 # Node ID 8734ba917fea8e0d36171e34c4c498737a2b4fe1 # Parent b75f74a769410da8c161e3129d8cf5173f5d006b [project @ 2002-11-14 04:31:19 by jwe] diff -r b75f74a76941 -r 8734ba917fea src/ChangeLog --- a/src/ChangeLog Wed Nov 13 15:43:35 2002 +0000 +++ b/src/ChangeLog Thu Nov 14 04:31:19 2002 +0000 @@ -1,3 +1,9 @@ +2002-11-13 John W. Eaton + + * variables.cc (is_variable): New static function. + (generate_struct_completions): Only evaluate objects that look + like variables. + 2002-11-12 John W. Eaton * pt-jump.h, pt-jump.cc (tree_break_expression, diff -r b75f74a76941 -r 8734ba917fea src/input.cc --- a/src/input.cc Wed Nov 13 15:43:35 2002 +0000 +++ b/src/input.cc Thu Nov 14 04:31:19 2002 +0000 @@ -459,15 +459,19 @@ else retval = name; - if (matches == 1 && looks_like_struct (retval)) - { - // Don't append anything, since we don't know - // whether it should be '(' or '.'. - command_editor::set_completion_append_character ('\0'); - } - else - command_editor::set_completion_append_character - (Vcompletion_append_char); + // XXX FIXME XXX -- looks_like_struct is broken for now, + // so it always returns false. + + if (matches == 1 && looks_like_struct (retval)) + { + // Don't append anything, since we don't know + // whether it should be '(' or '.'. + + command_editor::set_completion_append_character ('\0'); + } + else + command_editor::set_completion_append_character + (Vcompletion_append_char); break; } diff -r b75f74a76941 -r 8734ba917fea src/variables.cc --- a/src/variables.cc Wed Nov 13 15:43:35 2002 +0000 +++ b/src/variables.cc Thu Nov 14 04:31:19 2002 +0000 @@ -271,6 +271,24 @@ return retval; } +static inline bool +is_variable (const std::string& name) +{ + bool retval = false; + + if (! name.empty ()) + { + symbol_record *sr = curr_sym_tab->lookup (name); + + if (! sr) + sr = fbi_sym_tab->lookup (name); + + retval = (sr && sr->is_variable ()); + } + + return retval; +} + string_vector generate_struct_completions (const std::string& text, std::string& prefix, std::string& hint) @@ -287,34 +305,48 @@ hint = text.substr (pos+1); prefix = text.substr (0, pos); - } - int parse_status; + std::string base_name = prefix; + + pos = base_name.find_first_of ("{(."); - unwind_protect::begin_frame ("generate_struct_completions"); + if (pos != NPOS) + base_name = base_name.substr (0, pos); - unwind_protect_str (Vwarning_option); - unwind_protect_bool (discard_error_messages); - unwind_protect_int (error_state); + if (is_variable (base_name)) + { + int parse_status; + + unwind_protect::begin_frame ("generate_struct_completions"); - Vwarning_option = "off"; - discard_error_messages = true; + unwind_protect_str (Vwarning_option); + unwind_protect_bool (discard_error_messages); + unwind_protect_int (error_state); - octave_value tmp = eval_string (prefix, true, parse_status); + Vwarning_option = "off"; + discard_error_messages = true; - unwind_protect::run_frame ("generate_struct_completions"); + octave_value tmp = eval_string (prefix, true, parse_status); + + unwind_protect::run_frame ("generate_struct_completions"); - if (tmp.is_defined () && tmp.is_map ()) - names = tmp.map_keys (); + if (tmp.is_defined () && tmp.is_map ()) + names = tmp.map_keys (); + } + } return names; } +// XXX FIXME XXX -- this will have to be much smarter to work +// "correctly". + bool looks_like_struct (const std::string& text) { bool retval = false; +#if 0 symbol_record *sr = curr_sym_tab->lookup (text); if (sr && ! sr->is_function ()) @@ -336,6 +368,7 @@ retval = (tmp.is_defined () && tmp.is_map ()); } +#endif return retval; }