Re: Question about File > Open and the "Untitled" buffer

From: mitchell <>
Date: Fri, 9 Apr 2010 08:32:09 -0700 (PDT)


On Apr 9, 9:25 am, Robert <> wrote:
> On 9 Apr., 13:57, morchel <> wrote:
> >
> A while ago I tried to find a solution for this by closing the
> Untitled buffer in sessions.lua. I wasn't happy with my solution (as
> there were problems with the wrong view (not the buffer) being
> focussed when split views where saved.) Russels request made me think
> about trying it within, which should be better.
> This is around line 172 in core/file_io.lua
> ...
>'file_opened', utf8_filename)
> if (#textadept.buffers == 2 ) and not textadept.buffers[1].filename
> and not textadept.buffers[1].dirty then
>   view:goto_buffer(1, true)
>   textadept.buffers[1]:close()
> end
> for index, file in ipairs(recent_files) do
> ...
> (Sorry no diff tool installed here...)
> By checking for the number of open buffers this will not close an
> Untitled buffer if it was created by you later.
> Could those who are interested maybe try this out, possibly come up
> with a more elegant solution and check for other side effects :-). It
> should solve both the problem with the open file dialog as well as the
> session loading.

This is cute. I like it. The only problem is what if later you have an
error or message buffer as your only buffer? Those special kinds of
buffers don't have filenames. You'd have to check their buffer.type
(or buffer._type; I don't remember). Otherwise I think its a good
solution. is definately the way to go.

> Is there a way to close a buffer in the background, to avoid actually
> switching to it? If I skip the line view:goto... I get an error.

No, the indexed buffer must be focused. Otherwise calling
buffer:new_line() for example causes undesired behavior from


> Robert
Received on Fri 09 Apr 2010 - 11:32:09 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:42:54 EST