From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28009 invoked by alias); 21 Nov 2001 22:21:39 -0000 Mailing-List: contact gdb-patches-help@sourceware.cygnus.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 27916 invoked from network); 21 Nov 2001 22:21:31 -0000 Received: from unknown (HELO gash2.peakpeak.com) (207.174.178.17) by sourceware.cygnus.com with SMTP; 21 Nov 2001 22:21:31 -0000 Received: from creche.cygnus.com (ta0200.peakpeak.com [204.144.244.200]) by gash2.peakpeak.com (8.9.3/8.9.3) with ESMTP id PAA15561; Wed, 21 Nov 2001 15:21:27 -0700 Received: (from tromey@localhost) by creche.cygnus.com (8.9.3/8.9.3) id PAA18185; Wed, 21 Nov 2001 15:21:42 -0700 To: Elena Zannoni Cc: gdb-patches@sources.redhat.com Subject: Re: PATCH: operate-and-get-next References: <87r8skfh47.fsf@creche.redhat.com> <15300.61266.27769.906320@krustylu.cygnus.com> <87g08nzbho.fsf@creche.redhat.com> <15307.3296.609453.745678@krustylu.cygnus.com> <878zdibdxb.fsf@creche.redhat.com> <15356.8563.526055.897277@krustylu.cygnus.com> X-Zippy: Kids, the seven basic food groups are GUM, PUFF PASTRY, PIZZA, PESTICIDES, ANTIBIOTICS, NUTRA-SWEET and MILK DUDS!! X-Attribution: Tom Reply-To: tromey@redhat.com From: Tom Tromey Date: Thu, 08 Nov 2001 18:22:00 -0000 In-Reply-To: Elena Zannoni's message of "Wed, 21 Nov 2001 16:49:39 -0500" Message-ID: <87g077ix3e.fsf@creche.redhat.com> X-Mailer: Gnus v5.7/Emacs 20.5 X-SW-Source: 2001-11/txt/msg00174.txt.bz2 >>>>> "Elena" == Elena Zannoni 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 Index: ChangeLog from Tom Tromey * 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 * 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