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

From: Robert Gieseke <>
Date: Sat, 31 Jan 2015 11:22:00 +0100

Hi Mitchell,

Am 30/01/15 um 17:41 schrieb Mitchell:
> On Mon, 26 Jan 2015, Mitchell wrote:
>> On Mon, 26 Jan 2015, Robert Gieseke wrote:
>>> would you consider a patch that made Textadept buffers remember
>>> properties that are now view-specific like margins, wrap mode, eol etc.?
>>> Likely similar to what's already done for caret and selection position.
> I've thought some more on this and come up with a potential problem. If,
> for example, `buffer.wrap_mode` would be a per-buffer setting, what
> happens when you select it from the menu? Would the menu only change that
> buffer's setting? If so, then the user would have to toggle the setting
> for all buffers, which obviously is undesirable. If on the other hand
> Textadept were to iterate through existing buffers and toggle wrap mode,
> what happens for new buffers? They would be unwrapped by default. This
> issue seems to require keeping track of a general state (or perhaps a
> "per-view" state, as is the default when it comes to these things) and
> applying it to new buffers. I'm not sure how comfortable I am with an idea
> like that. (Also, Textadept would need to keep track of a list of
> properties that may change with each release of Scintilla; I'm not a fan
> of such bookkeeping.)
> It's an interesting problem that has no immediate solution, but I'm still
> open to a good one.

In my testing I already had some issues (with margins for example) I
have to investigate further, but the following seems to do what I had in
mind for `wrap_mode` (should be using functions of course).

-- Save buffer properties.
events.connect(events.BUFFER_BEFORE_SWITCH, function()
  local buffer = buffer
  buffer._wrap_mode = buffer.wrap_mode

events.connect(events.VIEW_BEFORE_SWITCH, function()
  local buffer = buffer
  buffer._wrap_mode = buffer.wrap_mode

-- Restore buffer properties.
events.connect(events.BUFFER_AFTER_SWITCH, function()
  local buffer = buffer
  if type(buffer._wrap_mode) == 'number' then
    buffer.wrap_mode = buffer._wrap_mode

events.connect(events.VIEW_AFTER_SWITCH, function()
  local buffer = buffer
  if type(buffer._wrap_mode) == 'number' then
    buffer.wrap_mode = buffer._wrap_mode

When I change the setting in one view, it is updated as well, once I
switch to the same buffer in another view.

I would have thought that the buffer-specific settings would move to the
buffer menu for changing a buffer for a session. For me it's mainly
being able to view a file with settings, an Ascii table or badly
indented code with very long lines when otherwise having wrap_mode enabled.

For new buffers or opening a file the default from `properties.lua`
would apply. Maybe one could make editing `properties.lua` more visible
by adding it to the menu (though this would require auto-creating it (if
not existing) similar to the main `init.lua`).


You are subscribed to
To change subscription settings, send an e-mail to
To unsubscribe, send an e-mail to
Received on Sat 31 Jan 2015 - 05:22:00 EST

This archive was generated by hypermail 2.2.0 : Sat 31 Jan 2015 - 06:48:27 EST