Re: New buffers

From: mitchell <mforal.n....at.gmail.com>
Date: Mon, 14 Jun 2010 11:11:17 -0700 (PDT)

Robert,

On Jun 14, 3:03 am, Robert <ro....at.web.de> wrote:
> Hi,
>
> before I close a buffer I check for it being a message buffer and
> unsplit the view:
> keys.cw  = { function() if buffer._type then view:unsplit() end
> buffer:close() return true end }
>
> This works only as expected if the message buffer comes after the
> originating buffer in the buffers table, so
> I played around a bit and now have this:

Try:

buffer:close()
textadept.goto_view(-1, false)
view:unsplit()

This works as long as the message buffer is in the same view it was
opened in when splitting.

Mitchell

>
> keys.cn  = { function()
> local current_buffer = buffer
> for index, b in ipairs(textadept.buffers) do
>   if b == current_buffer then
>     current_buffer = index
>     break
>   end
> end
> local new_buffer = t.new_buffer()
> table.insert(textadept.buffers, current_buffer + 1, new_buffer)
> table.remove(textadept.buffers) -- remove last item
> end }
>
> -- new textadept._print
> function textadept._print(buffer_type, ...)
>   local function safe_print(...)
>     local message = table.concat({...}, '\t')
>     local message_buffer, message_buffer_index
>     local message_view
>     local _, message_view = view:split(false) -- horizontal split
>     local current_buffer = buffer
>     for index, b in ipairs(textadept.buffers) do
>       if b == current_buffer then
>         current_buffer = index
>         break
>       end
>     end
>     message_buffer = textadept.new_buffer()
>     table.insert(textadept.buffers, current_buffer + 1, message_buffer)
>     table.remove(textadept.buffers) -- remove last item
>     message_buffer._type = buffer_type
>     textadept.events.handle('file_opened')
>     message_buffer:append_text(message..'\n')
>     message_buffer:set_save_point()
>   end
>   pcall(safe_print, ...) -- prevent endless loops if this errors
> end
>
> New buffers are created "next" to the buffer where I pressed Ctrl-n,
> similar to the new tab behaviour in
> recent Firefox versions. New message buffers get created next to the
> buffer the message or error belongs to.
> That way my close/unsplit function works and I can toggle related
> buffers with Tab/Shift-Tab easily.
>
> Is there a more global/lower level way to achieve this? Can the
> new_buffer function be changed or the
> new_buffer event be used? I didn't find a way to get the id of the
> last open buffer.
>
Received on Mon 14 Jun 2010 - 14:11:17 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:48:10 EST