changeset 36:6315f75c45ae

untested redo of edit
author devlinjs@FA7CZA6N1254998.wrightpatterson.afmc.ds.af.mil
date Fri, 21 Dec 2007 16:35:50 -0500
parents e2a5cdba3113
children 38aa4f49f095
files cmd2.py
diffstat 1 files changed, 28 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/cmd2.py	Fri Dec 21 16:17:06 2007 -0500
+++ b/cmd2.py	Fri Dec 21 16:35:50 2007 -0500
@@ -1,14 +1,17 @@
-"""Variant on standard library's cmd with extra features:
+"""Variant on standard library's cmd with extra features.
 
-Searchable command history
+To use, simply override cmd2.Cmd instead of cmd.Cmd; use precisely as though you
+were using the standard library's cmd, while enjoying the extra features.
+
+Searchable command history (commands: "hi", "li", "run")
+Load commands from file, save to file, edit commands in file
 Multi-line commands
 Case-insensitive commands
-Special-character shortcut commands
-Load commands from file
+Special-character shortcut commands (beyond cmd's "@" and "!")
 Settable environment parameters
 
 todo:
-edit spits eof
+edited commands end with "EOF".  Hmm.
 flags
 >
 """
@@ -243,16 +246,29 @@
     do_li = do_list
 	
     def do_ed(self, arg):
-        'ed [N]: brings up SQL from N commands ago in text editor, and puts result in SQL buffer.'
+        """ed: edit most recent command in text editor
+        ed [N]: edit numbered command from history
+	ed [filename]: edit specified file name
+	
+	commands are run after editor is closed."""
 	if not self.editor:
 	    print "please use 'set editor' to specify your text editing program of choice."
 	    return
-        buffer = self.last_matching(arg)
-        f = open(self.defaultFileName, 'w')
-        f.write(buffer or '')
-        f.close()
-	os.system('%s %s' % (self.editor, self.defaultFileName))
-        self.do_load(self.defaultFileName)
+	filename = self.defaultFileName
+	try:
+	    arg = int(arg)
+	    buffer = self.last_matching(arg)
+	except:
+	    if arg:
+		filename = arg
+	    else:
+		buffer = self.last_matching(arg)
+		f = open(filename, 'w')
+		f.write(buffer or '')
+		f.close()		
+
+	os.system('%s %s' % (self.editor, filename))
+        self.do_load(self.filename)
     do_edit = do_ed
     
     def do_save(self, fname=None):