comparison liboctave/cmd-edit.cc @ 6979:2883ea1c5c18

[project @ 2007-10-08 20:23:48 by dbateman]
author dbateman
date Mon, 08 Oct 2007 20:26:01 +0000
parents cf41866340d3
children 93c65f2a5668
comparison
equal deleted inserted replaced
6978:b75630794a11 6979:2883ea1c5c18
105 105
106 void do_set_completer_word_break_characters (const std::string& s); 106 void do_set_completer_word_break_characters (const std::string& s);
107 107
108 void do_set_basic_quote_characters (const std::string& s); 108 void do_set_basic_quote_characters (const std::string& s);
109 109
110 void do_set_filename_quote_characters (const std::string& s);
111
112 void do_set_completer_quote_characters (const std::string& s);
113
110 void do_set_completion_append_character (char c); 114 void do_set_completion_append_character (char c);
111 115
112 void do_set_completion_function (completion_fcn f); 116 void do_set_completion_function (completion_fcn f);
113 117
118 void do_set_quoting_function (quoting_fcn f);
119
120 void do_set_dequoting_function (dequoting_fcn f);
121
122 void do_set_char_is_quoted_function (char_is_quoted_fcn f);
123
124 void do_set_user_accept_line_function (user_accept_line_fcn f);
125
114 completion_fcn do_get_completion_function (void) const; 126 completion_fcn do_get_completion_function (void) const;
127
128 quoting_fcn do_get_quoting_function (void) const;
129
130 dequoting_fcn do_get_dequoting_function (void) const;
131
132 char_is_quoted_fcn do_get_char_is_quoted_function (void) const;
133
134 user_accept_line_fcn do_get_user_accept_line_function (void) const;
115 135
116 string_vector 136 string_vector
117 do_generate_filename_completions (const std::string& text); 137 do_generate_filename_completions (const std::string& text);
118 138
119 void do_insert_text (const std::string& text); 139 void do_insert_text (const std::string& text);
120 140
121 void do_newline (void); 141 void do_newline (void);
122 142
143 void do_accept_line (void);
144
123 void do_clear_undo_list (void); 145 void do_clear_undo_list (void);
124 146
125 void set_startup_hook (startup_hook_fcn f); 147 void set_startup_hook (startup_hook_fcn f);
126 148
127 void restore_startup_hook (void); 149 void restore_startup_hook (void);
134 156
135 void do_read_init_file (const std::string& file); 157 void do_read_init_file (const std::string& file);
136 158
137 bool do_filename_completion_desired (bool); 159 bool do_filename_completion_desired (bool);
138 160
161 bool do_filename_quoting_desired (bool);
162
139 static int operate_and_get_next (int, int); 163 static int operate_and_get_next (int, int);
140 164
141 static int history_search_backward (int, int); 165 static int history_search_backward (int, int);
142 166
143 static int history_search_forward (int, int); 167 static int history_search_forward (int, int);
148 172
149 event_hook_fcn previous_event_hook; 173 event_hook_fcn previous_event_hook;
150 174
151 completion_fcn completion_function; 175 completion_fcn completion_function;
152 176
177 quoting_fcn quoting_function;
178
179 dequoting_fcn dequoting_function;
180
181 char_is_quoted_fcn char_is_quoted_function;
182
183 user_accept_line_fcn user_accept_line_function;
184
153 static char *command_generator (const char *text, int state); 185 static char *command_generator (const char *text, int state);
186
187 static char *command_quoter (char *text, int match_type, char *quote_pointer);
188 static char *command_dequoter (char *text, int match_type);
189
190 static int command_char_is_quoted (char *text, int index);
191
192 static int command_accept_line (int count, int key);
154 193
155 static char **command_completer (const char *text, int start, int end); 194 static char **command_completer (const char *text, int start, int end);
156 }; 195 };
157 196
158 gnu_readline::gnu_readline () 197 gnu_readline::gnu_readline ()
159 : command_editor (), previous_startup_hook (0), 198 : command_editor (), previous_startup_hook (0),
160 previous_event_hook (0), completion_function (0) 199 previous_event_hook (0), completion_function (0),
200 quoting_function (0), dequoting_function (0),
201 char_is_quoted_function (0), user_accept_line_function (0)
161 { 202 {
162 // FIXME -- need interface to rl_add_defun, rl_initialize, and 203 // FIXME -- need interface to rl_add_defun, rl_initialize, and
163 // a function to set rl_terminal_name 204 // a function to set rl_terminal_name
164 205
165 std::string term = octave_env::getenv ("TERM"); 206 std::string term = octave_env::getenv ("TERM");
184 225
185 octave_rl_add_defun ("history-search-forward", 226 octave_rl_add_defun ("history-search-forward",
186 gnu_readline::history_search_forward, 227 gnu_readline::history_search_forward,
187 octave_rl_meta ('N')); 228 octave_rl_meta ('N'));
188 } 229 }
189
190
191 230
192 void 231 void
193 gnu_readline::do_set_name (const std::string& nm) 232 gnu_readline::do_set_name (const std::string& nm)
194 { 233 {
195 ::octave_rl_set_name (nm.c_str ()); 234 ::octave_rl_set_name (nm.c_str ());
317 { 356 {
318 ::octave_rl_set_basic_quote_characters (s.c_str ()); 357 ::octave_rl_set_basic_quote_characters (s.c_str ());
319 } 358 }
320 359
321 void 360 void
361 gnu_readline::do_set_filename_quote_characters (const std::string& s)
362 {
363 ::octave_rl_set_filename_quote_characters (s.c_str ());
364 }
365
366 void
367 gnu_readline::do_set_completer_quote_characters (const std::string& s)
368 {
369 ::octave_rl_set_completer_quote_characters (s.c_str ());
370 }
371
372 void
322 gnu_readline::do_set_completion_append_character (char c) 373 gnu_readline::do_set_completion_append_character (char c)
323 { 374 {
324 ::octave_rl_set_completion_append_character (c); 375 ::octave_rl_set_completion_append_character (c);
325 } 376 }
326 377
333 = f ? gnu_readline::command_completer : 0; 384 = f ? gnu_readline::command_completer : 0;
334 385
335 ::octave_rl_set_completion_function (fp); 386 ::octave_rl_set_completion_function (fp);
336 } 387 }
337 388
389 void
390 gnu_readline::do_set_quoting_function (quoting_fcn f)
391 {
392 quoting_function = f;
393
394 rl_quoting_fcn_ptr fp
395 = f ? gnu_readline::command_quoter : 0;
396
397 ::octave_rl_set_quoting_function (fp);
398 }
399
400 void
401 gnu_readline::do_set_dequoting_function (dequoting_fcn f)
402 {
403 dequoting_function = f;
404
405 rl_dequoting_fcn_ptr fp
406 = f ? gnu_readline::command_dequoter : 0;
407
408 ::octave_rl_set_dequoting_function (fp);
409 }
410
411 void
412 gnu_readline::do_set_char_is_quoted_function (char_is_quoted_fcn f)
413 {
414 char_is_quoted_function = f;
415
416 rl_char_is_quoted_fcn_ptr fp
417 = f ? gnu_readline::command_char_is_quoted : 0;
418
419 ::octave_rl_set_char_is_quoted_function (fp);
420 }
421
422 void
423 gnu_readline::do_set_user_accept_line_function (user_accept_line_fcn f)
424 {
425 user_accept_line_function = f;
426
427 if (f)
428 octave_rl_add_defun ("accept-line", gnu_readline::command_accept_line,
429 ::octave_rl_ctrl ('M'));
430 else
431 octave_rl_add_defun ("accept-line", ::octave_rl_newline,
432 ::octave_rl_ctrl ('M'));
433 }
434
338 gnu_readline::completion_fcn 435 gnu_readline::completion_fcn
339 gnu_readline::do_get_completion_function (void) const 436 gnu_readline::do_get_completion_function (void) const
340 { 437 {
341 return completion_function; 438 return completion_function;
439 }
440
441 gnu_readline::quoting_fcn
442 gnu_readline::do_get_quoting_function (void) const
443 {
444 return quoting_function;
445 }
446
447 gnu_readline::dequoting_fcn
448 gnu_readline::do_get_dequoting_function (void) const
449 {
450 return dequoting_function;
451 }
452
453 gnu_readline::char_is_quoted_fcn
454 gnu_readline::do_get_char_is_quoted_function (void) const
455 {
456 return char_is_quoted_function;
457 }
458
459 gnu_readline::user_accept_line_fcn
460 gnu_readline::do_get_user_accept_line_function (void) const
461 {
462 return user_accept_line_function;
342 } 463 }
343 464
344 string_vector 465 string_vector
345 gnu_readline::do_generate_filename_completions (const std::string& text) 466 gnu_readline::do_generate_filename_completions (const std::string& text)
346 { 467 {
387 } 508 }
388 509
389 void 510 void
390 gnu_readline::do_newline (void) 511 gnu_readline::do_newline (void)
391 { 512 {
392 ::octave_rl_newline (); 513 ::octave_rl_newline (1, '\n');
514 }
515
516 void
517 gnu_readline::do_accept_line (void)
518 {
519 command_accept_line (1, '\n');
393 } 520 }
394 521
395 void 522 void
396 gnu_readline::do_clear_undo_list () 523 gnu_readline::do_clear_undo_list ()
397 { 524 {
437 gnu_readline::do_filename_completion_desired (bool arg) 564 gnu_readline::do_filename_completion_desired (bool arg)
438 { 565 {
439 return ::octave_rl_filename_completion_desired (arg); 566 return ::octave_rl_filename_completion_desired (arg);
440 } 567 }
441 568
569 bool
570 gnu_readline::do_filename_quoting_desired (bool arg)
571 {
572 return ::octave_rl_filename_quoting_desired (arg);
573 }
574
442 int 575 int
443 gnu_readline::operate_and_get_next (int /* count */, int /* c */) 576 gnu_readline::operate_and_get_next (int /* count */, int /* c */)
444 { 577 {
445 // Accept the current line. 578 // Accept the current line.
446 579
447 command_editor::newline (); 580 command_editor::accept_line ();
448 581
449 // Find the current line, and find the next line to use. 582 // Find the current line, and find the next line to use.
450 583
451 int x_where = command_history::where (); 584 int x_where = command_history::where ();
452 585
495 } 628 }
496 629
497 return retval; 630 return retval;
498 } 631 }
499 632
633 char *
634 gnu_readline::command_quoter (char *text, int matches, char *qcp)
635 {
636 char *retval = 0;
637
638 quoting_fcn f = command_editor::get_quoting_function ();
639
640 std::string tmp = f (text, matches, *qcp);
641
642 size_t len = tmp.length ();
643
644 if (len > 0)
645 {
646 retval = static_cast<char *> (malloc (len+1));
647
648 strcpy (retval, tmp.c_str ());
649 }
650
651 return retval;
652 }
653
654 char *
655 gnu_readline::command_dequoter (char *text, int quote)
656 {
657 char *retval = 0;
658
659 dequoting_fcn f = command_editor::get_dequoting_function ();
660
661 std::string tmp = f (text, quote);
662
663 size_t len = tmp.length ();
664
665 if (len > 0)
666 {
667 retval = static_cast<char *> (malloc (len+1));
668
669 strcpy (retval, tmp.c_str ());
670 }
671
672 return retval;
673 }
674
675 int
676 gnu_readline::command_char_is_quoted (char *text, int quote)
677 {
678 char_is_quoted_fcn f = command_editor::get_char_is_quoted_function ();
679
680 return f (text, quote);
681 }
682
683 int
684 gnu_readline::command_accept_line (int count, int key)
685 {
686 user_accept_line_fcn f = command_editor::get_user_accept_line_function ();
687
688 if (f)
689 f (::octave_rl_line_buffer ());
690
691 ::octave_rl_redisplay ();
692
693 return ::octave_rl_newline (count, key);
694 }
695
500 char ** 696 char **
501 gnu_readline::command_completer (const char *text, int, int) 697 gnu_readline::command_completer (const char *text, int, int)
502 { 698 {
503 char **matches = 0; 699 char **matches = 0;
504 matches 700 matches
532 728
533 void do_insert_text (const std::string&); 729 void do_insert_text (const std::string&);
534 730
535 void do_newline (void); 731 void do_newline (void);
536 732
733 void do_accept_line (void);
734
537 private: 735 private:
538 736
539 FILE *input_stream; 737 FILE *input_stream;
540 738
541 FILE *output_stream; 739 FILE *output_stream;
587 // FIXME 785 // FIXME
588 } 786 }
589 787
590 void 788 void
591 default_command_editor::do_newline (void) 789 default_command_editor::do_newline (void)
790 {
791 // FIXME
792 }
793
794 void
795 default_command_editor::do_accept_line (void)
592 { 796 {
593 // FIXME 797 // FIXME
594 } 798 }
595 799
596 bool 800 bool
792 if (instance_ok ()) 996 if (instance_ok ())
793 instance->do_set_basic_quote_characters (s); 997 instance->do_set_basic_quote_characters (s);
794 } 998 }
795 999
796 void 1000 void
1001 command_editor::set_filename_quote_characters (const std::string& s)
1002 {
1003 if (instance_ok ())
1004 instance->do_set_filename_quote_characters (s);
1005 }
1006
1007 void
1008 command_editor::set_completer_quote_characters (const std::string& s)
1009 {
1010 if (instance_ok ())
1011 instance->do_set_completer_quote_characters (s);
1012 }
1013
1014 void
797 command_editor::set_completion_append_character (char c) 1015 command_editor::set_completion_append_character (char c)
798 { 1016 {
799 if (instance_ok ()) 1017 if (instance_ok ())
800 instance->do_set_completion_append_character (c); 1018 instance->do_set_completion_append_character (c);
801 } 1019 }
803 void 1021 void
804 command_editor::set_completion_function (completion_fcn f) 1022 command_editor::set_completion_function (completion_fcn f)
805 { 1023 {
806 if (instance_ok ()) 1024 if (instance_ok ())
807 instance->do_set_completion_function (f); 1025 instance->do_set_completion_function (f);
1026 }
1027
1028 void
1029 command_editor::set_quoting_function (quoting_fcn f)
1030 {
1031 if (instance_ok ())
1032 instance->do_set_quoting_function (f);
1033 }
1034
1035 void
1036 command_editor::set_dequoting_function (dequoting_fcn f)
1037 {
1038 if (instance_ok ())
1039 instance->do_set_dequoting_function (f);
1040 }
1041
1042 void
1043 command_editor::set_char_is_quoted_function (char_is_quoted_fcn f)
1044 {
1045 if (instance_ok ())
1046 instance->do_set_char_is_quoted_function (f);
1047 }
1048
1049 void
1050 command_editor::set_user_accept_line_function (user_accept_line_fcn f)
1051 {
1052 if (instance_ok ())
1053 instance->do_set_user_accept_line_function (f);
808 } 1054 }
809 1055
810 command_editor::completion_fcn 1056 command_editor::completion_fcn
811 command_editor::get_completion_function (void) 1057 command_editor::get_completion_function (void)
812 { 1058 {
813 return (instance_ok ()) 1059 return (instance_ok ())
814 ? instance->do_get_completion_function () : 0; 1060 ? instance->do_get_completion_function () : 0;
815 } 1061 }
816 1062
1063 command_editor::quoting_fcn
1064 command_editor::get_quoting_function (void)
1065 {
1066 return (instance_ok ())
1067 ? instance->do_get_quoting_function () : 0;
1068 }
1069
1070 command_editor::dequoting_fcn
1071 command_editor::get_dequoting_function (void)
1072 {
1073 return (instance_ok ())
1074 ? instance->do_get_dequoting_function () : 0;
1075 }
1076
1077 command_editor::char_is_quoted_fcn
1078 command_editor::get_char_is_quoted_function (void)
1079 {
1080 return (instance_ok ())
1081 ? instance->do_get_char_is_quoted_function () : 0;
1082 }
1083
1084 command_editor::user_accept_line_fcn
1085 command_editor::get_user_accept_line_function (void)
1086 {
1087 return (instance_ok ())
1088 ? instance->do_get_user_accept_line_function () : 0;
1089 }
1090
817 string_vector 1091 string_vector
818 command_editor::generate_filename_completions (const std::string& text) 1092 command_editor::generate_filename_completions (const std::string& text)
819 { 1093 {
820 return (instance_ok ()) 1094 return (instance_ok ())
821 ? instance->do_generate_filename_completions (text) : string_vector (); 1095 ? instance->do_generate_filename_completions (text) : string_vector ();
831 void 1105 void
832 command_editor::newline (void) 1106 command_editor::newline (void)
833 { 1107 {
834 if (instance_ok ()) 1108 if (instance_ok ())
835 instance->do_newline (); 1109 instance->do_newline ();
1110 }
1111
1112 void
1113 command_editor::accept_line (void)
1114 {
1115 if (instance_ok ())
1116 instance->do_accept_line ();
836 } 1117 }
837 1118
838 void 1119 void
839 command_editor::clear_undo_list (void) 1120 command_editor::clear_undo_list (void)
840 { 1121 {
908 bool 1189 bool
909 command_editor::filename_completion_desired (bool arg) 1190 command_editor::filename_completion_desired (bool arg)
910 { 1191 {
911 return (instance_ok ()) 1192 return (instance_ok ())
912 ? instance->do_filename_completion_desired (arg) : false; 1193 ? instance->do_filename_completion_desired (arg) : false;
1194 }
1195
1196 bool
1197 command_editor::filename_quoting_desired (bool arg)
1198 {
1199 return (instance_ok ())
1200 ? instance->do_filename_quoting_desired (arg) : false;
913 } 1201 }
914 1202
915 // Return a string which will be printed as a prompt. The string may 1203 // Return a string which will be printed as a prompt. The string may
916 // contain special characters which are decoded as follows: 1204 // contain special characters which are decoded as follows:
917 // 1205 //