[code] [textadept] Bug with property saving

From: <rob.g.att.web.de>
Date: Thu, 12 Mar 2015 15:03:30 +0100

Hi,

I think there is a bug introduced by the new margin and property saving. At first I though I had a bug in the Textredux module but I've created an example to reproduce this without it.
When creating a new buffer, changing its margins and closing it again, while starting from anywhere but the last buffer, the margins of the new buffer are added to the last buffer in _BUFFERS for some reason.

Steps to reproduce in a clean `.textadept/init.lua`:
- open `init.lua` and `session`
- go to `init.lua` (first buffer)
- create new buffer and change margin (`Ctrl-1` with the code below)
- close new buffer
- last buffer has margins (and other properties) from closed, previously created buffer

Code to reproduce and to produce some debug output:

keys.c1 = function()
  local target = buffer.new()
  target.margin_width_n[0] = 150
end

function info()
  for i, buf in ipairs(_BUFFERS) do
    local s = ''
    if buffer == buf then s = '=>' end
    if buf._margin_width_n then
      prev = tostring(buf._margin_width_n[0])
    else prev = '--' end
    _G.print(
      s .. (buf.filename or '??')..' '.. tostring(buf.margin_width_n[0])..
       ' ' .. prev
    )
  end
  _G.print("============================================================")
end

events.connect(events.BUFFER_AFTER_SWITCH, info)
events.connect(events.VIEW_AFTER_SWITCH, info)

events.connect(events.BUFFER_AFTER_SWITCH, function()
  _G.print("Buffer after switch: "..(buffer.filename or '-'))
  _G.print("view._prev_buffer after switch: "..tostring(view._prev_buffer))
end, 1)

Some observations:
- two buffer_after_switch events are fired when the buffer is closed
- after the first the margins are already stored in the last buffer of _BUFFERS
- when I disable the going back to the last buffer in `core/ui.lua` this does not happen anymore
- likely unrelated, when only one buffer is open, `Ctrl-Tab` still fires after_switch events

Any ideas what to check next?
Thanks,
Robert

-- 
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 Thu 12 Mar 2015 - 10:03:30 EDT

This archive was generated by hypermail 2.2.0 : Fri 13 Mar 2015 - 06:36:11 EDT