Mercurial > hg > octave-terminal
changeset 4179:8734ba917fea
[project @ 2002-11-14 04:31:19 by jwe]
author | jwe |
---|---|
date | Thu, 14 Nov 2002 04:31:19 +0000 |
parents | b75f74a76941 |
children | 84fe3ca3a246 |
files | src/ChangeLog src/input.cc src/variables.cc |
diffstat | 3 files changed, 64 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2002-11-13 John W. Eaton <jwe@bevo.che.wisc.edu> + + * variables.cc (is_variable): New static function. + (generate_struct_completions): Only evaluate objects that look + like variables. + 2002-11-12 John W. Eaton <jwe@bevo.che.wisc.edu> * pt-jump.h, pt-jump.cc (tree_break_expression,
--- a/src/input.cc +++ b/src/input.cc @@ -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; }
--- a/src/variables.cc +++ b/src/variables.cc @@ -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; }