poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/5] REPL: Fix bug in command line completion.


From: John Darrington
Subject: [PATCH 3/5] REPL: Fix bug in command line completion.
Date: Fri, 21 Feb 2020 17:36:33 +0100

If a command (eg: ".info") was entered on the command line and then
changed, using backspace or similar, then the completer for "info"
remained active, although this was not appropriate.  This change
corrects this behaviour.
---
 ChangeLog     |  5 +++++
 src/pk-repl.c | 27 +++++++++++++++------------
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index aa236add..319c99b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-16  John Darrington <address@hidden>
+
+       * src/pk-repl.c (poke_getc): Revert to poke_completion_function
+       if no complete command is on the repl's command line.
+
 2020-02-16  John Darrington <address@hidden>
 
        * src/pk-editor.c (null_complete_function): delete
diff --git a/src/pk-repl.c b/src/pk-repl.c
index cc1d1b71..36f614d8 100644
--- a/src/pk-repl.c
+++ b/src/pk-repl.c
@@ -145,7 +145,6 @@ poke_completion_function (const char *x, int state)
   return NULL;
 }
 
-
 static char *
 null_completion_function (const char *x, int state)
 {
@@ -164,17 +163,21 @@ poke_getc (FILE *stream)
   strncpy (line_to_point, rl_line_buffer, end);
 
   char *tok = strtok (line_to_point, "\t ");
-  if (rl_completion_entry_function == poke_completion_function)
-    {
-      struct pk_cmd *cmd = pk_cmd_find (tok);
-      if (cmd)
-       {
-         if (cmd->completer)
-           rl_completion_entry_function = cmd->completer;
-         else
-           rl_completion_entry_function = null_completion_function;
-       }
-    }
+  const struct pk_cmd *cmd = pk_cmd_find (tok);
+
+  if (cmd == NULL)
+    rl_completion_entry_function = poke_completion_function;
+
+   if (rl_completion_entry_function == poke_completion_function)
+     {
+       if (cmd)
+        {
+          if (cmd->completer)
+            rl_completion_entry_function = cmd->completer;
+          else
+            rl_completion_entry_function = null_completion_function;
+        }
+     }
   free (line_to_point);
 
   return rl_getc (stream);
-- 
2.20.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]