changeset 22172:ed8a0c39e14c

Allow TAB autocompletion of local functions in debug mode (bug #48317) * help.cc (local_functions): New function. * help.cc (make_name_list): Include local function names in the list.
author Lachlan Andrew <lachlanbis@gmail.com>
date Sat, 23 Jul 2016 18:39:07 -0400
parents 0a4c5a90f286
children 8de49f15e182
files libinterp/corefcn/help.cc
diffstat 1 files changed, 39 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/help.cc	Thu Jun 30 18:19:37 2016 +1000
+++ b/libinterp/corefcn/help.cc	Sat Jul 23 18:39:07 2016 -0400
@@ -796,6 +796,38 @@
 const static map_type keywords_map (keywords, keywords + size (keywords));
 const static string_vector keyword_names = names (keywords_map);
 
+// Return a vector of all functions from this file,
+// for use in command line auto-completion.
+static string_vector
+local_functions (void)
+{
+  string_vector retval;
+
+  octave_user_code *curr_fcn = octave_call_stack::caller_user_code ();
+
+  if (! curr_fcn)
+    return retval;
+
+  // All subfunctions are listed in the top-level function of this file.
+  while (curr_fcn->is_subfunction ())
+    curr_fcn = symbol_table::get_curr_fcn (curr_fcn->parent_fcn_scope ());
+
+  // Get subfunctions.
+  const std::list<std::string> names = curr_fcn->subfunction_names ();
+
+  size_t sz = names.size ();
+  retval.resize (sz);
+
+  // Loop over them.
+  size_t i = 0;
+  for (std::list<std::string>::const_iterator p = names.begin ();
+       p != names.end (); p++)
+    retval(i++) = *p;
+
+  retval.resize (i);
+  return retval;
+}
+
 // FIXME: It's not likely that this does the right thing now.
 
 string_vector
@@ -818,8 +850,11 @@
   const string_vector afl = autoloaded_functions ();
   const int afl_len = afl.numel ();
 
+  const string_vector lfl = local_functions ();
+  const int lfl_len = lfl.numel ();
+
   const int total_len
-    = key_len + bif_len + cfl_len + lcl_len + ffl_len + afl_len;
+    = key_len + bif_len + cfl_len + lcl_len + ffl_len + afl_len + lfl_len;
 
   string_vector list (total_len);
 
@@ -845,6 +880,9 @@
   for (i = 0; i < afl_len; i++)
     list[j++] = afl[i];
 
+  for (i = 0; i < lfl_len; i++)
+    list[j++] = lfl[i];
+
   return list;
 }