Mercurial > hg > octave-nkf
comparison liboctave/cmd-edit.cc @ 2941:b779a5b8aed4
[project @ 1997-05-08 02:14:34 by jwe]
author | jwe |
---|---|
date | Thu, 08 May 1997 02:17:52 +0000 |
parents | 66ef74ee5d9f |
children | 467aae13b70a |
comparison
equal
deleted
inserted
replaced
2940:c05d4e1a9bee | 2941:b779a5b8aed4 |
---|---|
66 { | 66 { |
67 public: | 67 public: |
68 | 68 |
69 typedef command_editor::fcn fcn; | 69 typedef command_editor::fcn fcn; |
70 | 70 |
71 typedef command_editor::completion_fcn completion_fcn; | |
72 | |
71 gnu_readline (void); | 73 gnu_readline (void); |
72 | 74 |
73 ~gnu_readline (void) { } | 75 ~gnu_readline (void) { } |
74 | 76 |
75 void do_set_name (const string& n); | 77 void do_set_name (const string& n); |
98 | 100 |
99 void do_set_paren_string_delimiters (const string& s); | 101 void do_set_paren_string_delimiters (const string& s); |
100 | 102 |
101 void do_set_completion_append_character (char c); | 103 void do_set_completion_append_character (char c); |
102 | 104 |
103 void do_set_attempted_completion_function (fcn f); | 105 void do_set_completion_function (completion_fcn f); |
106 | |
107 completion_fcn do_get_completion_function (void) const; | |
104 | 108 |
105 void do_insert_text (const string& text); | 109 void do_insert_text (const string& text); |
106 | 110 |
107 void do_newline (void); | 111 void do_newline (void); |
108 | 112 |
116 | 120 |
117 private: | 121 private: |
118 | 122 |
119 fcn previous_startup_hook; | 123 fcn previous_startup_hook; |
120 | 124 |
121 fcn attempted_completion_function; | 125 completion_fcn completion_function; |
126 | |
127 static char *command_generator (const char *text, int state); | |
128 | |
129 static char **command_completer (char *text, int start, int end); | |
122 }; | 130 }; |
123 | 131 |
124 gnu_readline::gnu_readline () | 132 gnu_readline::gnu_readline () |
125 : command_editor (), previous_startup_hook (0), | 133 : command_editor (), previous_startup_hook (0), completion_function (0) |
126 attempted_completion_function (0) | |
127 { | 134 { |
128 rl_initialize (); | 135 rl_initialize (); |
129 | 136 |
130 do_blink_matching_paren (true); | 137 do_blink_matching_paren (true); |
131 | 138 |
261 { | 268 { |
262 rl_completion_append_character = c; | 269 rl_completion_append_character = c; |
263 } | 270 } |
264 | 271 |
265 void | 272 void |
266 gnu_readline::do_set_attempted_completion_function (fcn f) | 273 gnu_readline::do_set_completion_function (completion_fcn f) |
267 { | 274 { |
268 attempted_completion_function = f; | 275 completion_function = f; |
276 | |
277 typedef char** (*foo) (...); | |
278 | |
279 rl_attempted_completion_function | |
280 = completion_function | |
281 ? static_cast<foo> (gnu_readline::command_completer) : 0; | |
282 } | |
283 | |
284 gnu_readline::completion_fcn | |
285 gnu_readline::do_get_completion_function (void) const | |
286 { | |
287 return completion_function; | |
269 } | 288 } |
270 | 289 |
271 void | 290 void |
272 gnu_readline::do_insert_text (const string& text) | 291 gnu_readline::do_insert_text (const string& text) |
273 { | 292 { |
326 command_history::set_mark (x_where + 1); | 345 command_history::set_mark (x_where + 1); |
327 | 346 |
328 command_editor::set_startup_hook (command_history::goto_mark); | 347 command_editor::set_startup_hook (command_history::goto_mark); |
329 } | 348 } |
330 | 349 |
350 char * | |
351 gnu_readline::command_generator (const char *text, int state) | |
352 { | |
353 char *retval = 0; | |
354 | |
355 completion_fcn f = command_editor::get_completion_function (); | |
356 | |
357 string tmp = f (text, state); | |
358 | |
359 size_t len = tmp.length (); | |
360 | |
361 if (len > 0) | |
362 { | |
363 retval = static_cast<char *> (malloc (len+1)); | |
364 | |
365 strcpy (retval, tmp.c_str ()); | |
366 } | |
367 | |
368 return retval; | |
369 } | |
370 | |
371 char ** | |
372 gnu_readline::command_completer (char *text, int /* start */, int /* end */) | |
373 { | |
374 char **matches = 0; | |
375 matches = completion_matches (text, gnu_readline::command_generator); | |
376 return matches; | |
377 } | |
378 | |
331 #endif | 379 #endif |
332 | 380 |
333 class | 381 class |
334 default_command_editor : public command_editor | 382 default_command_editor : public command_editor |
335 { | 383 { |
414 if (! instance) | 462 if (! instance) |
415 make_command_editor (); | 463 make_command_editor (); |
416 | 464 |
417 if (! instance) | 465 if (! instance) |
418 { | 466 { |
419 (*current_liboctave_error_handler) | 467 current_liboctave_error_handler |
420 ("unable to create command history object!"); | 468 ("unable to create command history object!"); |
421 | 469 |
422 retval = false; | 470 retval = false; |
423 } | 471 } |
424 | 472 |
546 if (instance_ok ()) | 594 if (instance_ok ()) |
547 instance->do_set_completion_append_character (c); | 595 instance->do_set_completion_append_character (c); |
548 } | 596 } |
549 | 597 |
550 void | 598 void |
551 command_editor::set_attempted_completion_function (fcn f) | 599 command_editor::set_completion_function (completion_fcn f) |
552 { | 600 { |
553 if (instance_ok ()) | 601 if (instance_ok ()) |
554 instance->do_set_attempted_completion_function (f); | 602 instance->do_set_completion_function (f); |
603 } | |
604 | |
605 command_editor::completion_fcn | |
606 command_editor::get_completion_function (void) | |
607 { | |
608 return (instance_ok ()) | |
609 ? instance->do_get_completion_function () : 0; | |
555 } | 610 } |
556 | 611 |
557 void | 612 void |
558 command_editor::insert_text (const string& text) | 613 command_editor::insert_text (const string& text) |
559 { | 614 { |
832 } | 887 } |
833 | 888 |
834 void | 889 void |
835 command_editor::error (int err_num) | 890 command_editor::error (int err_num) |
836 { | 891 { |
837 (*current_liboctave_error_handler) ("%s", strerror (err_num)); | 892 current_liboctave_error_handler ("%s", strerror (err_num)); |
838 } | 893 } |
839 | 894 |
840 void | 895 void |
841 command_editor::error (const string& s) | 896 command_editor::error (const string& s) |
842 { | 897 { |
843 (*current_liboctave_error_handler) ("%s", s.c_str ()); | 898 current_liboctave_error_handler ("%s", s.c_str ()); |
844 } | 899 } |
845 | 900 |
846 /* | 901 /* |
847 ;;; Local Variables: *** | 902 ;;; Local Variables: *** |
848 ;;; mode: C++ *** | 903 ;;; mode: C++ *** |