From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31018 invoked by alias); 27 Nov 2001 02:36:45 -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 30987 invoked from network); 27 Nov 2001 02:36:40 -0000 Received: from unknown (HELO cygnus.com) (205.180.230.5) by hostedprojects.ges.redhat.com with SMTP; 27 Nov 2001 02:36:40 -0000 Received: from rtl.cygnus.com (cse.cygnus.com [205.180.230.236]) by runyon.cygnus.com (8.8.7-cygnus/8.8.7) with ESMTP id SAA22758; Mon, 26 Nov 2001 18:36:38 -0800 (PST) Received: (from ezannoni@localhost) by rtl.cygnus.com (8.11.2/8.11.0) id fAR2gvD02280; Mon, 26 Nov 2001 21:42:57 -0500 X-Authentication-Warning: krustylu.cygnus.com: ezannoni set sender to ezannoni@cygnus.com using -f From: Elena Zannoni MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15362.64945.737893.148419@krustylu.cygnus.com> Date: Tue, 13 Nov 2001 09:48:00 -0000 To: tromey@redhat.com CC: gdb-patches@sources.redhat.com Subject: Re: PATCH: operate-and-get-next In-Reply-To: <15362.64511.39505.586347@krustylu.cygnus.com> References: <15362.64511.39505.586347@krustylu.cygnus.com> X-Mailer: VM 6.97 under Emacs 20.7.1 X-SW-Source: 2001-11/txt/msg00255.txt.bz2 Tom Tromey writes: > > > > >>>>> "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 Thanks Tom, yes, please commit it. Elena > > 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 > From mboxrd@z Thu Jan 1 00:00:00 1970 From: Elena Zannoni To: tromey@redhat.com Cc: gdb-patches@sources.redhat.com Subject: Re: PATCH: operate-and-get-next Date: Mon, 26 Nov 2001 18:36:00 -0000 Message-ID: <15362.64945.737893.148419@krustylu.cygnus.com> References: <15362.64511.39505.586347@krustylu.cygnus.com> X-SW-Source: 2001-11/msg00470.html Message-ID: <20011126183600.kF4LOR8vmY4pPoxx_qeCnQMyTws2wKSXmIg-7b-tK2A@z> Tom Tromey writes: > > > > >>>>> "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 Thanks Tom, yes, please commit it. Elena > > 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 >