avoid exiting during substitution
@@ -510,6 +510,7 @@ class InteractivePrompt(app.controller.Controller):
return {}, 'making stuff'
def execute(self):
+ try:
cmdLine = ''
try: cmdLine = self.textBuffer.lines[0]
except: pass
@@ -544,6 +545,8 @@ class InteractivePrompt(app.controller.Controller):
command = self.commands.get(cmd, self.unknownCommand)
results, message = command(cmdLine, self.host)
tb.setMessage(message)
+ except:
+ tb.setMessage('Execution threw an error.')
self.changeToHostWindow()
def shellExecute(self, commands, input):
@@ -591,11 +594,20 @@ class InteractivePrompt(app.controller.Controller):
def substituteText(self, cmdLine, lines):
if len(cmdLine) < 2:
- return
+ return lines, '''tip: %s/foo/bar/ to replace 'foo' with 'bar'.''' % (
+ cmdLine,)
if not lines:
- return [], 'No text was selected.'
- separator = cmdLine[0]
+ return lines, 'No text was selected.'
+ sre = re.match('\w+(\W)', cmdLine)
+ if not sre:
+ return lines, '''Separator punctuation missing, example:''' \
+ ''' %s/foo/bar/''' % (cmdLine,)
+ separator = sre.groups()[0]
+ try:
a, find, replace, flags = cmdLine.split(separator, 3)
+ except:
+ return lines, '''Separator punctuation missing, there should be''' \
+ ''' three '%s'.''' % (separator,)
data = self.host.textBuffer.doLinesToData(lines)
output = self.host.textBuffer.findReplaceText(find, replace, flags, data)
lines = self.host.textBuffer.doDataToLines(output)
