summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorWojciech Siewierski <wojciech.siewierski@onet.pl>2017-05-21 03:58:31 +0200
committerWojciech Siewierski <wojciech.siewierski@onet.pl>2017-05-21 03:59:28 +0200
commit2375cc577c24401149540b728ebcb92e3003df03 (patch)
treeb33e38f8c87057e1da52552959d1961487cc87e8
parent7548d13090ea0fb0f2e42be15413f60c6380e81d (diff)
downloadranger-2375cc577c24401149540b728ebcb92e3003df03.tar.gz
Add the :narrow command
The name is derived from
https://www.gnu.org/software/emacs/manual/html_node/emacs/Narrowing.html

Closes #867.
-rwxr-xr-xranger/config/commands.py16
-rw-r--r--ranger/container/directory.py3
-rw-r--r--ranger/gui/widgets/statusbar.py4
3 files changed, 23 insertions, 0 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index 4cedc4e1..502e6f61 100755
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -1469,6 +1469,22 @@ class scout(Command):
         return count == 1
 
 
+class narrow(Command):
+    """
+    :narrow
+
+    Show only the files selected right now. If no files are selected,
+    disable narrowing.
+    """
+    def execute(self):
+        if self.fm.thisdir.marked_items:
+            selection = [f.basename for f in self.fm.thistab.get_selection()]
+            self.fm.thisdir.narrow_filter = selection
+        else:
+            self.fm.thisdir.narrow_filter = None
+        self.fm.thisdir.refilter()
+
+
 class filter_inode_type(Command):
     """
     :filter_inode_type [dfl]
diff --git a/ranger/container/directory.py b/ranger/container/directory.py
index 168a46c7..dac87650 100644
--- a/ranger/container/directory.py
+++ b/ranger/container/directory.py
@@ -108,6 +108,7 @@ class Directory(  # pylint: disable=too-many-instance-attributes,too-many-public
     files_all = None
     filter = None
     temporary_filter = None
+    narrow_filter = None
     inode_type_filter = None
     marked_items = None
     scroll_begin = 0
@@ -252,6 +253,8 @@ class Directory(  # pylint: disable=too-many-instance-attributes,too-many-public
                         return False
                 return True
             filters.append(hidden_filter_func)
+        if self.narrow_filter:
+            filters.append(lambda fobj: fobj.basename in self.narrow_filter)
         if self.filter:
             filter_search = self.filter.search
             filters.append(lambda fobj: filter_search(fobj.basename))
diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py
index eb2250ae..1e2a253c 100644
--- a/ranger/gui/widgets/statusbar.py
+++ b/ranger/gui/widgets/statusbar.py
@@ -256,6 +256,10 @@ class StatusBar(Widget):  # pylint: disable=too-many-instance-attributes
             right.add(str(self.fm.thisdir.flat), base, 'flat')
             right.add(", ", "space")
 
+        if self.fm.thisdir.narrow_filter:
+            right.add("narrowed")
+            right.add(", ", "space")
+
         if self.fm.thisdir.filter:
             right.add("f=`", base, 'filter')
             right.add(self.fm.thisdir.filter.pattern, base, 'filter')