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')
4688ad1 ^

dc5d967 ^
4f8b08d ^



dc5d967 ^







dc5d967 ^

dba2306 ^

bf35794 ^
29355bd ^
c09bf8d ^


c09bf8d ^


dc5d967 ^
c09bf8d ^
1173723 ^

c09bf8d ^
dc5d967 ^
c09bf8d ^









e6cbe9c ^
1173723 ^

c53980c ^
c09bf8d ^










c09bf8d ^
c53980c ^
dc5d967 ^
c09bf8d ^
1173723 ^

c09bf8d ^


1173723 ^
c09bf8d ^







e6cbe9c ^
1173723 ^



8af1d97 ^



c53980c ^
c09bf8d ^






29355bd ^

b9da4b0 ^

29355bd ^

b9da4b0 ^
dc5d967 ^
b9da4b0 ^
29355bd ^
901b3ed ^








29355bd ^
901b3ed ^








29355bd ^

6458d72 ^
b9da4b0 ^



4688ad1 ^
c53980c ^


b9da4b0 ^

dfd84f9 ^
b9da4b0 ^

c53980c ^



b9da4b0 ^





439e15d ^

dc5d967 ^
439e15d ^

439e15d ^
439e15d ^
b9da4b0 ^
2e836ec ^
439e15d ^
1173723 ^
439e15d ^
1173723 ^
439e15d ^
1173723 ^
439e15d ^
1173723 ^
2e836ec ^
72655f0 ^
2e836ec ^
c53980c ^
439e15d ^





7696c89 ^
439e15d ^




e6cbe9c ^
439e15d ^




439e15d ^


26e134b ^

439e15d ^




439e15d ^
dc5d967 ^
439e15d ^



3399650 ^

dfd84f9 ^
da2bbd3 ^
439e15d ^


439e15d ^

83d2390 ^
dc5d967 ^
439e15d ^

59b4a5e ^
c0705ee ^
dba2306 ^
c0705ee ^
439e15d ^



adaa28a ^

adaa28a ^


dc5d967 ^
adaa28a ^



















439e15d ^

439e15d ^
dc5d967 ^
439e15d ^









0053620 ^

439e15d ^




439e15d ^
dc5d967 ^

439e15d ^



3399650 ^
c09bf8d ^
dba2306 ^
b1701ad ^

3399650 ^


66da153 ^
901b3ed ^
66da153 ^
3399650 ^

c0705ee ^
3399650 ^

c09bf8d ^
c0705ee ^

3399650 ^

439e15d ^




439e15d ^


0053620 ^

439e15d ^
adaa28a ^
bf35794 ^
adaa28a ^



























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382