public inbox for insight@sourceware.org
 help / color / mirror / Atom feed
* Patch: operate-and-get-next
@ 2001-09-28  9:15 Tom Tromey
  2001-09-28  9:27 ` Keith Seitz
  0 siblings, 1 reply; 10+ messages in thread
From: Tom Tromey @ 2001-09-28  9:15 UTC (permalink / raw)
  To: Insight List

One of my favorite features in Bash is called operate-and-get-next.
This is a readline function bound to Control-o.  It lets you easily
repeat a sequence of commands from history.

What you do is use C-p to find the first command in a sequence.  You
use C-o to execute it (like pressing Enter), and when the next prompt
comes up, the next command from history is already inserted for you.

This makes it really easy to repeat something like a loop or other
complex sequence -- just find the start and hit C-o many times until
it is done.

I still use the Insight console quite a bit, and I really miss this
feature.  So today I implemented it.  The patch is appended.  Is this
ok to commit?

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* library/console.itb (Console::_operate_and_get_next): New method.
	(Console::_setprompt): Insert next history element if requested.
	(Console::_build_win): Bind C-o to _operate_and_get_next.
	* library/console.ith (_operate_and_get_next): Declare.
	(_pendingHistElement): New variable.

Index: library/console.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/console.itb,v
retrieving revision 1.11
diff -u -r1.11 console.itb
--- library/console.itb 2001/06/01 20:05:55 1.11
+++ library/console.itb 2001/09/28 16:12:42
@@ -65,9 +65,6 @@
   #
   bind $_twin <Return> "$this invoke; break"
 
-  # disable this
-  bind_plain_key $_twin Control-o "break"
-
   # History control.
   bind_plain_key $_twin Control-p "[code $this _previous]; break"
   bind $_twin <Up> "[code $this _previous]; break"
@@ -77,7 +74,8 @@
   bind $_twin <Home> "[code $this _first]; break"
   bind $_twin <Meta-greater> "[code $this _last]; break"
   bind $_twin <End> "[code $this _last]; break"
-  
+  bind_plain_key $_twin Control-o "[code $this _operate_and_get_next]; break"
+
   # Tab completion
   bind_plain_key $_twin KeyPress-Tab "[code $this _complete]; break"
   
@@ -244,6 +242,21 @@
 }
 
 #-------------------------------------------------------------------
+#  METHOD:  _operate_and_get_next - Invoke the current command and,
+#           if this command came from the history, arrange for the
+#           next history command to be inserted once this command
+#           is finished.
+# ------------------------------------------------------------------
+body Console::_operate_and_get_next {} {
+  if {$_histElement >= 0} {
+    # _pendingHistElement will be used after the new history element
+    # is pushed.  So we must increment it.
+    set _pendingHistElement [expr {$_histElement + 1}]
+  }
+  invoke
+}
+
+#-------------------------------------------------------------------
 #  METHOD:  _previous - recall the previous command
 # ------------------------------------------------------------------
 body Console::_previous {} {
@@ -368,6 +381,12 @@
   $_twin insert {insert linestart} $prompt prompt_tag
   $_twin mark set cmdmark "insert -1 char"
   $_twin see insert
+
+  if {$_pendingHistElement >= 0} {
+    set _histElement $_pendingHistElement
+    set _pendingHistElement -1
+    _next
+  }
 }
 
 #-------------------------------------------------------------------
Index: library/console.ith
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/console.ith,v
retrieving revision 1.5
diff -u -r1.5 console.ith
--- library/console.ith 2001/05/31 20:32:57 1.5
+++ library/console.ith 2001/09/28 16:12:42
@@ -50,6 +50,7 @@
     variable _saved_insertion ""
     variable _running 0
     variable _saw_tab 0
+    variable _pendingHistElement -1
 
     method _build_win {}
     method _complete {}
@@ -59,6 +60,7 @@
     method _first {}
     method _last {}
     method _next {}
+    method _operate_and_get_next {}
     method _paste {{check_primary 1}}
     method _previous {}
     method _reset_tab {}

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2001-09-28 11:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-28  9:15 Patch: operate-and-get-next Tom Tromey
2001-09-28  9:27 ` Keith Seitz
2001-09-28  9:36   ` Tom Tromey
2001-09-28  9:40     ` Keith Seitz
2001-09-28  9:54   ` John R. Moore
2001-09-28 10:12     ` Tom Tromey
2001-09-28 10:19   ` Tom Tromey
2001-09-28 10:27     ` Keith Seitz
2001-09-28 10:41       ` Tom Tromey
2001-09-28 11:03         ` Keith Seitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).