From 6dcdb25098fc8c3bcfe01342c27b96d627c5c42a Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Wed, 27 Mar 2019 21:27:55 -0400 Subject: Line number margin grows for large files as needed. --- init.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 1543d352..1ec700b4 100644 --- a/init.lua +++ b/init.lua @@ -131,8 +131,16 @@ buffer.caret_line_visible = not CURSES --buffer.margin_right = -- Line Number Margin. buffer.margin_type_n[0] = buffer.MARGIN_NUMBER -local width = 4 * buffer:text_width(buffer.STYLE_LINENUMBER, '9') -buffer.margin_width_n[0] = width + (not CURSES and 4 or 0) +local function resize_line_number_margin() + -- This needs to be evaluated dynamically since themes/styles can change. + local buffer = _G.buffer + local width = math.max(4, #tostring(buffer.line_count)) * + buffer:text_width(buffer.STYLE_LINENUMBER, '9') + + (not CURSES and 4 or 0) + buffer.margin_width_n[0] = math.max(buffer.margin_width_n[0], width) +end +events.connect(events.BUFFER_NEW, resize_line_number_margin) +events.connect(events.FILE_OPENED, resize_line_number_margin) -- Marker Margin. buffer.margin_width_n[1] = not CURSES and 4 or 1 -- Fold Margin. -- cgit v1.2.3