Re: [textadept] Re: select all text behavior

From: Robert <ro....at.web.de>
Date: Sun, 12 Dec 2010 20:55:22 +0100

On Sun, Dec 12, 2010 at 10:38 AM, Scott Weisman <sweis....at.gmail.com> wrote:
> I found a problem in my solution. Sometimes I forget about the ctrl-a
> and just keep going about my business. When I hit escape later, if I
> am in a different buffer, I get an error:
>
> ...\Documents and Settings\sweisman/.textadept/init.lua:117: bad
> argument #1 to '?' (the indexed Buffer is not the focused one)
>
> So, I would like to changed the hook to something like this:
>
> keys.ca = { function ()
>    local buffer = buffer
> -- saved_buffer = ???
>    local KEYSYMS = _m.textadept.keys.KEYSYMS
>    local pos = buffer.current_pos
>    buffer:select_all()
>    local restore = events.connect('keypress', function(code)
>        if KEYSYMS[code] == 'esc' then
> -- current_buffer = ???
> -- if current_buffer ~= saved_buffer
> -- goto saved_buffer
> -- end
>            buffer:goto_pos(pos)
> -- if current_buffer ~= saved_buffer
> -- goto current_buffer
> -- end
>            events.disconnect('keypress', restore)
>        end
>    end)
> end }
>
> Do you know what I have to fill in there to make it work?
>
> Alternatively, just check if the current buffer is not the saved
> buffer, and skip the goto_pos in that case, and just disconnect
> without doing anything.
>
> Scott
>

You could save the position as a table with the filename as a key
pos[buffer.filename] = buffer.current_pos
and check this, or save the buffer id by looping through _BUFFERS and
saving it once you found the current id.
Maybe just something like (within the above snippet)?
delete_esc = events.connect('buffer_before_switch', function()
  events.disconnect('keypress', restore)
  events.disconnect('buffer_before_switch', delete_esc)
end)

Hope this helps,
Robert
Received on Sun 12 Dec 2010 - 14:55:22 EST

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:56:25 EST