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

From: Robert Gieseke <>
Date: Fri, 9 Apr 2010 20:43:26 +0200

On Fri, Apr 9, 2010 at 5:32 PM, mitchell <> wrote:
> Hi,
> 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.

More cases covered version attached. It will now even restore your ta
state if you left it with an error and a message buffer :-) I hopeI
haven't forgotten anything.

>> 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
> Scintilla.

Opening a file when there is only one 'Untitled' buffer feels a little
bit slower due to the switching back and forth, but I think it's fast


Received on Fri 09 Apr 2010 - 14:43:26 EDT

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