On 4/26/16 2:54 PM, [email protected] wrote:

> I have a short example program that I attached. I haven't added
> SIGWINCH handling yet. You can see that I use siglongjmp to get out of
> the SIGINT handler - a tip I found on stackoverflow - and then I try a
> few miscellaneous Readline cleanup functions. I'm trying to get
> behavior like Bash - ^C should cancel anything I've entered on a line,
> an give me a new prompt. (I notice that GDB has different, somewhat
> annoying behavior, of keeping the input line on ^C)
> 
> The example that I wrote has a bug which both R and Python suffer
> from. The problematic behavior is that when the user hits ^C during a
> reverse-isearch, the last isearch proposal is kept as a "hidden" input.
> 
> For R, I reported this bug in
> <https://bugs.r-project.org/bugzilla/show_bug.cgi?id=16603>.
> 
> I'm a bit curious to know if this bug has always been present, or if
> it appeared with Readline 6.3 or some other recent version.

It's always been present.

You can fix your problem in readline-6.3 and earlier by making your code
look like this:

    if(sigsetjmp(env, 1)) {
        rl_free_line_state ();
        rl_cleanup_after_signal ();

RL_UNSETSTATE(RL_STATE_ISEARCH|RL_STATE_NSEARCH|RL_STATE_VIMOTION|RL_STATE_NUMERICARG|RL_STATE_MULTIKEY);
        rl_done = 1;
        rl_callback_handler_remove ();
        printf("\n");
    }

If you want a little more control, you can replace rl_done = 1 with

rl_line_buffer[rl_point = rl_end = rl_mark = 0] = 0;

That part clears out the line buffer.  The call to UNSETSTATE cleans up the
readline state it uses to keep track of where it is between calls to
rl_callback_read_char().  Without that, readline's state tells it it's
still in the middle of the incremental search.

#ifdef to taste if some of the RL_STATE values aren't defined in the
readline version you're interested in.

Bash is not a good example to look at for this code, since it doesn't use
the callback interface.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    [email protected]    http://cnswww.cns.cwru.edu/~chet/

_______________________________________________
Bug-readline mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-readline

Reply via email to