octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MSVC 2.9.13 and path completion with spaces


From: David Bateman
Subject: Re: MSVC 2.9.13 and path completion with spaces
Date: Thu, 04 Oct 2007 02:50:24 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

John W. Eaton wrote:
> On  3-Oct-2007, David Bateman wrote:
> 
> | So it appears that bash does the quoting and not readline.. I suppose we
> | could just copy their quoting code..
> 
> I think it would require some modification because the languages are
> different.
> 
> | Well since most Windows users have their home directory under "Documents
> | and Settings" this is a bit of a pain for windows users, which is why I
> | was looking at it before a 3.0 release. I'll look at bash and see if
> | there are any ideas we can steal..
> 
> OK.
> 
> Currently, bash inserts "\ " when quoting spaces, and we can't use
> that.  I don't have a problem with fixing things so that the user has
> to start a filename with ' or " in order for it to be quoted, with
> Octave/readline inserting the final quote.  Bash will also do this,
> and it also seems to be what Matlab does, at least on Unixy systems.
> Maybe it would also be possible to get Octave/readline to insert the
> leading quote if there is only one completion and the filename has
> spaces.
> 
> 

What I have at the moment that isn't far off is the attached... It adds
the missing leading quote and even completes into deep sub directories
(if they arg is quoted). However it doesn't add the trailing quote
character. I think this might be done with correct quoting and dequoting
functions. I use the default readline ones in this patch but have
written non working ones and the infrastructure to set them. However,
although the trailing quote is added with the attached it messes up with
things like

cd ("Di<TAB>

where "Dir One" is a directory. If I could just figure out how to add
the trailing quote character correctly this would be prefer. If I
replace pointed to by the third arg of  rl_quote_func_t with a "'" then
the attach seems to work correctly, except for things like

cd ("Dir\ O<TAB>

As it treats the \ as a character. This is fairly rare though. It
however looses the ability to do deep sub directory completion..


In any case with a little cleaning up this patch is already vastly
better than what is there already for path completion.. Any suggestions
how to add the trailing quote with this patch? If not what is the best
compromise? No trailing quote or no deep sub-directory completion?

Regards
David

*** ./liboctave/cmd-edit.h.orig17       2007-10-02 16:38:21.677920959 +0200
--- ./liboctave/cmd-edit.h      2007-10-04 02:15:47.229492203 +0200
***************
*** 48,53 ****
--- 48,59 ----
  
    typedef std::string (*completion_fcn) (const std::string&, int);
  
+   typedef std::string (*quoting_fcn) (const std::string&, int);
+ 
+   typedef std::string (*dequoting_fcn) (const std::string&, int);
+ 
+   typedef int (*char_is_quoted_fcn) (const std::string&, int);
+ 
    virtual ~command_editor (void) { }
  
    static void set_name (const std::string& n);
***************
*** 84,95 ****
--- 90,117 ----
  
    static void set_basic_quote_characters (const std::string& s);
  
+   static void set_filename_quote_characters (const std::string& s);
+ 
+   static void set_completer_quote_characters (const std::string& s);
+ 
    static void set_completion_append_character (char c);
  
    static void set_completion_function (completion_fcn f);
  
+   static void set_quoting_function (quoting_fcn f);
+ 
+   static void set_dequoting_function (dequoting_fcn f);
+ 
+   static void set_char_is_quoted_function (char_is_quoted_fcn f);
+ 
    static completion_fcn get_completion_function (void);
  
+   static quoting_fcn get_quoting_function (void);
+ 
+   static dequoting_fcn get_dequoting_function (void);
+ 
+   static char_is_quoted_fcn get_char_is_quoted_function (void);
+ 
    static string_vector generate_filename_completions (const std::string& 
text);
  
    static void insert_text (const std::string& text);
***************
*** 110,115 ****
--- 132,139 ----
  
    static bool filename_completion_desired (bool);
  
+   static bool filename_quoting_desired (bool);
+ 
    static int current_command_number (void);
  
    static void reset_current_command_number (int n);
***************
*** 192,203 ****
--- 216,243 ----
  
    virtual void do_set_basic_quote_characters (const std::string&) { }
  
+   virtual void do_set_filename_quote_characters (const std::string&) { }
+ 
+   virtual void do_set_completer_quote_characters (const std::string&) { }
+ 
    virtual void do_set_completion_append_character (char) { }
  
    virtual void do_set_completion_function (completion_fcn) { }
  
+   virtual void do_set_quoting_function (quoting_fcn) { }
+ 
+   virtual void do_set_dequoting_function (dequoting_fcn) { }
+ 
+   virtual void do_set_char_is_quoted_function (char_is_quoted_fcn) { }
+ 
    virtual completion_fcn do_get_completion_function (void) const { return 0; }
  
+   virtual quoting_fcn do_get_quoting_function (void) const { return 0; }
+ 
+   virtual dequoting_fcn do_get_dequoting_function (void) const { return 0; }
+ 
+   virtual char_is_quoted_fcn do_get_char_is_quoted_function (void) const { 
return 0; }
+ 
    virtual string_vector do_generate_filename_completions (const std::string& 
text) = 0;
  
    virtual void do_insert_text (const std::string&) = 0;
***************
*** 218,223 ****
--- 258,265 ----
  
    virtual bool do_filename_completion_desired (bool) { return false; }
  
+   virtual bool do_filename_quoting_desired (bool) { return false; }
+ 
    int read_octal (const std::string& s);
  
    void error (int);
*** ./liboctave/cmd-edit.cc.orig17      2007-10-02 16:38:32.671365414 +0200
--- ./liboctave/cmd-edit.cc     2007-10-04 02:21:19.728386138 +0200
***************
*** 107,118 ****
--- 107,134 ----
  
    void do_set_basic_quote_characters (const std::string& s);
  
+   void do_set_filename_quote_characters (const std::string& s);
+ 
+   void do_set_completer_quote_characters (const std::string& s);
+ 
    void do_set_completion_append_character (char c);
  
    void do_set_completion_function (completion_fcn f);
  
+   void do_set_quoting_function (quoting_fcn f);
+ 
+   void do_set_dequoting_function (dequoting_fcn f);
+ 
+   void do_set_char_is_quoted_function (char_is_quoted_fcn f);
+ 
    completion_fcn do_get_completion_function (void) const;
  
+   quoting_fcn do_get_quoting_function (void) const;
+ 
+   dequoting_fcn do_get_dequoting_function (void) const;
+ 
+   char_is_quoted_fcn do_get_char_is_quoted_function (void) const;
+ 
    string_vector
    do_generate_filename_completions (const std::string& text);
  
***************
*** 136,141 ****
--- 152,159 ----
  
    bool do_filename_completion_desired (bool);
  
+   bool do_filename_quoting_desired (bool);
+ 
    static int operate_and_get_next (int, int);
  
    static int history_search_backward (int, int);
***************
*** 150,157 ****
--- 168,186 ----
  
    completion_fcn completion_function;
  
+   quoting_fcn quoting_function;
+ 
+   dequoting_fcn dequoting_function;
+ 
+   char_is_quoted_fcn char_is_quoted_function;
+ 
    static char *command_generator (const char *text, int state);
  
+   static char *command_quoter (char *text, int match_type, char 
*quote_pointer);
+   static char *command_dequoter (char *text, int match_type);
+ 
+   static int command_char_is_quoted (char *text, int index);
+ 
    static char **command_completer (const char *text, int start, int end);
  };
  
***************
*** 319,324 ****
--- 348,365 ----
  }
  
  void
+ gnu_readline::do_set_filename_quote_characters (const std::string& s)
+ {
+   ::octave_rl_set_filename_quote_characters (s.c_str ());
+ }
+ 
+ void
+ gnu_readline::do_set_completer_quote_characters (const std::string& s)
+ {
+   ::octave_rl_set_completer_quote_characters (s.c_str ());
+ }
+ 
+ void
  gnu_readline::do_set_completion_append_character (char c)
  {
    ::octave_rl_set_completion_append_character (c);
***************
*** 335,346 ****
--- 376,438 ----
    ::octave_rl_set_completion_function (fp);
  }
  
+ void
+ gnu_readline::do_set_quoting_function (quoting_fcn f)
+ {
+   quoting_function = f;
+ 
+   rl_quoting_fcn_ptr fp
+     = f ? gnu_readline::command_quoter : 0;
+ 
+   ::octave_rl_set_quoting_function (fp);
+ }
+ 
+ void
+ gnu_readline::do_set_dequoting_function (dequoting_fcn f)
+ {
+   dequoting_function = f;
+ 
+   rl_dequoting_fcn_ptr fp
+     = f ? gnu_readline::command_dequoter : 0;
+ 
+   ::octave_rl_set_dequoting_function (fp);
+ }
+ 
+ void
+ gnu_readline::do_set_char_is_quoted_function (char_is_quoted_fcn f)
+ {
+   char_is_quoted_function = f;
+ 
+   rl_char_is_quoted_fcn_ptr fp
+     = f ? gnu_readline::command_char_is_quoted : 0;
+ 
+   ::octave_rl_set_char_is_quoted_function (fp);
+ }
+ 
  gnu_readline::completion_fcn
  gnu_readline::do_get_completion_function (void) const
  {
    return completion_function;
  }
  
+ gnu_readline::quoting_fcn
+ gnu_readline::do_get_quoting_function (void) const
+ {
+   return quoting_function;
+ }
+ 
+ gnu_readline::dequoting_fcn
+ gnu_readline::do_get_dequoting_function (void) const
+ {
+   return dequoting_function;
+ }
+ 
+ gnu_readline::char_is_quoted_fcn
+ gnu_readline::do_get_char_is_quoted_function (void) const
+ {
+   return char_is_quoted_function;
+ }
+ 
  string_vector
  gnu_readline::do_generate_filename_completions (const std::string& text)
  {
***************
*** 439,444 ****
--- 531,542 ----
    return ::octave_rl_filename_completion_desired (arg);
  }
  
+ bool
+ gnu_readline::do_filename_quoting_desired (bool arg)
+ {
+   return ::octave_rl_filename_quoting_desired (arg);
+ }
+ 
  int
  gnu_readline::operate_and_get_next (int /* count */, int /* c */)
  {
***************
*** 497,502 ****
--- 595,650 ----
    return retval;
  }
  
+ char *
+ gnu_readline::command_quoter (char *text, int matches, char *)
+ {
+   char *retval = 0;
+ 
+   quoting_fcn f = command_editor::get_quoting_function ();
+ 
+   std::string tmp = f (text, matches);
+ 
+   size_t len = tmp.length ();
+ 
+   if (len > 0)
+     {
+       retval = static_cast<char *> (malloc (len+1));
+ 
+       strcpy (retval, tmp.c_str ());
+     }
+ 
+   return retval;
+ }
+ 
+ char *
+ gnu_readline::command_dequoter (char *text, int quote)
+ {
+   char *retval = 0;
+ 
+   dequoting_fcn f = command_editor::get_dequoting_function ();
+ 
+   std::string tmp = f (text, quote);
+ 
+   size_t len = tmp.length ();
+ 
+   if (len > 0)
+     {
+       retval = static_cast<char *> (malloc (len+1));
+ 
+       strcpy (retval, tmp.c_str ());
+     }
+ 
+   return retval;
+ }
+ 
+ int
+ gnu_readline::command_char_is_quoted (char *text, int quote)
+ {
+   char_is_quoted_fcn f = command_editor::get_char_is_quoted_function ();
+ 
+   return f (text, quote);
+ }
+ 
  char **
  gnu_readline::command_completer (const char *text, int, int)
  {
***************
*** 794,799 ****
--- 942,961 ----
  }
  
  void
+ command_editor::set_filename_quote_characters (const std::string& s)
+ {
+   if (instance_ok ())
+     instance->do_set_filename_quote_characters (s);
+ }
+ 
+ void
+ command_editor::set_completer_quote_characters (const std::string& s)
+ {
+   if (instance_ok ())
+     instance->do_set_completer_quote_characters (s);
+ }
+ 
+ void
  command_editor::set_completion_append_character (char c)
  {
    if (instance_ok ())
***************
*** 807,812 ****
--- 969,995 ----
      instance->do_set_completion_function (f);
  }
  
+ void
+ command_editor::set_quoting_function (quoting_fcn f)
+ {
+   if (instance_ok ())
+     instance->do_set_quoting_function (f);
+ }
+ 
+ void
+ command_editor::set_dequoting_function (dequoting_fcn f)
+ {
+   if (instance_ok ())
+     instance->do_set_dequoting_function (f);
+ }
+ 
+ void
+ command_editor::set_char_is_quoted_function (char_is_quoted_fcn f)
+ {
+   if (instance_ok ())
+     instance->do_set_char_is_quoted_function (f);
+ }
+ 
  command_editor::completion_fcn
  command_editor::get_completion_function (void)
  {
***************
*** 814,819 ****
--- 997,1023 ----
      ? instance->do_get_completion_function () : 0;
  }
  
+ command_editor::quoting_fcn
+ command_editor::get_quoting_function (void)
+ {
+   return (instance_ok ())
+     ? instance->do_get_quoting_function () : 0;
+ }
+ 
+ command_editor::dequoting_fcn
+ command_editor::get_dequoting_function (void)
+ {
+   return (instance_ok ())
+     ? instance->do_get_dequoting_function () : 0;
+ }
+ 
+ command_editor::char_is_quoted_fcn
+ command_editor::get_char_is_quoted_function (void)
+ {
+   return (instance_ok ())
+     ? instance->do_get_char_is_quoted_function () : 0;
+ }
+ 
  string_vector
  command_editor::generate_filename_completions (const std::string& text)
  {
***************
*** 912,917 ****
--- 1116,1128 ----
      ? instance->do_filename_completion_desired (arg) : false;
  }
  
+ bool
+ command_editor::filename_quoting_desired (bool arg)
+ {
+   return (instance_ok ())
+     ? instance->do_filename_quoting_desired (arg) : false;
+ }
+ 
  // Return a string which will be printed as a prompt.  The string may
  // contain special characters which are decoded as follows: 
  //   
*** ./liboctave/oct-rl-edit.h.orig17    2007-10-02 16:38:49.699504882 +0200
--- ./liboctave/oct-rl-edit.h   2007-10-03 23:41:01.320224215 +0200
***************
*** 34,39 ****
--- 34,45 ----
  
  typedef char * (*rl_completer_fcn_ptr) (const char *, int);
  
+ typedef char * (*rl_quoting_fcn_ptr) (char *, int, char *);
+ 
+ typedef char * (*rl_dequoting_fcn_ptr) (char *, int);
+ 
+ typedef int (*rl_char_is_quoted_fcn_ptr) (char *, int);
+ 
  #ifdef __cplusplus
  extern "C"
  {
***************
*** 75,80 ****
--- 81,88 ----
  
  extern int octave_rl_filename_completion_desired (int);
  
+ extern int octave_rl_filename_quoting_desired (int);
+ 
  extern char *octave_rl_filename_completion_function (const char *, int);
  
  extern void octave_rl_set_basic_word_break_characters (const char *);
***************
*** 83,93 ****
--- 91,113 ----
  
  extern void octave_rl_set_basic_quote_characters (const char *);
  
+ extern void octave_rl_set_filename_quote_characters (const char *);
+ 
+ extern void octave_rl_set_completer_quote_characters (const char *);
+ 
  extern void octave_rl_set_completion_append_character (char);
  
  extern void
  octave_rl_set_completion_function (rl_attempted_completion_fcn_ptr);
  
+ extern void
+ octave_rl_set_quoting_function (rl_quoting_fcn_ptr);
+ 
+ extern void
+ octave_rl_set_dequoting_function (rl_dequoting_fcn_ptr);
+ 
+ extern void octave_rl_set_char_is_quoted_function (rl_char_is_quoted_fcn_ptr);
+ 
  extern void octave_rl_set_startup_hook (rl_startup_hook_fcn_ptr);
  
  extern rl_startup_hook_fcn_ptr octave_rl_get_startup_hook (void);
*** ./liboctave/oct-rl-edit.c.orig17    2007-10-02 16:38:53.541310729 +0200
--- ./liboctave/oct-rl-edit.c   2007-10-04 01:05:52.085319712 +0200
***************
*** 196,201 ****
--- 196,209 ----
    return retval;
  }
  
+ int
+ octave_rl_filename_quoting_desired (int arg)
+ {
+   int retval = rl_filename_quoting_desired;
+   rl_filename_quoting_desired = arg;
+   return retval;
+ }
+ 
  char *
  octave_rl_filename_completion_function (const char *text, int state)
  {
***************
*** 227,232 ****
--- 235,256 ----
  }
  
  void
+ octave_rl_set_filename_quote_characters (const char *s)
+ {
+   OCTAVE_RL_SAVE_STRING (ss, s);
+ 
+   rl_filename_quote_characters = ss;
+ }
+ 
+ void
+ octave_rl_set_completer_quote_characters (const char *s)
+ {
+   OCTAVE_RL_SAVE_STRING (ss, s);
+ 
+   rl_completer_quote_characters = ss;
+ }
+ 
+ void
  octave_rl_set_completion_append_character (char c)
  {
    rl_completion_append_character = c;
***************
*** 239,244 ****
--- 263,286 ----
  }
  
  void
+ octave_rl_set_quoting_function (rl_quoting_fcn_ptr f)
+ {
+   rl_filename_quoting_function = f;
+ }
+ 
+ void
+ octave_rl_set_dequoting_function (rl_dequoting_fcn_ptr f)
+ {
+   rl_filename_dequoting_function = f;
+ }
+ 
+ void
+ octave_rl_set_char_is_quoted_function (rl_char_is_quoted_fcn_ptr f)
+ {
+   rl_char_is_quoted_p = f;
+ }
+ 
+ void
  octave_rl_set_startup_hook (rl_startup_hook_fcn_ptr f)
  {
    rl_startup_hook = f;
*** ./src/input.cc.orig17       2007-10-02 16:38:07.992612516 +0200
--- ./src/input.cc      2007-10-04 02:36:23.395895171 +0200
***************
*** 454,459 ****
--- 454,460 ----
  
    static size_t hint_len = 0;
  
+   static int file_index = 0;
    static int list_index = 0;
    static int name_list_len = 0;
    static int name_list_total_len = 0;
***************
*** 476,481 ****
--- 477,484 ----
  
        file_name_list = command_editor::generate_filename_completions (text);
  
+       file_index = name_list.length ();
+ 
        name_list.append (file_name_list);
  
        name_list_total_len = name_list.length ();
***************
*** 507,513 ****
              // FIXME -- 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 '.'.
--- 510,519 ----
              // FIXME -- looks_like_struct is broken for now,
              // so it always returns false.
  
!             if (list_index >= file_index)
!               command_editor::set_completion_append_character
!                 ('"');
!             else if (matches == 1 && looks_like_struct (retval))
                {
                  // Don't append anything, since we don't know
                  // whether it should be '(' or '.'.
***************
*** 526,531 ****
--- 532,606 ----
    return retval;
  }
  
+ static std::string
+ quoting_filename (const std::string &text, int matches)
+ {
+   if (matches == 1)
+     return std::string("'") + text + std::string("'");
+   else
+     return std::string("'") + text;
+ }
+ 
+ static std::string
+ dequoting_filename (const std::string &text, int quote)
+ {
+   std::string ret = text;
+ 
+   for (std::string::iterator it = ret.begin (); it < ret.end (); it++)
+     {
+       if (*it == quote)
+       ret.erase (it); 
+     } 
+ 
+   return ret;
+ }
+ 
+ static int
+ is_char_quoted (const std::string &text, int index)
+ {
+   int i, ret = 0;
+   bool pass_next = false;
+   std::string::const_iterator it;
+ 
+   for (it = text.begin (), i = 0; i <= index; it++, i++)
+     {
+       if (pass_next)
+       {
+         pass_next = false;
+         if (i == index)
+           ret = 1;
+       }
+       else if (*it == '\\')
+       pass_next = true;
+       else if (*it == '\'')
+       {
+         it++;
+         i++;
+         while (*it || *it != '\'')
+           {
+             it++;
+             i++;
+           }
+         if (i > index)
+           ret = 1;
+       }
+       else if (*it == '"')
+       {
+         it++;
+         i++;
+         while (*it && *it != '"')
+           {
+             it++;
+             i++;
+           }
+         if (i > index)
+           ret = 1;
+       }
+     }
+  
+   return ret;
+ }
+ 
  void
  initialize_command_input (void)
  {
***************
*** 545,551 ****
--- 620,635 ----
  
    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);
+ 
+   //command_editor::set_dequoting_function (dequoting_filename);
+ 
+   //command_editor::set_char_is_quoted_function (is_char_quoted);
  }
  
  static bool
***************
*** 1265,1271 ****
    "-*- texinfo -*-\n\
  @deftypefn {Built-in Function} {} __request_drawnow__ ()\n\
  @deftypefnx {Built-in Function} {} __request_drawnow__ (@var{flag})\n\
! Request a call drawnow at the next user prompt.\n\
  @end deftypefn")
  {
    octave_value retval;
--- 1349,1355 ----
    "-*- texinfo -*-\n\
  @deftypefn {Built-in Function} {} __request_drawnow__ ()\n\
  @deftypefnx {Built-in Function} {} __request_drawnow__ (@var{flag})\n\
! Undocumented internal function.\n\
  @end deftypefn")
  {
    octave_value retval;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]