bug-readline
[Top][All Lists]
Advanced

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

Re: bracketed-paste-mode and gdb


From: Andrew Burgess
Subject: Re: bracketed-paste-mode and gdb
Date: Wed, 16 Feb 2022 17:03:41 +0000

Chet Ramey <chet.ramey@case.edu> writes:

> On 2/15/22 12:21 PM, Andrew Burgess wrote:
>
>> I've tried two things, neither seem to quite work, as I don't think I
>> quite have all the information that I need.  I have a rough readline
>> patch below which I think solves the issue, but I'd like to explain
>> what I've tried so far, I'm hoping there might be a solution that
>> doesn't involve changing readline.
>> 
>> My first thought was that I could use rl_deprep_term_function,
>> something like:
>> 
>>    rl_deprep_term_function = gdb_rl_deprep_term_function;
>> 
>>    void
>>    gdb_rl_deprep_term_function ()
>>    {
>>      if (/* Did we just receive eof? */)
>>        printf ("quit\n");
>>      rl_deprep_terminal ();
>>    }
>> 
>> Obviously, I'm struggling with what the if condition should be.
>
> You can test your hypothesis by temporarily using _rl_eof_found as the
> `if' condition.

Interestingly, I notice that rl_deprep_terminal already contains this:

  if (terminal_prepped & TPX_BRACKPASTE)
    {
      fprintf (rl_outstream, BRACK_PASTE_FINI);
      if (_rl_eof_found)
        fprintf (rl_outstream, "\n");
    }

Notice the "\n" - this should have prevented the prompt corruption I'm
seeing, but this doesn't trigger.

[ Note: Though the '\n' would prevent the corruption that we currently
  see, we still wouldn't get exactly the output we want, as the 'quit'
  string would appear on the next line, rather than afte the prompt.

  This is fine, as using rl_deprep_term_function allows us to print the
  'quit' string before that newline is printed, so long was we can know if
  an eof was seen or not.  ]

Turns out that when using the callback interface, _rl_eof_found is not
set true by the time that rl_deprep_terminal is called (in the eof
case).

There's a new patch below that "fixes" _rl_eof_found in the callback
case.  I say "fixes" because I don't claim any great level of expertise
with the readline code, so this is more RFC.

Anyway, with this patch applied you can take the example project from my
first email, and change cb_deprep_terminal like this:

  void
  cb_deprep_terminal (void)
  {
    extern int _rl_eof_found;
  
    if (_rl_eof_found)
      printf ("quit");
  
    rl_deprep_terminal ();
  }

And this works just as well as my original suggestion using a new
RL_STATE_EOF.

I guess, if your suggestion is to go with use _rl_eof_found, then this
would be made part of the public API, and renamed rl_eof_found, right?

Thanks,
Andrew

---

diff --git a/callback.c b/callback.c
index a466cf9..b36f776 100644
--- a/callback.c
+++ b/callback.c
@@ -127,7 +127,7 @@ void
 rl_callback_read_char (void)
 {
   char *line;
-  int eof, jcode;
+  int jcode;
   static procenv_t olevel;
 
   if (rl_linefunc == NULL)
@@ -161,15 +161,15 @@ rl_callback_read_char (void)
       RL_CHECK_SIGNALS ();
       if  (RL_ISSTATE (RL_STATE_ISEARCH))
        {
-         eof = _rl_isearch_callback (_rl_iscxt);
-         if (eof == 0 && (RL_ISSTATE (RL_STATE_ISEARCH) == 0) && RL_ISSTATE 
(RL_STATE_INPUTPENDING))
+         _rl_eof_found = _rl_isearch_callback (_rl_iscxt);
+         if (_rl_eof_found == 0 && (RL_ISSTATE (RL_STATE_ISEARCH) == 0) && 
RL_ISSTATE (RL_STATE_INPUTPENDING))
            rl_callback_read_char ();
 
          CALLBACK_READ_RETURN ();
        }
       else if  (RL_ISSTATE (RL_STATE_NSEARCH))
        {
-         eof = _rl_nsearch_callback (_rl_nscxt);
+         _rl_eof_found = _rl_nsearch_callback (_rl_nscxt);
 
          CALLBACK_READ_RETURN ();
        }
@@ -182,7 +182,7 @@ rl_callback_read_char (void)
 
          k = _rl_callback_data->i2;
 
-         eof = (*_rl_callback_func) (_rl_callback_data);
+         _rl_eof_found = (*_rl_callback_func) (_rl_callback_data);
          /* If the function `deregisters' itself, make sure the data is
             cleaned up. */
          if (_rl_callback_func == 0)   /* XXX - just sanity check */
@@ -206,7 +206,7 @@ rl_callback_read_char (void)
        }
       else if (RL_ISSTATE (RL_STATE_VIMOTION))
        {
-         eof = _rl_vi_domove_callback (_rl_vimvcxt);
+         _rl_eof_found = _rl_vi_domove_callback (_rl_vimvcxt);
          /* Should handle everything, including cleanup, numeric arguments,
             and turning off RL_STATE_VIMOTION */
          if (RL_ISSTATE (RL_STATE_NUMERICARG) == 0)
@@ -217,8 +217,8 @@ rl_callback_read_char (void)
 #endif
       else if (RL_ISSTATE (RL_STATE_NUMERICARG))
        {
-         eof = _rl_arg_callback (_rl_argcxt);
-         if (eof == 0 && (RL_ISSTATE (RL_STATE_NUMERICARG) == 0) && RL_ISSTATE 
(RL_STATE_INPUTPENDING))
+         _rl_eof_found = _rl_arg_callback (_rl_argcxt);
+         if (_rl_eof_found == 0 && (RL_ISSTATE (RL_STATE_NUMERICARG) == 0) && 
RL_ISSTATE (RL_STATE_INPUTPENDING))
            rl_callback_read_char ();
          /* XXX - this should handle _rl_last_command_was_kill better */
          else if (RL_ISSTATE (RL_STATE_NUMERICARG) == 0)
@@ -228,9 +228,9 @@ rl_callback_read_char (void)
        }
       else if (RL_ISSTATE (RL_STATE_MULTIKEY))
        {
-         eof = _rl_dispatch_callback (_rl_kscxt);      /* For now */
-         while ((eof == -1 || eof == -2) && RL_ISSTATE (RL_STATE_MULTIKEY) && 
_rl_kscxt && (_rl_kscxt->flags & KSEQ_DISPATCHED))
-           eof = _rl_dispatch_callback (_rl_kscxt);
+         _rl_eof_found = _rl_dispatch_callback (_rl_kscxt);    /* For now */
+         while ((_rl_eof_found == -1 || _rl_eof_found == -2) && RL_ISSTATE 
(RL_STATE_MULTIKEY) && _rl_kscxt && (_rl_kscxt->flags & KSEQ_DISPATCHED))
+           _rl_eof_found = _rl_dispatch_callback (_rl_kscxt);
          if (RL_ISSTATE (RL_STATE_MULTIKEY) == 0)
            {
              _rl_internal_char_cleanup ();
@@ -245,7 +245,7 @@ rl_callback_read_char (void)
             pointer to a struct that has the argument count originally
             passed to the registering function and space for any additional
             parameters.  */
-         eof = (*_rl_callback_func) (_rl_callback_data);
+         _rl_eof_found = (*_rl_callback_func) (_rl_callback_data);
          /* If the function `deregisters' itself, make sure the data is
             cleaned up. */
          if (_rl_callback_func == 0)
@@ -259,7 +259,7 @@ rl_callback_read_char (void)
            }
        }
       else
-       eof = readline_internal_char ();
+       _rl_eof_found = readline_internal_char ();
 
       RL_CHECK_SIGNALS ();
       if (rl_done == 0 && _rl_want_redisplay)
@@ -270,7 +270,7 @@ rl_callback_read_char (void)
 
       if (rl_done)
        {
-         line = readline_internal_teardown (eof);
+         line = readline_internal_teardown (_rl_eof_found);
 
          if (rl_deprep_term_function)
            (*rl_deprep_term_function) ();




reply via email to

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