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

From: Robert <ro....at.web.de>
Date: Mon, 14 Jun 2010 09:01:54 +0200

On Wed, Jun 9, 2010 at 10:19 PM, mitchell <mforal.n....at.gmail.com> wrote:
> Hi Ryan,
>
> On Jun 7, 10:44 am, Ryan Pusztai <rpusz....at.gmail.com> wrote:
>> Hi,
>>
>> I added this to my init.lua file to control some defaults about all themes
>> and it has been working great.
>>
>> -- ~/.textadept/init.lua
>>   local function OnBufferNew()
>>  local textadept = _G.textadept
>> local c = textadept.constants
>> local buffer = buffer
>>  -- Global tabs and indentation
>> buffer.tab_width = 4
>> buffer.use_tabs = true
>>  buffer.indent = 4
>> buffer.indentation_guides = 1
>> -- Multiple selection support
>>  buffer.multiple_selection = true
>> buffer.additional_selection_typing = true
>>  buffer.additional_carets_visible = true
>> -- Make line number buffer wider (4 digits)
>>  buffer.margin_width_n[0] = 4 + 4 * buffer:text_width( c.STYLE_LINENUMBER,
>> '9' )
>>   end
>>
>>   textadept.events.add_handler( "buffer_new", OnBufferNew )
>> -- end ~/.textadept/init.lua
>>
>> I am trying to extend the line number margin by one more character than the
>> default (up to 4 digits). This works great until you open a split. in the
>> split it goes to the default of 3 digits. Any thoughts?
>> Does it have to do with the indexing to '0' on "buffer.margin_width_n"? If
>> so, how do I make this work all the time?
>
> Put the margin code in another function that handles the 'view_new'
> event.
>
> Mitchell
>
>> Thanks.
>> --
>> Regards,
>> Ryan
>
> --

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?

Robert
Received on Mon 14 Jun 2010 - 03:01:54 EDT

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