aboutsummaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2019-03-27 21:27:55 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2019-03-27 21:27:55 -0400
commit6dcdb25098fc8c3bcfe01342c27b96d627c5c42a (patch)
tree7d368d6f2216845710653abbdf03c11c1b9fb981 /init.lua
parent082df4a067e9757e5cfd2ff32c0a0d7e3d546ce3 (diff)
downloadtextadept-6dcdb25098fc8c3bcfe01342c27b96d627c5c42a.tar.gz
textadept-6dcdb25098fc8c3bcfe01342c27b96d627c5c42a.zip
Line number margin grows for large files as needed.
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua12
1 files 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.