Re: Ctrl-Tab to go back to the most-recently-used buffer

From: Andy Lima <andysky....at.gmail.com>
Date: Thu, 14 May 2009 04:56:37 +0100

Mitchell,

Problem is: _G.previous_buffer_idx always has the current buffer index, not
the previous one's.

My code so far:
--------
local function switch_to_previously_used_buffer()
  view:goto_buffer(_G.previous_buffer_idx, true)
end

textadept.events.add_handler('buffer_switch',
  function()
    for idx, buf in ipairs(textadept.buffers) do
      if buf == buffer then
        _G.previous_buffer_idx = idx
        break
      end
    end
  end
)

keys['c\t'] = { switch_to_previously_used_buffer }
--------

On Thu, May 14, 2009 at 4:39 AM, mitchell <mforal.n....at.gmail.com> wrote:

>
> Andy,
>
> > > This would work. You can store a variable like 'previous_buffer' in
> > > the global table _G if you'd like.
> >
> > Ok, but how do I get the current buffer index? ..In order to later switch
> to
> > it with "view:goto_buffer(previous_buffer_index, true)"..
>
> You could loop through textadept.buffers:
>
> for idx, buf in ipairs(textadept.buffers) do
> if buf == buffer then
> -- do something with idx
> end
> end
>
> -Mitchell;
> >
>
Received on Wed 13 May 2009 - 23:56:37 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:37:53 EST