summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2013-10-21 02:25:34 +0200
committerFlorent Le Coz <louiz@louiz.org>2013-10-21 02:25:34 +0200
commit4a091b3d2d82df6218c4db3cf6fca0cbc52c08ba (patch)
tree6e784724ca1bfa16dbcb3862e39504bdc755ba19 /plugins
parente02f93a8ef9d41e0d3c34bbb076eb6db928afac7 (diff)
downloadpoezio-4a091b3d2d82df6218c4db3cf6fca0cbc52c08ba.tar.gz
poezio-4a091b3d2d82df6218c4db3cf6fca0cbc52c08ba.tar.bz2
poezio-4a091b3d2d82df6218c4db3cf6fca0cbc52c08ba.tar.xz
poezio-4a091b3d2d82df6218c4db3cf6fca0cbc52c08ba.zip
Make the /link plugin accept a range
Like /link 1:10 to open the last 10 links Fixes #2130
Diffstat (limited to 'plugins')
-rw-r--r--plugins/link.py49
1 files changed, 31 insertions, 18 deletions
diff --git a/plugins/link.py b/plugins/link.py
index ef8a4c8a..3c4d99b9 100644
--- a/plugins/link.py
+++ b/plugins/link.py
@@ -43,21 +43,22 @@ Usage
.. glossary::
/link
- **Usage:** ``/link [num]``
+ **Usage:** ``/link [range]``
This plugin adds a :term:`/link` command that will open the links in ``firefox``. If
you want to use another browser, you can use the :term:`/set` command to change the
:term:`browser` option.
- :term:`/link` without argument will open the last received link, if any is found.
- If an integer argument is given, /link will go back gradually in the buffer
- to open the previous link, and so on.
-
-
- If you are scrolling in the buffer, poezio will open the links starting from
- the first you can see. (although there are some problems with multiline
- messages).
+ :term:`/link` without argument will open the last link found
+ in the current tab, if any is found. An optional range
+ argument can be given, to select one or more links to
+ open. Examples:
+ ``/link 1`` is equivalent to ``/link``
+ ``/link 3`` will open the third link found in the current tab,
+ starting from the bottom.
+ ``/link 1:5`` will open the last five links in the current tab
+ ``/link :2`` will open the last two links
Options
-------
@@ -109,17 +110,29 @@ class Plugin(BasePlugin):
def command_link(self, args):
args = common.shell_split(args)
if len(args) == 1:
- try:
- nb = int(args[0])
- except:
- return self.api.run_command('/help link')
+ if args[0].find(':') == -1:
+ try:
+ start = int(args[0])
+ end = start
+ except ValueError:
+ return self.api.run_command('/help link')
+ else:
+ start, end = args[0].split(':', 1)
+ if start == '':
+ start = 1
+ try:
+ start = int(start)
+ end = int(end)
+ except ValueError:
+ return self.api.information('Invalid range: %s' % (args[0]), 'Error')
else:
- nb = 1
- link = self.find_link(nb)
- if link:
+ start = 1
+ end = 1
+ for nb in range(start, end+1):
+ link = self.find_link(nb)
+ if not link:
+ return self.api.information('No URL found.', 'Warning')
self.core.exec_command([self.config.get('browser', 'firefox'), link])
- else:
- self.api.information('No URL found.', 'Warning')
def cleanup(self):
del self.config