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: Sun, 07 Oct 2007 23:06:45 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

John W. Eaton wrote:
> On  5-Oct-2007, David Bateman wrote:
> 
> | > Fow now, I think I'd prefer to be able to complete subdirectories.
> |
> | This is what I'm aiming for.. The limitation will be that for
> | subdirectory completion the pathname must be quoted..
> 
> Is there a way to detect that filename completion is in progress and
> temporarily remove the directory separator characters from the list of
> word break characters (if that is what is causing completion be
> restarted after / or \)?
> 
> jwe
> 


Ok, here is my current version of this patch. What it does is add a set
of characters that if they appear in a filename completion, the readline
attempts to add a leading quote (if the string doesn't already have one)
to the filename, It uses a single quote for the filename quoting with
the idea that this is what should be used for raw commands, but respects
any existing quoting with double quotes.

The function that is bound to the Return key is also changed to check if
the returned string needs a terminating quote, and redisplay the string
with any added quotes before calling the rl_newline function that is
normally bound to the return character. This allows the user to type
something like

cd C:\Doc<TAB><RETURN>

and get what you would expect to happen, happen. As mentioned if you
want completion of sub-directories then a leading quote might need to be
added, that is

cd DirOne/DirTw<TAB>

won't complete the directory name as expected, but

cd 'DirOne/DirTw<TAB>

will. Given that "/" and "\" have other meanings than a directory
separation character in Octave, its hard to see how to do better in this
case..

I haven't tested this patch without readline to see what effect this
will have, and so it might breaking building in that case. Is this an issue?

D.

*** ./liboctave/cmd-edit.h.orig17       2007-10-02 16:38:21.677920959 +0200
--- ./liboctave/cmd-edit.h      2007-10-05 13:48:51.887292166 +0200
***************
*** 48,53 ****
--- 48,61 ----
  
    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);
+ 
+   typedef void (*user_accept_line_fcn) (const std::string&);
+ 
    virtual ~command_editor (void) { }
  
    static void set_name (const std::string& n);
***************
*** 84,101 ****
--- 92,131 ----
  
    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 void set_user_accept_line_function (user_accept_line_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 user_accept_line_fcn get_user_accept_line_function (void);
+ 
    static string_vector generate_filename_completions (const std::string& 
text);
  
    static void insert_text (const std::string& text);
  
    static void newline (void);
  
+   static void accept_line (void);
+ 
    static void clear_undo_list (void);
  
    static void add_startup_hook (startup_hook_fcn f);
***************
*** 110,115 ****
--- 140,147 ----
  
    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,209 ****
--- 224,263 ----
  
    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 void do_set_user_accept_line_function (user_accept_line_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 user_accept_line_fcn do_get_user_accept_line_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;
  
    virtual void do_newline (void) = 0;
  
+   virtual void do_accept_line (void) = 0;
+ 
    virtual void do_clear_undo_list (void) { }
  
    virtual void set_startup_hook (startup_hook_fcn) { }
***************
*** 218,223 ****
--- 272,279 ----
  
    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-07 22:04:08.281641050 +0200
***************
*** 107,118 ****
--- 107,138 ----
  
    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);
+ 
+   void do_set_user_accept_line_function (user_accept_line_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;
+ 
+   user_accept_line_fcn do_get_user_accept_line_function (void) const;
+ 
    string_vector
    do_generate_filename_completions (const std::string& text);
  
***************
*** 120,125 ****
--- 140,147 ----
  
    void do_newline (void);
  
+   void do_accept_line (void);
+ 
    void do_clear_undo_list (void);
  
    void set_startup_hook (startup_hook_fcn f);
***************
*** 136,141 ****
--- 158,165 ----
  
    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,163 ****
  
    completion_fcn completion_function;
  
    static char *command_generator (const char *text, int state);
  
    static char **command_completer (const char *text, int start, int end);
  };
  
  gnu_readline::gnu_readline ()
    : command_editor (), previous_startup_hook (0),
!     previous_event_hook (0), completion_function (0)
  {
    // FIXME -- need interface to rl_add_defun, rl_initialize, and
    // a function to set rl_terminal_name
--- 174,204 ----
  
    completion_fcn completion_function;
  
+   quoting_fcn quoting_function;
+ 
+   dequoting_fcn dequoting_function;
+ 
+   char_is_quoted_fcn char_is_quoted_function;
+ 
+   user_accept_line_fcn user_accept_line_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 int command_accept_line (int count, int key);
+ 
    static char **command_completer (const char *text, int start, int end);
  };
  
  gnu_readline::gnu_readline ()
    : command_editor (), previous_startup_hook (0),
!     previous_event_hook (0), completion_function (0),
!     quoting_function (0), dequoting_function (0),
!     char_is_quoted_function (0), user_accept_line_function (0)
  {
    // FIXME -- need interface to rl_add_defun, rl_initialize, and
    // a function to set rl_terminal_name
***************
*** 187,194 ****
                       octave_rl_meta ('N'));
  }
  
- 
- 
  void
  gnu_readline::do_set_name (const std::string& nm)
  {
--- 228,233 ----
***************
*** 319,324 ****
--- 358,375 ----
  }
  
  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 ****
--- 386,467 ----
    ::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);
+ }
+ 
+ void
+ gnu_readline::do_set_user_accept_line_function (user_accept_line_fcn f)
+ {
+   user_accept_line_function = f;
+ 
+   if (f)
+     octave_rl_add_defun ("accept-line", gnu_readline::command_accept_line, 
+                        ::octave_rl_ctrl ('M'));
+   else
+     octave_rl_add_defun ("accept-line", ::octave_rl_newline,
+                        ::octave_rl_ctrl ('M'));
+ }
+ 
  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;
+ }
+ 
+ gnu_readline::user_accept_line_fcn
+ gnu_readline::do_get_user_accept_line_function (void) const
+ {
+   return user_accept_line_function;
+ }
+ 
  string_vector
  gnu_readline::do_generate_filename_completions (const std::string& text)
  {
***************
*** 389,395 ****
  void
  gnu_readline::do_newline (void)
  {
!   ::octave_rl_newline ();
  }
  
  void
--- 510,522 ----
  void
  gnu_readline::do_newline (void)
  {
!   ::octave_rl_newline (1, '\n');
! }
! 
! void
! gnu_readline::do_accept_line (void)
! {
!   command_accept_line (1, '\n');
  }
  
  void
***************
*** 439,450 ****
    return ::octave_rl_filename_completion_desired (arg);
  }
  
  int
  gnu_readline::operate_and_get_next (int /* count */, int /* c */)
  {
    // Accept the current line.
  
!   command_editor::newline ();
  
    // Find the current line, and find the next line to use.
  
--- 566,583 ----
    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 */)
  {
    // Accept the current line.
  
!   command_editor::accept_line ();
  
    // Find the current line, and find the next line to use.
  
***************
*** 497,502 ****
--- 630,698 ----
    return retval;
  }
  
+ char *
+ gnu_readline::command_quoter (char *text, int matches, char *qcp)
+ {
+   char *retval = 0;
+ 
+   quoting_fcn f = command_editor::get_quoting_function ();
+ 
+   std::string tmp = f (text, matches, *qcp);
+ 
+   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);
+ }
+ 
+ int
+ gnu_readline::command_accept_line (int count, int key)
+ {
+   user_accept_line_fcn f = command_editor::get_user_accept_line_function ();
+ 
+   if (f)
+     f (::octave_rl_line_buffer ());
+ 
+   ::octave_rl_redisplay ();
+ 
+   return ::octave_rl_newline (count, key);
+ }
+ 
  char **
  gnu_readline::command_completer (const char *text, int, int)
  {
***************
*** 534,539 ****
--- 730,737 ----
  
    void do_newline (void);
  
+   void do_accept_line (void);
+ 
  private:
  
    FILE *input_stream;
***************
*** 593,598 ****
--- 791,802 ----
    // FIXME
  }
  
+ void
+ default_command_editor::do_accept_line (void)
+ {
+   // FIXME
+ }
+ 
  bool
  command_editor::instance_ok (void)
  {
***************
*** 794,799 ****
--- 998,1017 ----
  }
  
  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 ****
--- 1025,1058 ----
      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);
+ }
+ 
+ void
+ command_editor::set_user_accept_line_function (user_accept_line_fcn f)
+ {
+   if (instance_ok ())
+     instance->do_set_user_accept_line_function (f);
+ }
+ 
  command_editor::completion_fcn
  command_editor::get_completion_function (void)
  {
***************
*** 814,819 ****
--- 1060,1093 ----
      ? 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;
+ }
+ 
+ command_editor::user_accept_line_fcn
+ command_editor::get_user_accept_line_function (void)
+ {
+   return (instance_ok ())
+     ? instance->do_get_user_accept_line_function () : 0;
+ }
+ 
  string_vector
  command_editor::generate_filename_completions (const std::string& text)
  {
***************
*** 836,841 ****
--- 1110,1122 ----
  }
  
  void
+ command_editor::accept_line (void)
+ {
+   if (instance_ok ())
+     instance->do_accept_line ();
+ }
+ 
+ void
  command_editor::clear_undo_list (void)
  {
    if (instance_ok ())
***************
*** 912,917 ****
--- 1193,1205 ----
      ? 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-05 18:21:22.695844414 +0200
***************
*** 34,44 ****
--- 34,54 ----
  
  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);
+ 
+ typedef int (*rl_command_fcn_ptr) (int, int);
+ 
  #ifdef __cplusplus
  extern "C"
  {
  #endif
  
+   extern void octave_rl_redisplay (void);
+ 
  extern int octave_rl_screen_height (void);
  
  extern int octave_rl_screen_width (void);
***************
*** 55,61 ****
  
  extern void octave_rl_insert_text (const char *);
  
! extern void octave_rl_newline (void);
  
  extern void octave_rl_clear_undo_list (void);
  
--- 65,73 ----
  
  extern void octave_rl_insert_text (const char *);
  
! extern int octave_rl_newline (int, int);
! 
! extern const char *octave_rl_line_buffer (void);
  
  extern void octave_rl_clear_undo_list (void);
  
***************
*** 75,80 ****
--- 87,94 ----
  
  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 ****
--- 97,119 ----
  
  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-05 18:21:47.379198582 +0200
***************
*** 47,52 ****
--- 47,58 ----
   \
    strcpy (ss, s)
  
+ void
+ octave_rl_redisplay (void)
+ {
+   rl_redisplay ();
+ }
+ 
  int
  octave_rl_screen_height (void)
  {
***************
*** 118,127 ****
    rl_insert_text (s);
  }
  
! void
! octave_rl_newline (void)
  {
!   rl_newline (1, '\n');
  }
  
  void
--- 124,139 ----
    rl_insert_text (s);
  }
  
! int
! octave_rl_newline (int count, int key)
  {
!   return rl_newline (count, key);
! }
! 
! const char *
! octave_rl_line_buffer (void)
! {
!   return rl_line_buffer;
  }
  
  void
***************
*** 196,201 ****
--- 208,221 ----
    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 ****
--- 247,268 ----
  }
  
  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 ****
--- 275,298 ----
  }
  
  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-05 14:25:52.543275727 +0200
***************
*** 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 '.'.
--- 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 '.'.
***************
*** 526,531 ****
--- 526,565 ----
    return retval;
  }
  
+ static std::string
+ quoting_filename (const std::string &text, int, char quote)
+ {
+   if (quote)
+     return text;
+   else
+     return (std::string ("'") + text);
+ }
+ 
+ static void
+ accept_line (const std::string &text)
+ {
+   // Close open strings if needed
+   bool sq = false;
+   bool dq = false;
+   bool pass_next = false;
+ 
+   for (std::string::const_iterator it = text.begin(); it < text.end(); it++)
+     {
+       if (pass_next)
+       pass_next = false;
+       else if (*it == '\\')
+       pass_next = true;
+       else if (*it == '\'' && ! dq)
+       sq = !sq;
+       else if (*it == '"' && ! sq)
+       dq = !dq;
+     }
+   if (sq)
+     command_editor::insert_text("'");
+   if (dq)
+     command_editor::insert_text("\"");
+ }
+ 
  void
  initialize_command_input (void)
  {
***************
*** 545,551 ****
--- 579,592 ----
  
    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_user_accept_line_function (accept_line);
  }
  
  static bool
2007-10-07  David Bateman  <address@hidden>

        * oct-rl-edit. (typedef rl_quoting_fcn_ptr, rl_dequoting_fcn_ptr,
        rl_char_is_quoted_fcn_ptr, rl_command_fcn_ptr): New  typedefs
        for readline compatible functions.
        (octave_rl_redisplay): Redisplay the current line of text.
        (octave_rl_newline):  Change interface to the same
        as used by the equivalent readline function itself.
        (octave_rl_filename_quoting_desired,
        octave_rl_set_filename_quote_characters,
        octave_rl_set_completer_quote_characters,
        octave_rl_qet_quoting_function, octave_rl_qet_dequoting_function,
        octave_rl_set_char_is_quoted_function): New functions to control
        readline filename quoting and line acceptace.
        * oct-rl-edit.c (octave_rl_newline): Change interface to the same
        as used by the equivalent readline function itself.
        (octave_rl_redisplay): Redisplay the current line of text.
        (octave_rl_filename_quoting_desired,
        octave_rl_set_filename_quote_characters,
        octave_rl_set_completer_quote_characters,
        octave_rl_qet_quoting_function, octave_rl_qet_dequoting_function,
        octave_rl_set_char_is_quoted_function): New functions to control
        readline filename quoting and line acceptace.
        * cmd-edit.h (typedef quoting_fcn, typedef dequoting_fcn,
        typedef char_is_quoted_fcn, user_accept_line_fcn): New typedefs
        to map C++ function to readline compatible functions.
        (set_filename_quote_characters): New function to set the
        characters to if they appear in a filename that force the filename
        to be quoted.
        (set_completer_quote_characters): The characters that the readline
        completion function considers as quotation characters.
        (set_quoting_function, set_dequoting_function,
        set_char_is_quoted_function, set_user_accept_line_function):
        Functions to set the Octave functions to perform quoting and the
        acceptance of a line of text by readline.
        (get_quoting_function, get_dequoting_function,
        get_char_is_quoted_function, get_user_accept_line_function):
        Functions to get the above functions.
        (accept_line): New method for the command_editor to accept a line
        of text.
        (file_quoting_desired): Function to set whether readline should
        attempt to quote filenames.
        (do_set_filename_quoting_characters, 
        do_set_completer_quote_characters, do_set_quoting_function,
        do_set_dequoting_function, do_set_char_is_quoted_function,
        do_set_user_accept_line_function, do_get_quoting_function,
        do_get_dequoting_function, do_get_char_is_quoted_function,
        do_get_user_accept_line_function, do_filename_quoting_desired):
        Virtual functions to control the behavior of readline quoting and
        acceptance of lines.
        (do_accept_line): Virtual function for the accept line function.
        * cmd-edit.cc (class gnu_readline do_set_filename_quote_characters, 
        do_completer_quote_characters, do_set_quoting_function,
        do_set_dequoting_function, do_set_char_is_quoted_function,
        do_set_user_accept_line_function, do_get_quoting_function,
        do_get_dequoting_function, do_get_user_accept_line_function, 
        do_accept_line, do_filename_quoting_desired, command_quoter,
        command_dequoter, command_char_is_quoted, command_accept_line):
        New functions in gnu_readline class to control filename quoting 
        and line acceptance.
        (quoting_function, dequoting_function, char_is_quoted_function,
        user_accept_line_function): private variable to store functions
        supplied for readline quoting and line acceptance.
        (gnu_readline::gnu_readline): Also set the new function pointers
        to zero.
        (gnu_readline::do_newline): Adapt to new octave_rl_newline
        interface.
        (gnu_readeline::operate_and_get_next): Use new accept_line
        function rather than newline.
        (default_ommand_editor::do_accept_line): New method.
        (class command_editor set_filename_quote_characters, 
        set_completer_quote_characters, set_quoting_function,
        set_dequoting_function, set_char_is_quoted_function,
        set_user_accept_line_function, get_quoting_function,
        get_dequoting_function, get_user_accept_line_function, 
        accept_line, filename_quoting_desired): New functions checking
        instance before calling virtual function.

2007-10-07  David Bateman  <address@hidden>

        *  input.cc (quoting_filename): Function to add a leading quote to
        a string if needed.
        (accept_line): Function to check if a string needs a closing quote
        before calling the rl_newline function.
        (initialize_command_input): Initialize completer_quote_characters,
        filename_quote_characters, quoting_function,
        user_accept_line_function.

reply via email to

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