diff -r 382b6790eaee liboctave/cmd-edit.cc --- a/liboctave/cmd-edit.cc Sat Feb 25 22:03:33 2012 -0500 +++ b/liboctave/cmd-edit.cc Sun Feb 26 10:26:54 2012 -0500 @@ -148,16 +148,20 @@ void set_startup_hook (startup_hook_fcn f); void restore_startup_hook (void); void set_event_hook (event_hook_fcn f); void restore_event_hook (void); + void do_set_completion_word_break_hook (completion_word_break_hook_fcn f); + + void do_restore_completion_word_break_hook (void); + void do_restore_event_hook (void); void do_read_init_file (const std::string& file); void do_re_read_init_file (void); bool do_filename_completion_desired (bool); @@ -170,16 +174,18 @@ static int history_search_forward (int, int); private: startup_hook_fcn previous_startup_hook; event_hook_fcn previous_event_hook; + completion_word_break_hook_fcn previous_completion_word_break_hook; + completion_fcn completion_function; quoting_fcn quoting_function; dequoting_fcn dequoting_function; char_is_quoted_fcn char_is_quoted_function; @@ -558,16 +564,31 @@ } void gnu_readline::restore_event_hook (void) { ::octave_rl_set_event_hook (previous_event_hook); } +void +gnu_readline::do_set_completion_word_break_hook (completion_word_break_hook_fcn f) +{ + previous_completion_word_break_hook = + ::octave_rl_get_completion_word_break_hook (); + + ::octave_rl_set_completion_word_break_hook (f); +} + +void +gnu_readline::do_restore_completion_word_break_hook (void) +{ + ::octave_rl_set_completion_word_break_hook (previous_completion_word_break_hook); +} + void gnu_readline::do_read_init_file (const std::string& file) { ::octave_rl_read_init_file (file.c_str ()); } void gnu_readline::do_re_read_init_file (void) @@ -1227,16 +1248,34 @@ if (p != event_hook_set.end ()) event_hook_set.erase (p); if (event_hook_set.empty ()) instance->restore_event_hook (); } } +void +command_editor::set_completion_word_break_hook (completion_word_break_hook_fcn f) +{ + if (instance_ok ()) + { + instance->do_set_completion_word_break_hook (f); + } +} + +void +command_editor::restore_completion_word_break_hook (void) +{ + if (instance_ok ()) + { + instance->do_restore_completion_word_break_hook (); + } +} + void command_editor::run_event_hooks (void) { event_handler (); } void command_editor::read_init_file (const std::string& file_arg) diff -r 382b6790eaee liboctave/cmd-edit.h --- a/liboctave/cmd-edit.h Sat Feb 25 22:03:33 2012 -0500 +++ b/liboctave/cmd-edit.h Sun Feb 26 10:26:54 2012 -0500 @@ -40,16 +40,18 @@ : command_number (0) { } public: typedef int (*startup_hook_fcn) (void); typedef int (*event_hook_fcn) (void); + typedef char* (*completion_word_break_hook_fcn) (void); + typedef std::string (*completion_fcn) (const std::string&, int); typedef std::string (*quoting_fcn) (const std::string&, int, char); typedef std::string (*dequoting_fcn) (const std::string&, int); typedef int (*char_is_quoted_fcn) (const std::string&, int); @@ -132,16 +134,20 @@ static void add_startup_hook (startup_hook_fcn f); static void remove_startup_hook (startup_hook_fcn f); static void add_event_hook (event_hook_fcn f); static void remove_event_hook (event_hook_fcn f); + static void set_completion_word_break_hook (completion_word_break_hook_fcn f); + + static void restore_completion_word_break_hook (); + static void run_event_hooks (void); static void read_init_file (const std::string& file = std::string ()); static void re_read_init_file (void); static bool filename_completion_desired (bool); @@ -282,16 +288,20 @@ virtual void do_read_init_file (const std::string&) { } virtual void do_re_read_init_file (void) { } virtual bool do_filename_completion_desired (bool) { return false; } virtual bool do_filename_quoting_desired (bool) { return false; } + virtual void do_set_completion_word_break_hook (completion_word_break_hook_fcn) { } + + virtual void do_restore_completion_word_break_hook (void) { } + int read_octal (const std::string& s); void error (int); void error (const std::string&); // The current command number. int command_number; diff -r 382b6790eaee liboctave/oct-rl-edit.c --- a/liboctave/oct-rl-edit.c Sat Feb 25 22:03:33 2012 -0500 +++ b/liboctave/oct-rl-edit.c Sun Feb 26 10:26:54 2012 -0500 @@ -313,16 +313,34 @@ } rl_event_hook_fcn_ptr octave_rl_get_event_hook (void) { return rl_event_hook; } +void +octave_rl_set_completion_word_break_hook (rl_completion_word_break_hook_fcn_ptr f) +{ +#if RL_VERSION_MAJOR >= 5 + rl_completion_word_break_hook = f; +#endif +} + +rl_completion_word_break_hook_fcn_ptr +octave_rl_get_completion_word_break_hook (void) +{ +#if RL_VERSION_MAJOR >= 5 + return rl_completion_word_break_hook; +#else + return (rl_completion_word_break_hook_fcn_ptr)0; +#endif +} + char ** octave_rl_completion_matches (const char *text, rl_completer_fcn_ptr f) { return rl_completion_matches (text, f); } char octave_rl_prompt_start_ignore (void) diff -r 382b6790eaee liboctave/oct-rl-edit.h --- a/liboctave/oct-rl-edit.h Sat Feb 25 22:03:33 2012 -0500 +++ b/liboctave/oct-rl-edit.h Sun Feb 26 10:26:54 2012 -0500 @@ -22,16 +22,18 @@ #if !defined (octave_rl_edit_h) #define octave_rl_edit_h 1 typedef int (*rl_startup_hook_fcn_ptr) (void); typedef int (*rl_event_hook_fcn_ptr) (void); +typedef char* (*rl_completion_word_break_hook_fcn_ptr) (void); + typedef int (*rl_fcn_ptr) (int, int); typedef char ** (*rl_attempted_completion_fcn_ptr) (const char *, int, int); typedef char * (*rl_completer_fcn_ptr) (const char *, int); typedef char * (*rl_quoting_fcn_ptr) (char *, int, char *); @@ -118,16 +120,22 @@ extern void octave_rl_set_startup_hook (rl_startup_hook_fcn_ptr); extern rl_startup_hook_fcn_ptr octave_rl_get_startup_hook (void); extern void octave_rl_set_event_hook (rl_event_hook_fcn_ptr f); extern rl_event_hook_fcn_ptr octave_rl_get_event_hook (void); +extern void +octave_rl_set_completion_word_break_hook (rl_completion_word_break_hook_fcn_ptr); + +extern rl_completion_word_break_hook_fcn_ptr +octave_rl_get_completion_word_break_hook (void); + extern char ** octave_rl_completion_matches (const char *, rl_completer_fcn_ptr); extern char octave_rl_prompt_start_ignore (void); extern char octave_rl_prompt_end_ignore (void); extern void octave_rl_add_defun (const char *, rl_fcn_ptr, char); diff -r 382b6790eaee src/input.cc --- a/src/input.cc Sat Feb 25 22:03:33 2012 -0500 +++ b/src/input.cc Sun Feb 26 10:26:54 2012 -0500 @@ -475,18 +475,21 @@ names.sort (true); return names; } static bool is_completing_dirfns (void) { - static std::string dirfns_commands[] = {"cd", "ls"}; - static const size_t dirfns_commands_length = 2; + static std::string dirfns_commands[] = { + "cd", "ls", "load", "save", "rename", "rmdir", + "movefile", "copyfile", "unlink" + }; + static const size_t dirfns_commands_length = 9; bool retval = false; std::string line = command_editor::get_line_buffer (); for (size_t i = 0; i < dirfns_commands_length; i++) { int index = line.find (dirfns_commands[i] + " "); @@ -496,16 +499,29 @@ retval = true; break; } } return retval; } +// for rl_completion_word_break_hook +static char *get_completion_word_break_chars (void) +{ + if ( is_completing_dirfns() ) + { + return "\t\n\r \"\'"; + } + else + { + return "\t\n\r !\"\'*+-/:;<=>(){}[\\]^`~"; + } +} + static std::string generate_completion (const std::string& text, int state) { std::string retval; static std::string prefix; static std::string hint; @@ -610,16 +626,18 @@ // causes trouble for the new struct element completion code. static const char *s = "\t\n !\"\'*+-/:;<=>(){}[\\]^`~"; command_editor::set_basic_word_break_characters (s); command_editor::set_completer_word_break_characters (s); + command_editor::set_completion_word_break_hook (get_completion_word_break_chars); + command_editor::set_basic_quote_characters ("\""); command_editor::set_filename_quote_characters (" \t\n\\\"'@<>=;|&()#$`?*[!:{"); command_editor::set_completer_quote_characters ("'\""); command_editor::set_completion_function (generate_completion); command_editor::set_quoting_function (quoting_filename);