[code] Re: Change to Line Number Margin Width calculation in init.lua

From: Ryan <ryanpcmcquen.att.member.fsf.org>
Date: Tue, 26 Mar 2019 00:12:20 +0100 (CET)

Given that a file could jump to the next group of digits, while being edited, perhaps adding one to `lineCountLength` would be safer.

--
> On Monday, Mar 25, 2019 at 1:59 PM, Ryan McQuen <ryanpcmcquen.att.member.fsf.org (mailto:ryanpcmcquen.att.member.fsf.org)> wrote:
> Textadept currently has some strange handling for the Line Number Margin Width, which results in numbers running over once files reach a certain number (depending on font, this can happen as soon as a file hits 100 lines). I propose the following change to `init.lua` which calculates the width based on the file when it is opened:
>
> --- init-old.lua 2019-03-25 13:48:32.000000000 -0700
> +++ init-new.lua 2019-03-25 13:49:30.000000000 -0700
> @@ -131,8 +131,17 @@
> --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)
> +-- Increase the line number margin width, relatively:
> +events.connect(
> + events.FILE_OPENED,
> + function()
> + if type(buffer.line_count) == 'number' then
> + local lineCountLength = tostring(buffer.line_count):len()
> + local width = lineCountLength * 12
> + buffer.margin_width_n[0] = width + (not CURSES and 4 or 0)
> + end
> + end
> +)
> -- Marker Margin.
> buffer.margin_width_n[1] = not CURSES and 4 or 1
> -- Fold Margin.
>
>
> You can see this in action in the attached screenshots, which allow the width to be set programmatically, dependent on the file.
>
> ----
> From: ryanpcmcquen.att.member.fsf.org
> To: code.att.foicica.com
> Mar 25, 2019, 1:58:17 PM

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Mon 25 Mar 2019 - 19:12:20 EDT

This archive was generated by hypermail 2.2.0 : Tue 26 Mar 2019 - 06:26:59 EDT