From 58e33e2512d9bb27c2de8135f53c6e3f0c562bfd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 4 Apr 2018 08:53:12 +0530 Subject: [PATCH] URL hints: Exclude trailing punctuation from URLs --- kittens/url_hints/main.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/kittens/url_hints/main.py b/kittens/url_hints/main.py index 8c29dc566..970ce9e8f 100644 --- a/kittens/url_hints/main.py +++ b/kittens/url_hints/main.py @@ -158,6 +158,8 @@ def find_urls(pat, line): idx = url.rfind('[') if idx > -1: e -= len(url) - idx + while line[e - 1] in '.,?!' and e > 1: # remove trailing punctuation + e -= 1 yield s, e @@ -213,12 +215,7 @@ def run(args, source_file=None): input(_('No URLs found, press Enter to abort.')) return - try: - run_loop(args, lines, index_map) - except Exception: - import traceback - traceback.print_exc() - input(_('Press Enter to quit')) + run_loop(args, lines, index_map) OPTIONS = partial('''\ @@ -252,6 +249,11 @@ def main(args=sys.argv): args, items = parse_args(args[1:], OPTIONS, '[path to file or omit to use stdin]', msg, 'url_hints') except SystemExit as e: print(e.args[0], file=sys.stderr) - input('Press enter to quit...') + input(_('Press Enter to quit')) return 1 - run(args, (items or [None])[0]) + try: + run(args, (items or [None])[0]) + except Exception: + import traceback + traceback.print_exc() + input(_('Press Enter to quit'))