From f615d85172fba1efd334e11149df6f794edc0aed Mon Sep 17 00:00:00 2001 From: Collin Grady Date: Sun, 3 Aug 2014 03:34:00 +0000 Subject: [PATCH] Added line_count segment for vim. Returns total number of lines in current buffer. Addresses #556 --- powerline/config_files/colorschemes/vim/__main__.json | 1 + powerline/segments/vim.py | 6 ++++++ tests/test_segments.py | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/powerline/config_files/colorschemes/vim/__main__.json b/powerline/config_files/colorschemes/vim/__main__.json index 6bfc59dc..16c5ac71 100644 --- a/powerline/config_files/colorschemes/vim/__main__.json +++ b/powerline/config_files/colorschemes/vim/__main__.json @@ -10,6 +10,7 @@ "file_directory": "information:additional", "file_name_empty": "file_directory", "line_percent": "information:additional", + "line_count": "line_current", "position": "information:additional" } } diff --git a/powerline/segments/vim.py b/powerline/segments/vim.py index 62f4fe25..5f55bb7b 100644 --- a/powerline/segments/vim.py +++ b/powerline/segments/vim.py @@ -334,6 +334,12 @@ def line_current(pl, segment_info): return str(segment_info['window'].cursor[0]) +@requires_segment_info +def line_count(pl, segment_info): + '''Return the line count of the current buffer.''' + return str(len(segment_info['buffer'])) + + @requires_segment_info def col_current(pl, segment_info): '''Return the current cursor column. diff --git a/tests/test_segments.py b/tests/test_segments.py index de467728..03ccba24 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -687,6 +687,17 @@ class TestVim(TestCase): finally: vim_module._bw(segment_info['bufnr']) + def test_line_count(self): + pl = Pl() + segment_info = vim_module._get_segment_info() + segment_info['buffer'][0:-1] = [str(i) for i in range(99)] + try: + self.assertEqual(vim.line_count(pl=pl, segment_info=segment_info), '100') + vim_module._set_cursor(50, 0) + self.assertEqual(vim.line_count(pl=pl, segment_info=segment_info), '100') + finally: + vim_module._bw(segment_info['bufnr']) + def test_position(self): pl = Pl() segment_info = vim_module._get_segment_info()