Re: [code] [textadept] to switch show of line numbering

From: A.M. Genaev <genaev.att.nioch.nsc.ru>
Date: Mon, 02 Sep 2013 18:05:03 +0700

Hi Mitchell,

You code works fine.

May i ask you about some additions?

I usually deal with small scripts on perl and bash and I want line numbering
off as default. And default line numbering margin (4) is too many for me.

I tried to solve these problems by adding in my inin.lua the next code based
on you reply and on content of http://foicica.com/wiki/adjust-line-number-margin-on-zoom and http://foicica.com/wiki/line-number-margin:

-- line numbering
line_numbering = false
line_numbering_width = 2

-- function to set buffer.margin_width_n[0]
local set_buffer_margin_width = function(line_numbering_width)
  local buffer = buffer
  local c = _SCINTILLA.constants
  local width = #(buffer.line_count..'')
  width = width > line_numbering_width and width or line_numbering_width
  buffer.margin_width_n[0] = line_numbering_width
   + width * buffer:text_width(c.STYLE_LINENUMBER, '9')
end

-- set buffer.margin_width_n[0]
if line_numbering then
  set_buffer_margin_width(line_numbering_width)
else
  buffer.margin_width_n[0] = 0
end

-- adjust the line number margin for opened file
events.connect(events.FILE_OPENED, function()
  if line_numbering then
    set_buffer_margin_width(line_numbering_width)
  else
    buffer.margin_width_n[0] = 0
  end
end)

-- adjust line number margin on zoom
events.connect('SCN', function(n)
  if n.code == _SCINTILLA.constants.SCN_ZOOM then
    if line_numbering then
      set_buffer_margin_width(line_numbering_width)
    else
      buffer.margin_width_n[0] = 0
    end
  end
end)

-- to toggle line numbering on and off (Ctrl-_)
keys['c_'] = function()
  if buffer.margin_width_n[0] > 0 then
    buffer.margin_width_n[0] = 0
  else
    set_buffer_margin_width(line_numbering_width)
    line_numbering = true
  end
end

It is almost well but line numbering becomes 'on' always when zooming.
And i feel than it may be made simpler.

I would be grateful for any comments.

> You can assign a key binding to toggle in your ~/.textadept/init.lua:
>
> local margin_width = buffer.margin_width_n[0]
> keys['c_'] = function()
> if buffer.margin_width_n[0] > 0 then
> buffer.margin_width_n[0] = 0
> else
> buffer.margin_width_n[0] = margin_width
> end
> end
>
> Cheers,
> Mitchell
------------------------------------------
Dr. Alexander Genaev
Novosibirsk Institute of Organic Chemistry
Lavrentiev ave. 9, 630090 Novosibirsk, Russia
genaev.att.nioch.nsc.ru

-- 
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 02 Sep 2013 - 07:05:03 EDT

This archive was generated by hypermail 2.2.0 : Tue 03 Sep 2013 - 06:41:35 EDT