Re: Line number margin not the same in splits as the default view

From: mitchell <mforal.n....at.gmail.com>
Date: Mon, 14 Jun 2010 07:37:40 -0700 (PDT)

Robert,

> Thanks for sharing this - the missing line numbers in large log files
> had always bugged me a little, but never enough to try to fix it.
>
> I came up with this as I didn't want to always have a margin four digits wide:
> local function set_line_number_margin()
>   local textadept = _G.textadept
>   local c = textadept.constants
>   local buffer = buffer
>   local width = #((buffer.line_count+1)..'')
>   buffer.margin_width_n[0] = 4 + width *
> buffer:text_width(c.STYLE_LINENUMBER, '9')
> end
>
> textadept.events.add_handler("buffer_after_switch", set_line_number_margin)
>
> textadept.events.add_handler("keypress", function(code, shift, control, alt)
>   if code == 65293 then -- New line
>     set_line_number_margin()
>   end
> end)
>
> I don't know yet if I dislike the changing of the margin while
> switching buffers or when going from 9 to 10 lines.
>
> Mitchell, maybe a file_opened event to handle longer file numbers
> could be added?
> This would only cover files with 1000 or more lines.
>
> events.connect('file_opened', function()
>   local buffer = buffer
>   local c = _SCINTILLA.constants
>   local width = #(buffer.line_count..'')
>   width = width > 3 and width or 3
>   buffer.margin_width_n[0] = 4 + width *
> buffer:text_width(c.STYLE_LINENUMBER, '9')
> end)
>
> Or maybe this belongs to the themes?

It wouldn't be in themes because themes are within a 'buffer_new' or
'view_new' event. It would best be placed in a user script.

Mitchell

>
Received on Mon 14 Jun 2010 - 10:37:40 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:47:34 EST