about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@hut.pm>2017-10-17 23:50:03 +0200
committerhut <hut@hut.pm>2017-10-17 23:50:03 +0200
commit45f8b2c35a302de8d2599db2639843725c1302c8 (patch)
treeb5a129faa4eb9bec4305b6ae5c2f9dc8926421c8
parent7d597e21e50e9beaa94536cfd88bd6cc5a790a7e (diff)
parente2f72291063f95089bfb3c9613a969dd5e5a34d8 (diff)
downloadranger-45f8b2c35a302de8d2599db2639843725c1302c8.tar.gz
Merge branch 'one-indexed' of https://github.com/n1amr/ranger
-rw-r--r--doc/ranger.18
-rw-r--r--doc/ranger.pod7
-rw-r--r--ranger/config/rc.conf3
-rw-r--r--ranger/container/settings.py2
-rw-r--r--ranger/core/actions.py1
-rw-r--r--ranger/ext/direction.py9
-rw-r--r--ranger/gui/widgets/browsercolumn.py7
7 files changed, 35 insertions, 2 deletions
diff --git a/doc/ranger.1 b/doc/ranger.1
index 1e745fb6..f96c7f20 100644
--- a/doc/ranger.1
+++ b/doc/ranger.1
@@ -816,6 +816,14 @@ all directories above the current one as well?
 .IP "mouse_enabled [bool] <zm>" 4
 .IX Item "mouse_enabled [bool] <zm>"
 Enable mouse input?
+.IP "one_indexed [bool]" 4
+.IX Item "one_indexed [bool]"
+Start line numbers from 1.  Possible values are:
+.Sp
+.Vb 2
+\& false      start line numbers from 0
+\& true       start line numbers from 1
+.Ve
 .IP "padding_right [bool]" 4
 .IX Item "padding_right [bool]"
 When collapse_preview is on and there is no preview, should there remain a
diff --git a/doc/ranger.pod b/doc/ranger.pod
index f7053361..310ab1fd 100644
--- a/doc/ranger.pod
+++ b/doc/ranger.pod
@@ -812,6 +812,13 @@ all directories above the current one as well?
 
 Enable mouse input?
 
+=item one_indexed [bool]
+
+Start line numbers from 1.  Possible values are:
+
+ false      start line numbers from 0
+ true       start line numbers from 1
+
 =item padding_right [bool]
 
 When collapse_preview is on and there is no preview, should there remain a
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index 27c094a1..9459a3d3 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -225,6 +225,9 @@ set clear_filters_on_dir_change false
 # Disable displaying line numbers in main column
 set line_numbers false
 
+# Start line numbers from 1 instead of 0
+set one_indexed false
+
 # Save tabs on exit
 set save_tabs_on_exit false
 
diff --git a/ranger/container/settings.py b/ranger/container/settings.py
index 6ffa5e2d..bb902f9d 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -52,6 +52,7 @@ ALLOWED_SETTINGS = {
     'max_history_size': (int, type(None)),
     'metadata_deep_search': bool,
     'mouse_enabled': bool,
+    'one_indexed': bool,
     'open_all_images': bool,
     'padding_right': bool,
     'preview_directories': bool,
@@ -94,6 +95,7 @@ ALLOWED_VALUES = {
     'cd_tab_case': ['sensitive', 'insensitive', 'smart'],
     'confirm_on_delete': ['multiple', 'always', 'never'],
     'line_numbers': ['false', 'absolute', 'relative'],
+    'one_indexed': [False, True],
     'preview_images_method': ['w3m', 'iterm2', 'urxvt', 'urxvt-full'],
     'vcs_backend_bzr': ['disabled', 'local', 'enabled'],
     'vcs_backend_git': ['enabled', 'disabled', 'local'],
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index eb091186..5f8f6c53 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -461,6 +461,7 @@ class Actions(  # pylint: disable=too-many-instance-attributes,too-many-public-m
         """
         cwd = self.thisdir
         kw.setdefault('cycle', self.fm.settings['wrap_scroll'])
+        kw.setdefault('one_indexed', self.fm.settings['one_indexed'])
         direction = Direction(kw)
         if 'left' in direction or direction.left() > 0:
             steps = direction.left()
diff --git a/ranger/ext/direction.py b/ranger/ext/direction.py
index e337c26e..7df45556 100644
--- a/ranger/ext/direction.py
+++ b/ranger/ext/direction.py
@@ -96,6 +96,10 @@ class Direction(dict):
     def cycle(self):
         return self.get('cycle') in (True, 'true', 'on', 'yes')
 
+    def one_indexed(self):
+        return ('one_indexed' in self and
+                self.get('one_indexed') in (True, 'true', 'on', 'yes'))
+
     def multiply(self, n):
         for key in ('up', 'right', 'down', 'left'):
             try:
@@ -129,7 +133,10 @@ class Direction(dict):
         pos = direction
         if override is not None:
             if self.absolute():
-                pos = override
+                if self.one_indexed():
+                    pos = override - 1
+                else:
+                    pos = override
             else:
                 pos *= override
         if self.pages():
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index 485f4fc8..b3272cbc 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -207,7 +207,12 @@ class BrowserColumn(Pager):  # pylint: disable=too-many-instance-attributes
         if self.settings.line_numbers == 'relative':
             line_number = abs(selected_i - i)
             if line_number == 0:
-                line_number = selected_i
+                if self.settings.one_indexed:
+                    line_number = selected_i + 1
+                else:
+                    line_number = selected_i
+        elif self.settings.one_indexed:
+            line_number += 1
 
         return linum_format.format(line_number)