Re: [code] [textadept] Buffer/view properties

From: Robert Gieseke <>
Date: Tue, 10 Feb 2015 20:27:30 +0100

Am 03/02/15 um 19:53 schrieb Robert Gieseke:
> Hi,
> Am 03/02/15 um 19:41 schrieb Mitchell:
> []
>> Okay, that all is reasonable. Looking at the "View" menu, I think "Toggle
>> View EOL", "Toggle Wrap Mode", and "Toggle View Whitespace" can be tweaked
>> to be buffer-specific properties based on your method.
Currently I use this:

local function save_properties()
  local buffer = buffer
  buffer._wrap_mode = buffer.wrap_mode
  buffer._view_eol = buffer.view_eol
  buffer._view_ws = buffer.view_ws
  buffer._margin_width_n = {}
  buffer._margin_type_n = {}
  for i = 0, 4 do
    buffer._margin_width_n[i] = buffer.margin_width_n[i]
    buffer._margin_type_n[i] = buffer.margin_type_n[i]

local function restore_properties()
  local buffer = buffer
  -- Check that saved properties exist.
  if type(buffer._wrap_mode) ~= 'number' then return end
  buffer.wrap_mode = buffer._wrap_mode
  buffer.view_eol = buffer._view_eol
  buffer.view_ws = buffer._view_ws
  for i = 0, 4 do
    buffer.margin_width_n[i] = buffer._margin_width_n[i]
    buffer.margin_type_n[i] = buffer._margin_type_n[i]

-- Save buffer properties.
events.connect(events.BUFFER_BEFORE_SWITCH, function()

events.connect(events.VIEW_BEFORE_SWITCH, function()

-- Restore buffer properties.
events.connect(events.BUFFER_AFTER_SWITCH, function()

events.connect(events.VIEW_AFTER_SWITCH, function()

One issue I see is that when creating a new buffer, properties like
view_eol are preserved, not sure if that's a problem.
As for storing the margins, this would be useful for Textredux,
textadept-vi and changing the width for buffers with 10.000s of lines.
Not sure if any styles should be stored as well.

Maybe others like to try this as well.


You are subscribed to
To change subscription settings, send an e-mail to
To unsubscribe, send an e-mail to
Received on Tue 10 Feb 2015 - 14:27:30 EST

This archive was generated by hypermail 2.2.0 : Wed 11 Feb 2015 - 06:47:22 EST