# HG changeset patch
# User Daniel Robinson
# Date 1406272418 -7200
#      ven. juil. 25 09:13:38 2014 +0200
# Branch stable
# Node ID b66821f5042b21fd592d04872481b559994adf19
# Parent  ab5983dc058743b5380c7c03c8b75a0a81f3db3b
Fix tab completion bug (bug #34624)

diff -r ab5983dc0587 -r b66821f5042b libinterp/corefcn/input.cc
--- a/libinterp/corefcn/input.cc	jeu. juil. 24 11:11:57 2014 -0700
+++ b/libinterp/corefcn/input.cc	ven. juil. 25 09:13:38 2014 +0200
@@ -352,8 +352,11 @@
 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;
 
@@ -373,6 +376,19 @@
   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)
 {
@@ -487,6 +503,8 @@
 
   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\\\"'@<>=;|&()#$`?*[!:{");
diff -r ab5983dc0587 -r b66821f5042b liboctave/util/cmd-edit.cc
--- a/liboctave/util/cmd-edit.cc	jeu. juil. 24 11:11:57 2014 -0700
+++ b/liboctave/util/cmd-edit.cc	ven. juil. 25 09:13:38 2014 +0200
@@ -169,6 +169,10 @@
 
   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);
@@ -195,6 +199,8 @@
 
   event_hook_fcn previous_event_hook;
 
+  completion_word_break_hook_fcn previous_completion_word_break_hook;
+
   completion_fcn completion_function;
 
   quoting_fcn quoting_function;
@@ -627,6 +633,21 @@
   ::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)
 {
@@ -1408,6 +1429,24 @@
     }
 }
 
+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)
 {
diff -r ab5983dc0587 -r b66821f5042b liboctave/util/cmd-edit.h
--- a/liboctave/util/cmd-edit.h	jeu. juil. 24 11:11:57 2014 -0700
+++ b/liboctave/util/cmd-edit.h	ven. juil. 25 09:13:38 2014 +0200
@@ -47,6 +47,8 @@
 
   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);
@@ -151,6 +153,10 @@
 
   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 ());
@@ -329,6 +335,10 @@
 
   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) { }
+
   virtual void do_interrupt (bool) { }
 
   int do_insert_initial_input (void);
diff -r ab5983dc0587 -r b66821f5042b liboctave/util/oct-rl-edit.c
--- a/liboctave/util/oct-rl-edit.c	jeu. juil. 24 11:11:57 2014 -0700
+++ b/liboctave/util/oct-rl-edit.c	ven. juil. 25 09:13:38 2014 +0200
@@ -360,6 +360,24 @@
   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)
 {
diff -r ab5983dc0587 -r b66821f5042b liboctave/util/oct-rl-edit.h
--- a/liboctave/util/oct-rl-edit.h	jeu. juil. 24 11:11:57 2014 -0700
+++ b/liboctave/util/oct-rl-edit.h	ven. juil. 25 09:13:38 2014 +0200
@@ -29,6 +29,8 @@
 
 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);
@@ -137,6 +139,12 @@
 
 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);
 
