This very simple patch makes sure that only files and no matlab
symbols shows up when completing a "cd" och "ls" command. It also
makes sure no files are displayed when completing the first command on
the line. It's still not possible to complete a path-three such as "cd
projects/octave/stacking", only files/folders in the current directory
are showned in the completion list (just like before I touched the
code).
The intelligence of "is_completing_dirfns" needs serious enhancement
but at least it's a start.
Please leave feedback. Which kind of completion behavior do you
prefer?
=== modified file 'liboctave/cmd-edit.cc'
@@ -136,6 +136,8 @@
string_vector
do_generate_filename_completions (const std::string& text);
+ std::string do_get_line_buffer (void);
+
void do_insert_text (const std::string& text);
void do_newline (void);
@@ -501,6 +503,12 @@
return retval;
}
+std::string
+gnu_readline::do_get_line_buffer (void)
+{
+ return ::octave_rl_line_buffer ();
+}
+
void
gnu_readline::do_insert_text (const std::string& text)
{
@@ -726,6 +734,8 @@
string_vector do_generate_filename_completions (const
std::string& text);
+ std::string do_get_line_buffer (void);
+
void do_insert_text (const std::string&);
void do_newline (void);
@@ -779,6 +789,12 @@
return string_vector ();
}
+std::string
+default_command_editor::do_get_line_buffer (void)
+{
+ return "";
+}
+
void
default_command_editor::do_insert_text (const std::string&)
{
@@ -1081,6 +1097,13 @@
? instance->do_get_char_is_quoted_function () : 0;
}
+std::string
+command_editor::get_line_buffer (void)
+{
+ return (instance_ok())
+ ? instance->do_get_line_buffer() : "";
+}
+
command_editor::user_accept_line_fcn
command_editor::get_user_accept_line_function (void)
{
=== modified file 'liboctave/cmd-edit.h'
@@ -120,6 +120,8 @@
static string_vector generate_filename_completions (const
std::string& text);
+ static std::string get_line_buffer(void);
+
static void insert_text (const std::string& text);
static void newline (void);
@@ -252,6 +254,8 @@
virtual string_vector do_generate_filename_completions (const
std::string& text) = 0;
+ virtual std::string do_get_line_buffer(void) = 0;
+
virtual void do_insert_text (const std::string&) = 0;
virtual void do_newline (void) = 0;
=== modified file 'src/input.cc'
@@ -447,6 +447,21 @@
return names;
}
+static bool
+is_completing_dirfns (const std::string& line)
+{
+ static std::string dirfns_commands[] = {"cd", "ls"};
+ static const size_t dirfns_commands_length = 2;
+
+ for(size_t i=0; i < dirfns_commands_length; ++i)
+ {
+ int index = line.find (dirfns_commands[i] + " ");
+ if (index==0) return true;
+ }
+
+ return false;
+}
+
static std::string
generate_completion (const std::string& text, int state)
{
@@ -473,7 +488,13 @@
hint = text;
- name_list = generate_possible_completions (text, prefix, hint);
+ std::string line = command_editor::get_line_buffer();
+
+ // no reason to display matlab symbols while completing a
file/directory operation
+ if (!is_completing_dirfns(line))
+ name_list = generate_possible_completions (text, prefix,
hint);
+ else
+ name_list = string_vector();
name_list_len = name_list.length ();
----------------------------------------------------------------------
---
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Register now and save $200. Hurry, offer ends at 11:59 p.m.,
Monday, April 7! Use priority code J8TLD2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://
java.sun.com/javaone
_______________________________________________
Octave-dev mailing list
address@hidden
https://lists.sourceforge.net/lists/listinfo/octave-dev