Reset languagae modules(was: API Changes)

From: Robert <ro....at.web.de>
Date: Sat, 19 Jun 2010 14:57:42 +0200

On Fri, Jun 18, 2010 at 5:58 PM, mitchell <mforal.n....at.gmail.com> wrote:
> Robert,
>
> On Jun 18, 11:09 am, Robert <ro....at.web.de> wrote:
>> Hi Mitchell,
>>
>> looking throught the new API I saw this in ._G.luadoc:
>>
>> -- Resets the Lua state by reloading all init scripts.
>> -- Language-specific modules for opened files are NOT reloaded. Re-opening the
>> -- files that use them will reload those modules.
>> -- This function is useful for modifying init scripts (such as keys.lua) on the
>> -- fly without having to restart Textadept.
>>
>> I just tested this and it is reloading the module. I think, you had a
>> fix for the language modules a while ago.
>> Speaking of the resets.
>> I have
>> keys['f9'] = { function()
>>   buffer:save()
>>   gui.statusbar_text = "Reset."
>>   _G.reset()
>> end }
>> in my init.lua.
>> Maybe adding the statusbar change to Textadept core would be helpful
>> for others as well, sometimes a processed file is failing silently.
>
> If you have a lua file open and focused and then reset the lua state,
> the lua module is reloaded since the file is open. But if you have a
> cpp file open in another buffer, resetting the lua state will not
> reload the cpp module until that buffer is refocused or another cpp
> file loaded.
>

Thanks - now I understand why it sometimes worked for me and sometimes not :-)
The refocusing doesn't seem to work, as a workaround I could edit the
cpp module, go back to the c-file that made me want to edit the
language module, and then reset the Lua state.
To able to do the reset in the language module file I added the
following to my init.lua:

if RESETTING then
  events.connect('buffer_after_switch', function ()
    local lang = buffer._lexer or false
    if lang and not package.loaded[lang] then
      buffer:set_lexer(lang)
    end
  end)
end

I added the extra check for "lang" to prevent "hanging" Textadept when
creating a new buffer after a reset.

Would you consider adding this (or something similar) to
mime_types.lua? It would make developing language modules a lot
easier.

Robert
Received on Sat 19 Jun 2010 - 08:57:42 EDT

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