summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorAmr Alaa <n1amr1@gmail.com>2017-09-17 13:15:20 +0200
committerAmr Alaa <n1amr1@gmail.com>2017-09-17 13:19:51 +0200
commite2f72291063f95089bfb3c9613a969dd5e5a34d8 (patch)
tree6dfc2dbb87d9303b20ac65f9f087506d3073fde1 /ranger
parent5bd92b3413c11af4f296ced630dd71c96d3b56b7 (diff)
downloadranger-e2f72291063f95089bfb3c9613a969dd5e5a34d8.tar.gz
add settings option to use one indexed line numbers
Diffstat (limited to 'ranger')
-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
5 files changed, 20 insertions, 2 deletions
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index 92428312..b4163083 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -221,6 +221,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 521583c4..a0e1ab10 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -50,6 +50,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,
@@ -93,6 +94,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 14fde110..75559954 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -203,7 +203,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)