From c8848a26411523e90c59ebe6b0a3f259f254f535 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Mon, 4 Apr 2016 20:33:08 -0400 Subject: [PATCH 1/2] Implement edit-url to craft a url with an editor. The edit-url command opens a url (by default, the current url) in the user's external editor and navigates to the result when the editor is closed. This makes it easy to tweak the current url to navigate within a site. `edit-url` accepts the same flags as `open` (e.g. -t will open in a new tab. One may provide a url as an argument to create a shortcut to pre-populate part of a url and allow filling in the rest. There is no default keybinding. Resolves #1261. --- doc/help/commands.asciidoc | 16 ++++++++++++++++ qutebrowser/browser/commands.py | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index d3819741e..7d70614d3 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -20,6 +20,7 @@ |<>|Open the last/[count]th download. |<>|Remove the last/[count]th download from the list. |<>|Retry the first failed/[count]th download. +|<>|Compose a url in an external editor and navigate to it. |<>|Send a fake keypress or key string to the website or qutebrowser. |<>|Go forward in the history of the current tab. |<>|Toggle fullscreen mode. @@ -223,6 +224,21 @@ Retry the first failed/[count]th download. ==== count The index of the download to retry. +[[edit-url]] +=== edit-url +Syntax: +:edit-url [*--bg*] [*--tab*] [*--window*] ['url']+ + +Open a URL in an external editor and navigate to it upon closing the editor. + +==== optional arguments +* +'url'+: A URL to pre-populate the editor with; defaults to the current URL. +* +*-b*+, +*--bg*+: Open in a new background tab. +* +*-t*+, +*--tab*+: Open in a new tab. +* +*-w*+, +*--window*+: Open in a new window. + +==== count +The tab index to open the URL in. + [[fake-key]] === fake-key Syntax: +:fake-key [*--global*] 'keystring'+ diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 3cae6941c..cb935ed58 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1847,3 +1847,27 @@ class CommandDispatcher: """Clear remembered SSL error answers.""" nam = self._current_widget().page().networkAccessManager() nam.clear_all_ssl_errors() + + @cmdutils.register(instance='command-dispatcher', scope='window') + def edit_url(self, url=None, bg=False, tab=False, window=False, count=None): + """Navigate to a url formed in an external editor. + + The editor which should be launched can be configured via the + `general -> editor` config option. + + Args: + url: URL to edit; defaults to the current page url. + bg: Open in a new background tab. + tab: Open in a new tab. + window: Open in a new window. + count: The tab index to open the URL in, or None. + """ + self._editor = editor.ExternalEditor( + self._win_id, self._tabbed_browser) + + # Passthrough for openurl args (e.g. -t, -b, -w) + self._editor.editing_finished.connect( + functools.partial(self.openurl, + bg = bg, tab = tab, window = window, count = count)) + + self._editor.edit(url or self._current_url().toString()) From e0d1e527d058daf7edfcce64024141e75c5f68d3 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Tue, 5 Apr 2016 07:49:01 -0400 Subject: [PATCH 2/2] Fix up edit-url implementation. Remove spaces around '=' for kwargs, don't set the _editor member. --- qutebrowser/browser/commands.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index cb935ed58..e65676bb3 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1862,12 +1862,11 @@ class CommandDispatcher: window: Open in a new window. count: The tab index to open the URL in, or None. """ - self._editor = editor.ExternalEditor( - self._win_id, self._tabbed_browser) + ed = editor.ExternalEditor(self._win_id, self._tabbed_browser) # Passthrough for openurl args (e.g. -t, -b, -w) - self._editor.editing_finished.connect( + ed.editing_finished.connect( functools.partial(self.openurl, - bg = bg, tab = tab, window = window, count = count)) + bg=bg, tab=tab, window=window, count=count)) - self._editor.edit(url or self._current_url().toString()) + ed.edit(url or self._current_url().toString())