From ce6615816476bf371fd5f660d790721530ed23b3 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sun, 12 Mar 2017 20:11:53 +0530 Subject: [PATCH] Editor support at subprompt --- buku.1 | 3 +++ buku.py | 40 +++++++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/buku.1 b/buku.1 index e37b9f4..15c750d 100644 --- a/buku.1 +++ b/buku.1 @@ -265,6 +265,9 @@ Run a regular expression search. .BI "t" " [...]" Search bookmarks by a tag. List all tags alphabetically, if no arguments. The index of a tag from the tag list can be used to search all bookmarks having the tag. Note that multiple indices and/or ranges do not work in this case. .TP +.BI "w" " [index|editor]" +Edit and add or update a bookmark. +.TP .BI "?" Show help on prompt keys. .TP diff --git a/buku.py b/buku.py index afa90ff..1f161c9 100755 --- a/buku.py +++ b/buku.py @@ -1636,6 +1636,7 @@ keys: d match substrings ('pen' matches 'opened') r expression run a regex search t [...] search bookmarks by a tag or show tag list + w [index|editor] edit and add or update a bookmark (tag list index fetches bookmarks by tag) ? show this help q, ^D, double Enter exit buku @@ -1876,6 +1877,28 @@ def parse_tags(keywords=[]): return delim_wrap(DELIM.join(sorted_tags)) +def edit_at_prompt(obj, nav): + '''Edit and add or update a bookmark + + :param obj: a valid instance of BukuDb class + ''' + + if nav == 'w': + editor = get_system_editor() + if not is_editor_valid(editor): + return + elif is_int(nav[2:]): + obj.edit_update_rec(int(nav[2:])) + return + else: + editor = nav[2:] + + result = edit_rec(editor, '', None, DELIM, None) + if result is not None: + url, title, tags, desc = result + obj.add_rec(url, title, tags, desc) + + def taglist_subprompt(obj, msg, noninteractive=False): '''Additional prompt to show unique tag list @@ -1919,16 +1942,15 @@ def taglist_subprompt(obj, msg, noninteractive=False): elif is_int(nav): print('No matching index %s' % nav) new_results = False - elif is_int(nav[0]): - print('Invalid input') - new_results = False elif nav == 't': new_results = True - continue elif (nav == 'q' or nav == 'd' or nav == '?' or nav.startswith('s ') or nav.startswith('S ') or nav.startswith('r ') or nav.startswith('t ')): return nav + elif nav == 'w' or nav.startswith('w '): + edit_at_prompt(obj, nav) + new_results = False else: print('Invalid input') new_results = False @@ -2017,6 +2039,9 @@ def prompt(obj, results, noninteractive=False, deep=False, subprompt=False): if nav == 'q': return + # No new results fetched beyond this point + new_results = False + # toggle deep search with 'd' if nav == 'd': deep = not deep @@ -2025,16 +2050,17 @@ def prompt(obj, results, noninteractive=False, deep=False, subprompt=False): else: print('deep search off') - new_results = False continue # Show help with '?' if nav == '?': ExtendedArgumentParser.prompt_help(sys.stdout) - new_results = False continue - new_results = False + # Edit and add or update + if nav == 'w' or nav.startswith('w '): + edit_at_prompt(obj, nav) + continue # Nothing to browse if there are no results if not results: