# HG changeset patch # User John W. Eaton # Date 1364430546 14400 # Node ID 389b09a914e264bbac1d4dacc9c9536265eee079 # Parent f33dcbd6a005f38fbb3664e13bc9bc5620d89c45 allow gui to force readline to return from its idle/read loop * cmd-edit.h, cmd-edit.cc (command_editor::interrupt, command_editor::do_interrupt): New functions. (gnu_readline::do_interrupt): New function. * oct-rl-edit.h, oct-rl-edit.c (octave_rl_done): New function. * main-window.cc (main_window::debug_step_into_callback, main_window::debug_step_over_callback, main_window::debug_step_out_callback): Call command_editor::interrupt. * input.cc (get_debug_input): Reset command_editor::interrutp state. If previous state is true, then exit early. diff --git a/libgui/src/main-window.cc b/libgui/src/main-window.cc --- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -50,6 +50,7 @@ #include "toplev.h" #include "version.h" +#include "cmd-edit.h" #include "cmd-hist.h" #include "oct-env.h" @@ -1215,22 +1216,35 @@ Fdbcont (); } +// The next three callbacks are invoked by GUI buttons. Those buttons +// should only be active when we are doing debugging, which means that +// Octave is waiting for input in get_debug_input. Calling +// command_editor::interrupt will force readline to return even if it +// has not read any input, and then get_debug_input will return, +// allowing the evaluator to continue and execute the next statement. + void main_window::debug_step_into_callback (void) { Fdbstep (ovl ("in")); + + command_editor::interrupt (true); } void main_window::debug_step_over_callback (void) { Fdbstep (); + + command_editor::interrupt (true); } void main_window::debug_step_out_callback (void) { Fdbstep (ovl ("out")); + + command_editor::interrupt (true); } void diff --git a/libinterp/interpfcn/input.cc b/libinterp/interpfcn/input.cc --- a/libinterp/interpfcn/input.cc +++ b/libinterp/interpfcn/input.cc @@ -554,15 +554,20 @@ int retval = curr_parser.run (); - if (retval == 0 && curr_parser.stmt_list) + if (command_editor::interrupt (false)) + break; + else { - curr_parser.stmt_list->accept (*current_evaluator); + if (retval == 0 && curr_parser.stmt_list) + { + curr_parser.stmt_list->accept (*current_evaluator); - if (octave_completion_matches_called) - octave_completion_matches_called = false; + if (octave_completion_matches_called) + octave_completion_matches_called = false; + } + + octave_quit (); } - - octave_quit (); } } diff --git a/liboctave/util/cmd-edit.cc b/liboctave/util/cmd-edit.cc --- a/liboctave/util/cmd-edit.cc +++ b/liboctave/util/cmd-edit.cc @@ -163,6 +163,8 @@ bool do_filename_quoting_desired (bool); + void do_interrupt (bool); + static int operate_and_get_next (int, int); static int history_search_backward (int, int); @@ -587,6 +589,12 @@ return ::octave_rl_filename_quoting_desired (arg); } +void +gnu_readline::do_interrupt (bool arg) +{ + ::octave_rl_done (arg); +} + int gnu_readline::operate_and_get_next (int /* count */, int /* c */) { @@ -1270,6 +1278,26 @@ ? instance->do_filename_quoting_desired (arg) : false; } +bool +command_editor::interrupt (bool arg) +{ + bool retval; + + if (instance_ok ()) + { + // Return the current interrupt state. + retval = instance->interrupted; + + instance->do_interrupt (arg); + + instance->interrupted = arg; + } + else + retval = false; + + return retval; +} + // Return a string which will be printed as a prompt. The string may // contain special characters which are decoded as follows: // diff --git a/liboctave/util/cmd-edit.h b/liboctave/util/cmd-edit.h --- a/liboctave/util/cmd-edit.h +++ b/liboctave/util/cmd-edit.h @@ -37,7 +37,7 @@ protected: command_editor (void) - : command_number (0) { } + : command_number (0), interrupted (false) { } public: @@ -147,6 +147,8 @@ static bool filename_quoting_desired (bool); + static bool interrupt (bool); + static int current_command_number (void); static void reset_current_command_number (int n); @@ -287,6 +289,8 @@ virtual bool do_filename_quoting_desired (bool) { return false; } + virtual void do_interrupt (bool) { } + int read_octal (const std::string& s); void error (int); @@ -295,6 +299,8 @@ // The current command number. int command_number; + + bool interrupted; }; #endif diff --git a/liboctave/util/oct-rl-edit.c b/liboctave/util/oct-rl-edit.c --- a/liboctave/util/oct-rl-edit.c +++ b/liboctave/util/oct-rl-edit.c @@ -218,6 +218,12 @@ return retval; } +void +octave_rl_done (int arg) +{ + rl_done = arg; +} + char * octave_rl_filename_completion_function (const char *text, int state) { diff --git a/liboctave/util/oct-rl-edit.h b/liboctave/util/oct-rl-edit.h --- a/liboctave/util/oct-rl-edit.h +++ b/liboctave/util/oct-rl-edit.h @@ -90,6 +90,8 @@ extern int octave_rl_filename_quoting_desired (int); +extern void octave_rl_done (int); + extern char *octave_rl_filename_completion_function (const char *, int); extern void octave_rl_set_basic_word_break_characters (const char *);