From c7da3f12c36a472ed50c0bbf1da6e6b9389d0a07 Mon Sep 17 00:00:00 2001 From: moculus Date: Sun, 30 Mar 2008 08:20:37 +0000 Subject: [PATCH] feature request for dan and +33 bugfix --HG-- branch : pmacs2 --- application.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/application.py b/application.py index 6208483..c66905e 100755 --- a/application.py +++ b/application.py @@ -812,6 +812,18 @@ if __name__ == "__main__": ciphers = { 'none': open_plain_file, 'aes': open_aes_file } linetypes = { 'win': '\r\n', 'mac': '\r', 'unix': '\n' } + # preprocess args + argv = list(sys.argv[1:]) + goto_line = None + i = 0 + while i < len(argv): + if argv[i] == '-nw': + del argv[i] + elif argv[i].startswith('+'): + goto_line = int(argv.pop(i)) + else: + i += 1 + import optparse parser = optparse.OptionParser() @@ -835,7 +847,7 @@ if __name__ == "__main__": parser.add_option('-m', '--mode', dest='mode', metavar='MODE', help='open arguments in MODE') - (opts, args) = parser.parse_args() + (opts, args) = parser.parse_args(argv) # if debugging, disable error handling to produce backtraces if opts.debug: @@ -843,12 +855,14 @@ if __name__ == "__main__": # we will support using +19 as the first argument to indicate opening the # first file on line 19 (same as -g 19 or --goto 19) - if len(args) > 0 and args[0].startswith('+'): - opts.goto = int(args[0][1:]) - args = args[1:] + if goto_line: + opts.goto = goto_line + #if len(args) > 0 and args[0].startswith('+'): + # opts.goto = int(args[0][1:]) + # args = args[1:] - if opts.goto is not None: - opts.goto += 1 + #if opts.goto is not None: + # opts.goto += 1 # figure out which kind of line types we're using if opts.linetype not in linetypes: