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

From: Mitchell <m.att.foicica.com>
Date: Wed, 11 Feb 2015 12:00:25 -0500 (EST)

Hi Robert,

On Tue, 10 Feb 2015, Robert Gieseke wrote:

> 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]
> end
> end
>
> 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]
> end
> end
>
> -- Save buffer properties.
> events.connect(events.BUFFER_BEFORE_SWITCH, function()
> save_properties()
> end)
>
> events.connect(events.VIEW_BEFORE_SWITCH, function()
> save_properties()
> end)
>
> -- Restore buffer properties.
> events.connect(events.BUFFER_AFTER_SWITCH, function()
> restore_properties()
> end)
>
> events.connect(events.VIEW_AFTER_SWITCH, function()
> restore_properties()
> end)
>
> One issue I see is that when creating a new buffer, properties like
> view_eol are preserved, not sure if that's a problem.

The defaults would be set in Textadept's properties.lua, so this is not an
issue.

> 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.

I don't think I like the idea of making margin widths and types
"per-buffer". That would open the door to "why not save all properties
associated with views, not buffers?"

Cheers,
Mitchell

-- 
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 Wed 11 Feb 2015 - 12:00:25 EST

This archive was generated by hypermail 2.2.0 : Thu 12 Feb 2015 - 06:47:35 EST