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

From: Mitchell <m.att.foicica.com>
Date: Wed, 27 Mar 2019 21:29:05 -0400 (EDT)

Hi Ryan,

On Mon, 25 Mar 2019, Ryan McQuen 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.

I've committed something similar[1] that will hopefully work. Thanks for the suggestion.

Cheers,
Mitchell

[1]: https://foicica.com/hg/textadept/rev/f6e0eae74f45

-- 
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 Wed 27 Mar 2019 - 21:29:05 EDT

This archive was generated by hypermail 2.2.0 : Thu 28 Mar 2019 - 06:37:55 EDT