Re: [code] How to replace the "Untitled" buffer

From: Markus F.X.J. Oberhumer <markus.att.oberhumer.com>
Date: Sun, 14 Feb 2016 03:01:07 +0100

Hi Robert,

thanks for your code - actually the version below seems to work for me.

Which problems did you see?

Cheers,
Markus

--- START OF init.lua
ui.size = {1024, 800}

local textredux = require('textredux')

local function redux_menu()
  local buf = buffer
  if #_BUFFERS == 1 and not (buf.filename or buf._type or buf.modify) then
    local dir = os.getenv("HOME")
    textredux.fs.open_file(dir)
    view:goto_buffer(1)
    io.close_buffer()
  end
end

events.connect(events.BUFFER_DELETED, function() redux_menu() end)
events.connect(events.INITIALIZED, function() redux_menu() end)
--- END OF init.lua

On 2016-02-11 22:38, Robert Gieseke wrote:
> Hi Markus,
>
> I tried this
>
> local home = os.getenv("HOME")
>
> local function redux_menu()
> local buf = buffer
> if #_BUFFERS == 1 and not (buf.filename or buf._type or buf.modify) then
> textredux.fs.open_file(home)
> view:goto_buffer(1)
> io.close_buffer()
> end
> end
>
> events.connect(events.BUFFER_DELETED, function() redux_menu() end)
>
> I also tried attaching the same function to the INITIALIZED handler but
> there seemed to be an issue with refreshing the Textredux buffer, so
> with this setup you would have to close single Untitled buffer to get
> the menu.
>
> Not sure about needing an extra event, in any case be aware that
> Textadept's `core/file.io` also handles closing an initial "Untitled"
> buffer (l. 319)
>
> You could of course have a proper Textredux buffer with different
> option, I like the idea a lot!
>
> Cheers,
> Robert
>
> Am 11/02/16 um 19:14 schrieb Markus F.X.J. Oberhumer:
>> Hi Robert,
>>
>> I tried that, but there seems to be some magic in lbuffer_delete() - please
>> see the marked line below.
>>
>> Maybe adding some extra event inside lbuffer_new() or new_buffer() could help?
>>
>> But then, it also seems the initial "Untitled" is created before init.lua ??
>>
>> Thanks,
>> Markus
>>
>>
>>
>> --- a/src/textadept.c
>> +++ b/src/textadept.c
>> @@ -1093,7 +1093,7 @@
>> Scintilla *view = l_globaldoccompare(L, 1) == 0 ? focused_view : dummy_view;
>> sptr_t doc = SS(view, SCI_GETDOCPOINTER, 0, 0);
>> lua_getfield(L, LUA_REGISTRYINDEX, "ta_buffers");
>> - if (lua_rawlen(L, -1) == 1) new_buffer(0);
>> + if (lua_rawlen(L, -1) == 1) new_buffer(0); // new Untitled buffer ???
>> lL_gotodoc(L, focused_view, -1, TRUE);
>> delete_buffer(doc);
>> lL_event(L, "buffer_after_switch", -1), lL_event(L, "buffer_deleted", -1);
>>
>>
>>
>> On 2016-02-11 19:03, Robert Gieseke wrote:
>>> Hi,
>>> I think you could check in a buffer closed event whether there is only an Untitled buffer left and create your Textredux buffer.
>>>
>>> Cheers,
>>> Robert
>>>
>>>> Am 11.02.2016 um 18:41 schrieb Markus F.X.J. Oberhumer <markus.att.oberhumer.com>:
>>>>
>>>> Hi,
>>>>
>>>> I would like to replace the "Untitled" buffer that you get when
>>>> there are no files or when you close all tabs, e.g. with
>>>> a custom textredux buffer.
>>>>
>>>> It seems this is hardcoded in textadept.c, though.
>>>>
>>>> Any hints?
>>>>
>>>> Thanks,
>>>> Markus
>>>>

-- 
Markus Oberhumer, <markus@oberhumer.com>, http://www.oberhumer.com/
-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Sat 13 Feb 2016 - 21:01:07 EST

This archive was generated by hypermail 2.2.0 : Sun 14 Feb 2016 - 06:29:32 EST