Re: [code] [textadept] Autoindent tweak

From: Chris Emerson <c-ta.att.mail.nosreme.org>
Date: Wed, 9 Sep 2015 13:35:38 +0100

Hi,

On Fri, Sep 04, 2015 at 08:03:04PM -0400, Mitchell wrote:
> Hi Chris,
>
> On Fri, 4 Sep 2015, Chris Emerson wrote:
>
> >Hi,
> >
> >I really like textadept.editing.AUTOINDENT.
> >
> >One thing that's slightly annoying, though (ie not what I've been used to
> >elsewhere), is that I end up leaving otherwise empty lines with spaces
> >around.
[...]
> Other than using virtual space, I cannot think of any other
> solution. (However, auto-toggling virtual space would likely be a
> bug-ridden endeavor.)

I'm currently going for the bug-ridden solution, with the intention to fix
or work around the bugs as I come across them. :-)

I replaced the built-in AUTOINDENT event handler with one which positions the
cursor in virtual space instead of inserting them, and turn off virtual space
unconditionally in a KEYPRESS handler. I haven't (yet) found any issues when
using the keyboard, but I can get around it with the mouse (by clicking in
virtual space after the virtual indenting).

  -- Disable the built-in AUTOINDENT
  textadept.editing.AUTOINDENT = false

  -- Adapted from textadept's modules/textadept/editing.lua
  events.connect(events.CHAR_ADDED, function(char)
    if char ~= 10 then
        -- disable virtual space
        buffer.virtual_space_options = buffer.VS_NONE
        return
     end
    local line = buffer:line_from_position(buffer.current_pos)
    local i = line - 1
    while i >= 0 and buffer:get_line(i):find('^[\r\n]+$') do i = i - 1 end
    if i >= 0 then
      -- Instead of Textadept's version:
      -- buffer.line_indentation[line] = buffer.line_indentation[i]
      -- buffer:vc_home()
      --
      buffer.virtual_space_options = buffer.VS_USERACCESSIBLE
      for j=1,buffer.line_indentation[i] do
          buffer:char_right()
      end

    end
  end)
  events.connect(events.KEYPRESS, function()
    buffer.virtual_space_options = buffer.VS_NONE
  end, 1)

Chris

-- 
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 09 Sep 2015 - 08:35:38 EDT

This archive was generated by hypermail 2.2.0 : Thu 10 Sep 2015 - 06:49:25 EDT