changeset 28708:91f0ee715701

maint: merge stable to default.
author John W. Eaton <jwe@octave.org>
date Thu, 10 Sep 2020 11:46:41 -0400
parents 0c9a5eae6c27 (current diff) f0a3f4527ba6 (diff)
children 9dc9f15dac64
files libinterp/corefcn/input.cc libinterp/corefcn/input.h
diffstat 2 files changed, 22 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/input.cc	Thu Sep 03 13:36:05 2020 +0200
+++ b/libinterp/corefcn/input.cc	Thu Sep 10 11:46:41 2020 -0400
@@ -391,6 +391,18 @@
     return retval;
   }
 
+  static int internal_input_event_hook_fcn (void)
+  {
+    octave_quit ();
+
+    input_system& input_sys
+      = __get_input_system__ ("internal_input_event_hook_fcn");
+
+    input_sys.run_input_event_hooks ();
+
+    return 0;
+  }
+
   // Use literal "octave" in default setting for PS1 instead of
   // "\\s" to avoid setting the prompt to "octave.exe" or
   // "octave-gui", etc.
@@ -399,12 +411,15 @@
     : 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_input_event_hook_functions (), m_initialized (false)
   {
   }
 
   void input_system::initialize (bool line_editing)
   {
+    if (m_initialized)
+      return;
+
     // Force default line editor if we don't want readline editing.
     if (! line_editing)
       {
@@ -435,6 +450,10 @@
     command_editor::set_completion_function (generate_completion);
 
     command_editor::set_quoting_function (quoting_filename);
+
+    command_editor::add_event_hook (internal_input_event_hook_fcn);
+
+    m_initialized = true;
   }
 
   octave_value
@@ -1188,22 +1207,6 @@
   return ovl ();
 }
 
-namespace octave
-{
-  static int internal_input_event_hook_fcn (void)
-  {
-    input_system& input_sys
-      = __get_input_system__ ("internal_input_event_hook_fcn");
-
-    input_sys.run_input_event_hooks ();
-
-    if (! input_sys.have_input_event_hooks ())
-      command_editor::remove_event_hook (internal_input_event_hook_fcn);
-
-    return 0;
-  }
-}
-
 DEFMETHOD (add_input_event_hook, interp, args, ,
            doc: /* -*- texinfo -*-
 @deftypefn  {} {@var{id} =} add_input_event_hook (@var{fcn})
@@ -1238,9 +1241,6 @@
 
   hook_function hook_fcn (args(0), user_data);
 
-  if (! input_sys.have_input_event_hooks ())
-    octave::command_editor::add_event_hook (octave::internal_input_event_hook_fcn);
-
   input_sys.add_input_event_hook (hook_fcn);
 
   return ovl (hook_fcn.id ());
@@ -1271,9 +1271,6 @@
     warning ("remove_input_event_hook: %s not found in list",
              hook_fcn_id.c_str ());
 
-  if (! input_sys.have_input_event_hooks ())
-    octave::command_editor::remove_event_hook (octave::internal_input_event_hook_fcn);
-
   return ovl ();
 }
 
--- a/libinterp/corefcn/input.h	Thu Sep 03 13:36:05 2020 +0200
+++ b/libinterp/corefcn/input.h	Thu Sep 10 11:46:41 2020 -0400
@@ -191,6 +191,8 @@
 
     hook_function_list m_input_event_hook_functions;
 
+    bool m_initialized;
+
     std::string gnu_readline (const std::string& s, bool& eof) const;
   };