changeset 28972:a00eca5d6cbe stable

allow auto repeat of debug commands to be disabled * input.h, input.cc (input_system::m_auto_repeat_debug_command): New member variable. (input_system::auto_repeat_debug_command): New functions. (Fauto_repeat_debug_command): New function. * debug.txi: Document new function. * NEWS: Mention new function.
author John W. Eaton <jwe@octave.org>
date Wed, 21 Oct 2020 14:45:40 -0400
parents bcfa15435e4c
children fdb7c296505a 1152256be2cf
files NEWS doc/interpreter/debug.txi libinterp/corefcn/input.cc libinterp/corefcn/input.h
diffstat 4 files changed, 55 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue Oct 20 13:27:38 2020 -0400
+++ b/NEWS	Wed Oct 21 14:45:40 2020 -0400
@@ -206,6 +206,7 @@
 
 ### Alphabetical list of new functions added in Octave 6
 
+* `auto_repeat_debug_command`
 * `commandhistory`
 * `commandwindow`
 * `filebrowser`
--- a/doc/interpreter/debug.txi	Tue Oct 20 13:27:38 2020 -0400
+++ b/doc/interpreter/debug.txi	Wed Oct 21 14:45:40 2020 -0400
@@ -178,7 +178,10 @@
 When in debug mode the @key{RETURN} key will execute the last entered command.
 This is useful, for example, after hitting a breakpoint and entering
 @code{dbstep} once.  After that, one can advance line by line through the code
-with only a single key stroke.
+with only a single key stroke.  This feature may be disabled using the
+@code{auto_repeat_debug_command} function.
+
+@DOCSTRING(auto_repeat_debug_command)
 
 @node Call Stack
 @section Call Stack
--- a/libinterp/corefcn/input.cc	Tue Oct 20 13:27:38 2020 -0400
+++ b/libinterp/corefcn/input.cc	Wed Oct 21 14:45:40 2020 -0400
@@ -410,10 +410,10 @@
   input_system::input_system (interpreter& interp)
     : m_interpreter (interp), m_PS1 (R"(octave:\#> )"), m_PS2 ("> "),
       m_completion_append_char (' '), m_gud_mode (false),
-      m_mfile_encoding ("system"), m_last_debugging_command ("\n"),
-      m_input_event_hook_functions (), m_initialized (false)
-  {
-  }
+      m_mfile_encoding ("system"), m_auto_repeat_debug_command (true),
+      m_last_debugging_command ("\n"), m_input_event_hook_functions (),
+      m_initialized (false)
+  { }
 
   void input_system::initialize (bool line_editing)
   {
@@ -541,6 +541,14 @@
     return retval;
   }
 
+  octave_value
+  input_system::auto_repeat_debug_command (const octave_value_list& args,
+                                           int nargout)
+  {
+    return set_internal_variable (m_auto_repeat_debug_command, args, nargout,
+                                  "auto_repeat_debug_command");
+  }
+
   bool input_system::yes_or_no (const std::string& prompt)
   {
     std::string prompt_string = prompt + "(yes or no) ";
@@ -751,7 +759,7 @@
         else
           input_sys.last_debugging_command ("\n");
       }
-    else if (tw.in_debug_repl ())
+    else if (tw.in_debug_repl () && input_sys.auto_repeat_debug_command ())
       {
         retval = input_sys.last_debugging_command ();
         history_skip_auto_repeated_debugging_command = true;
@@ -1404,6 +1412,25 @@
   return input_sys.mfile_encoding (args, nargout);
 }
 
+DEFMETHOD (auto_repeat_debug_command, interp, args, nargout,
+           doc: /* -*- texinfo -*-
+@deftypefn  {} {@var{val} =} auto_repeat_debug_command ()
+@deftypefnx {} {@var{old_val} =} auto_repeat_debug_command (@var{new_val})
+@deftypefnx {} {} auto_repeat_debug_command (@var{new_val}, "local")
+Query or set the internal variable that controls whether debugging
+commands are automatically repeated when the input line is empty (typing
+just @key{RET}).
+
+When called from inside a function with the @qcode{"local"} option, the
+variable is changed locally for the function and any subroutines it calls.
+The original variable value is restored when exiting the function.
+@end deftypefn */)
+{
+  octave::input_system& input_sys = interp.get_input_system ();
+
+  return input_sys.auto_repeat_debug_command (args, nargout);
+}
+
 // Always define these functions.  The macro is intended to allow the
 // declarations to be hidden, not so that Octave will not provide the
 // functions if they are requested.
--- a/libinterp/corefcn/input.h	Tue Oct 20 13:27:38 2020 -0400
+++ b/libinterp/corefcn/input.h	Wed Oct 21 14:45:40 2020 -0400
@@ -147,6 +147,21 @@
 
     void set_mfile_encoding (const std::string& s) { m_mfile_encoding = s; }
 
+    octave_value
+    auto_repeat_debug_command (const octave_value_list& args, int nargout);
+
+    bool auto_repeat_debug_command (void) const
+    {
+      return m_auto_repeat_debug_command;
+    }
+
+    bool auto_repeat_debug_command (bool val)
+    {
+      bool old_val = m_auto_repeat_debug_command;
+      m_auto_repeat_debug_command = val;
+      return old_val;
+    }
+
     bool yes_or_no (const std::string& prompt);
 
     std::string interactive_input (const std::string& s, bool& eof);
@@ -184,6 +199,9 @@
     // Codepage which is used to read .m files
     std::string m_mfile_encoding;
 
+    // TRUE means repeat last debug command if the user just types RET.
+    bool m_auto_repeat_debug_command;
+
     // If we are in debugging mode, this is the last command entered,
     // so that we can repeat the previous command if the user just
     // types RET.