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

From: Robert <ro....at.web.de>
Date: Tue, 13 Apr 2010 13:42:24 -0700 (PDT)

On Apr 11, 10:25 pm, mitchell <mforal.n....at.gmail.com> wrote:
> Brian,
>
> On Apr 11, 3:08 pm, Robert <ro....at.web.de> wrote:
>
>
>
> > On Apr 10, 9:21 am, Brian Schott <briancsch....at.gmail.com> wrote:
> > ...
>
> > > and they were utterly vanquished.
>
> > Ugh. There is a problem... When you close all buffers, and only one
> > Untitled buffer remains it becomes quite easy to crash Textadept. When
> > you have a look at the side pane view of the buffer list in 2.1 it can
> > be seen how once you close the Untitled buffer immediately another
> > appears. With the new "new buffer" event this seems to become a
> > problem.
> > A quick fix could be something like this (Don't close if there is only
> > one clean Untitled buffer):
> > --- a/core/file_io.lua  Sun Apr 11 12:09:10 2010 +0200
> > +++ b/core/file_io.lua  Sun Apr 11 20:58:15 2010 +0200
> > @@ -322,6 +322,10 @@
> >  -- @usage buffer:close()
> >  function close(buffer)
> >    textadept.check_focused_buffer(buffer)
> > +  local b = textadept.buffers[1]
> > +  if #textadept.buffers == 1 and not (b.dirty or b._type or
> > b.filename) then
> > +    return false
> > +  end
> >    if buffer.dirty and
> >       textadept.dialog('msgbox',
>
> > However, it's still not possible to open more than one Untitled
> > buffer... maybe the "new buffer" event needs to be changed.
>
> I have reverted the change for now. I didn't realize that another
> Untitled buffer couldn't be opened. Clearly my solution isn't a good
> one.
>
> Mitchell

Gentlemen,
this should work. Making Mitchell's event a 'file_opened' event and
calling this event when the faux message or error buffer is created
during the session loading.
I've been thinking about saving the message or error buffer content to
real files or not saving them at all, but this seems to be a good
solution for the moment.

Good night,
Robert

diff -r 3cf0089aba54 core/events.lua
--- a/core/events.lua Mon Apr 12 21:41:15 2010 +0200
+++ b/core/events.lua Tue Apr 13 22:37:15 2010 +0200
@@ -339,6 +339,15 @@
     buffer:toggle_fold(line)
   end)

+add_handler('file_opened',
+ function() -- close initial 'Untitled' buffer
+ local b = textadept.buffers[1]
+ if #textadept.buffers == 2 and not (b.filename or b._type or
b.dirty) then
+ view:goto_buffer(1, true)
+ buffer:close()
+ end
+ end)
+
 add_handler('buffer_new',
   function() -- set additional buffer functions
     local buffer = buffer
diff -r 3cf0089aba54 modules/textadept/session.lua
--- a/modules/textadept/session.lua Mon Apr 12 21:41:15 2010 +0200
+++ b/modules/textadept/session.lua Tue Apr 13 22:37:15 2010 +0200
@@ -51,6 +51,7 @@
       else
         textadept.new_buffer()
         buffer._type = filename
+ textadept.events.handle('file_opened', filename)
       end
       -- Restore saved buffer selection and view.
       local anchor = tonumber(anchor) or 0
Received on Tue 13 Apr 2010 - 16:42:24 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:43:00 EST