@@ -553,7 +553,6 @@ class Cmd(cmd.Cmd):
553553
554554 # Attributes which ARE dynamically settable at runtime
555555 abbrev = False # Abbreviated commands recognized
556- autorun_on_edit = False # Should files automatically run after editing (doesn't apply to commands)
557556 colors = (platform .system () != 'Windows' )
558557 continuation_prompt = '> '
559558 debug = False
@@ -575,7 +574,6 @@ class Cmd(cmd.Cmd):
575574 # To make an attribute settable with the "do_set" command, add it to this ...
576575 # This starts out as a dictionary but gets converted to an OrderedDict sorted alphabetically by key
577576 settable = {'abbrev' : 'Accept abbreviated commands' ,
578- 'autorun_on_edit' : 'Automatically run files after editing' ,
579577 'colors' : 'Colorized output (*nix only)' ,
580578 'continuation_prompt' : 'On 2nd+ line of input' ,
581579 'debug' : 'Show full error stack on error' ,
@@ -1773,95 +1771,25 @@ def do_history(self, args):
17731771 else :
17741772 self .poutput (hi .pr ())
17751773
1776- def _last_matching (self , arg ):
1777- """Return the last item from the history list that matches arg. Or if arg not provided, return last item.
1778-
1779- If not match is found, return None.
1780-
1781- :param arg: str - text to search for in history
1782- :return: str - last match, last item, or None, depending on arg.
1783- """
1784- try :
1785- if arg :
1786- return self .history .get (arg )[- 1 ]
1787- else :
1788- return self .history [- 1 ]
1789- except IndexError :
1790- return None
17911774
17921775 @with_argument_list
17931776 def do_edit (self , arglist ):
17941777 """Edit a file or command in a text editor.
17951778
1796- Usage: edit [N]|[ file_path]
1779+ Usage: edit [file_path]
17971780 Where:
1798- * N - Number of command (from history), or `*` for all commands in history
1799- (default: last command)
18001781 * file_path - path to a file to open in editor
18011782
18021783The editor used is determined by the ``editor`` settable parameter.
18031784"set editor (program-name)" to change or set the EDITOR environment variable.
1804-
1805- The optional arguments are mutually exclusive. Either a command number OR a file name can be supplied.
1806- If neither is supplied, the most recent command in the history is edited.
1807-
1808- Edited commands are always run after the editor is closed.
1809-
1810- Edited files are run on close if the ``autorun_on_edit`` settable parameter is True.
18111785"""
18121786 if not self .editor :
18131787 raise EnvironmentError ("Please use 'set editor' to specify your text editing program of choice." )
1814- filename = None
1815- if arglist and arglist [0 ]:
1816- try :
1817- # Try to convert argument to an integer
1818- history_idx = int (arglist [0 ])
1819- except ValueError :
1820- # Argument passed is not convertible to an integer, so treat it as a file path
1821- filename = arglist [0 ]
1822- history_item = ''
1823- else :
1824- # Argument passed IS convertible to an integer, so treat it as a history index
1825-
1826- # Save off original index for pringing
1827- orig_indx = history_idx
1828-
1829- # Convert negative index into equivalent positive one
1830- if history_idx < 0 :
1831- history_idx += len (self .history ) + 1
1832-
1833- # Make sure the index is actually within the history
1834- if 1 <= history_idx <= len (self .history ):
1835- history_item = self ._last_matching (history_idx )
1836- else :
1837- self .perror ('index {!r} does not exist within the history' .format (orig_indx ), traceback_war = False )
1838- return
1839-
1788+ filename = arglist [0 ] if arglist else ''
1789+ if filename :
1790+ os .system ('"{}" "{}"' .format (self .editor , filename ))
18401791 else :
1841- try :
1842- history_item = self .history [- 1 ]
1843- except IndexError :
1844- self .perror ('edit must be called with argument if history is empty' , traceback_war = False )
1845- return
1846-
1847- delete_tempfile = False
1848- if history_item :
1849- if filename is None :
1850- fd , filename = tempfile .mkstemp (suffix = '.txt' , text = True )
1851- os .close (fd )
1852- delete_tempfile = True
1853-
1854- f = open (os .path .expanduser (filename ), 'w' )
1855- f .write (history_item or '' )
1856- f .close ()
1857-
1858- os .system ('"{}" "{}"' .format (self .editor , filename ))
1859-
1860- if self .autorun_on_edit or history_item :
1861- self .do_load (filename )
1862-
1863- if delete_tempfile :
1864- os .remove (filename )
1792+ os .system ('"{}"' .format (self .editor ))
18651793
18661794 @property
18671795 def _current_script_dir (self ):
0 commit comments