Re: PATCH: operate-and-get-next

Elena Zannoni
2001-11-27T02:36:45Z

Tom Tromey writes:
>
>
>
> >>>>> "Elena" == Elena Zannoni <ezannoni@cygnus.com> writes:
>
> Elena> Tom, you appended the wrong patch... :-)
>
> Sorry. I must have inserted the wrong file into the buffer.
>
> Elena> Can you resend?
>
> I've appended the correct patch.
> The comments in my previous message apply.
>
> Tom

Thanks Tom, yes, please commit it.

Elena

>
> Index: ChangeLog
> from Tom Tromey <tromey@redhat.com>
>
> * event-loop.c (start_event_loop): Call
> after_char_processing_hook.
> * event-top.h (after_char_processing_hook): Declare.
> * event-top.c (rl_callback_read_char_wrapper): Call
> after_char_processing_hook.
> (after_char_processing_hook): New global.
> * top.c (operate_saved_history): New global.
> (gdb_rl_operate_and_get_next): New function.
> (init_main): Add the operate-and-get-next defun.
> (gdb_rl_operate_and_get_next_completion): New function.
>
> Index: event-loop.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/event-loop.c,v
> retrieving revision 1.16
> diff -u -r1.16 event-loop.c
> --- event-loop.c 2001/03/27 20:36:23 1.16
> +++ event-loop.c 2001/11/07 18:39:50
> @@ -402,6 +402,14 @@
> interface specific, because interfaces can display the
> prompt in their own way. */
> display_gdb_prompt (0);
> + /* This call looks bizarre, but it is required. If the user
> + entered a command that caused an error,
> + after_char_processing_hook won't be called from
> + rl_callback_read_char_wrapper. Using a cleanup there
> + won't work, since we want this function to be called
> + after a new prompt is printed. */
> + if (after_char_processing_hook)
> + (*after_char_processing_hook) ();
> /* Maybe better to set a flag to be checked somewhere as to
> whether display the prompt or not. */
> }
> Index: event-top.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/event-top.c,v
> retrieving revision 1.16
> diff -u -r1.16 event-top.c
> --- event-top.c 2001/08/27 22:39:55 1.16
> +++ event-top.c 2001/11/07 18:39:51
> @@ -153,6 +153,10 @@
> char *linebuffer_ptr;
> }
> readline_input_state;
> +
> +/* This hook is called by rl_callback_read_char_wrapper after each
> + character is processed. */
> +void (*after_char_processing_hook) ();
>
>
> /* Wrapper function for calling into the readline library. The event
> @@ -162,6 +166,8 @@
> rl_callback_read_char_wrapper (gdb_client_data client_data)
> {
> rl_callback_read_char ();
> + if (after_char_processing_hook)
> + (*after_char_processing_hook) ();
> }
>
> /* Initialize all the necessary variables, start the event loop,
> Index: event-top.h
> ===================================================================
> RCS file: /cvs/src/src/gdb/event-top.h,v
> retrieving revision 1.3
> diff -u -r1.3 event-top.h
> --- event-top.h 2001/04/20 14:25:59 1.3
> +++ event-top.h 2001/11/07 18:39:51
> @@ -108,3 +108,4 @@
> extern void (*call_readline) (void *);
> extern void (*input_handler) (char *);
> extern int input_fd;
> +extern void (*after_char_processing_hook) (void);
> Index: top.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/top.c,v
> retrieving revision 1.47
> diff -u -r1.47 top.c
> --- top.c 2001/10/21 19:43:41 1.47
> +++ top.c 2001/11/07 18:39:53
> @@ -1032,6 +1032,52 @@
> #endif
> }
>
> +/* The current saved history number from operate-and-get-next.
> + This is -1 if not valid. */
> +static int operate_saved_history = -1;
> +
> +/* This is put on the appropriate hook and helps operate-and-get-next
> + do its work. */
> +void
> +gdb_rl_operate_and_get_next_completion ()
> +{
> + int delta = where_history () - operate_saved_history;
> + /* The `key' argument to rl_get_previous_history is ignored. */
> + rl_get_previous_history (delta, 0);
> + operate_saved_history = -1;
> +
> + /* readline doesn't automatically update the display for us. */
> + rl_redisplay ();
> +
> + after_char_processing_hook = NULL;
> + rl_pre_input_hook = NULL;
> +}
> +
> +/* This is a gdb-local readline command handler. It accepts the
> + current command line (like RET does) and, if this command was taken
> + from the history, arranges for the next command in the history to
> + appear on the command line when the prompt returns.
> + We ignore the arguments. */
> +static int
> +gdb_rl_operate_and_get_next (int count, int key)
> +{
> + if (event_loop_p)
> + {
> + /* Use the async hook. */
> + after_char_processing_hook = gdb_rl_operate_and_get_next_completion;
> + }
> + else
> + {
> + /* This hook only works correctly when we are using the
> + synchronous readline. */
> + rl_pre_input_hook = (Function *) gdb_rl_operate_and_get_next_completion;
> + }
> +
> + /* Add 1 because we eventually want the next line. */
> + operate_saved_history = where_history () + 1;
> + return rl_newline (1, key);
> +}
> +
> /* Read one line from the command input stream `instream'
> into the local static buffer `linebuffer' (whose current length
> is `linelength').
> @@ -1876,6 +1922,10 @@
> get_gdb_completer_word_break_characters ();
> rl_completer_quote_characters = get_gdb_completer_quote_characters ();
> rl_readline_name = "gdb";
> +
> + /* The name for this defun comes from Bash, where it originated.
> + 15 is Control-o, the same binding this function has in Bash. */
> + rl_add_defun ("operate-and-get-next", gdb_rl_operate_and_get_next, 15);
>
> /* The set prompt command is different depending whether or not the
> async version is run. NOTE: this difference is going to
> Index: doc/ChangeLog
> from Tom Tromey <tromey@redhat.com>
>
> * gdb.texinfo (Command Syntax): Document C-o binding.
>
> Index: doc/gdb.texinfo
> ===================================================================
> RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
> retrieving revision 1.54
> diff -u -r1.54 gdb.texinfo
> --- doc/gdb.texinfo 2001/11/05 23:26:09 1.54
> +++ doc/gdb.texinfo 2001/11/07 18:40:11
> @@ -1190,6 +1190,13 @@
> nothing. This is useful mainly in command files (@pxref{Command
> Files,,Command files}).
>
> +@cindex repeating command sequences
> +@kindex C-o @r{(operate-and-get-next)}
> +The @kbd{C-o} binding is useful for repeating a complex sequence of
> +commands. This command accepts the current line, like @kbd{RET}, and
> +then fetches the next line relative to the current line from the history
> +for editing.
> +
> @node Completion
> @section Command completion
>