Re: Lua Rocks

From: Robert <ro....at.web.de>
Date: Fri, 11 Jun 2010 10:25:13 +0200

On Wed, Jun 9, 2010 at 5:29 AM, mitchell <mforal.n....at.gmail.com> wrote:
>
> I think the wiki is a fine place for it to do. I'm not sure how I feel
> about hardcoding a 'modules/common/' directory.
>
> Mitchell
>

How about the following:
First (independently of the loading of user extensions or modules):
I think it would reduce possible confusion, if the package path would
be modified like this

-- init.lua
local paths = {
  _USERHOME..'/core/?.lua',
  _USERHOME..'/modules/?.lua',
  _USERHOME..'/modules/?/init.lua',
  _HOME..'/modules/?.lua',
  _HOME..'/modules/?/init.lua',
  package.path
}

-- core/init.lua
package.path = _USERHOME..'/core/?.lua;'.._HOME..'/core/?.lua;'..package.path

Currently one could have e.g. "key_commands.lua" and "events.lua" in
.textadept/ and then another "key_commands.lua" in .textadept/ext/.
With "core" on the path it would be more similar to the main directory
layout.

Second,
two other ideas for the original question of simplifying adding
modules/functions etc.:

Automatically loading all *.lua files in ~/.textadept (like currently
key_commands.lua and snippets.lua), a possible key_commands.lua to be
loaded last (to make sure all functions are defined).

-- In the "if not textadept.user_dofile('init.lua')" block
for file in lfs.dir(_USERHOME) do
  if file:find('%.lua$') and file ~= 'init.lua' and file ~=
'key_commands.lua' then
    textadept.user_dofile(file)
  end
end
textadept.user_dofile('key_commands.lua')

Then I could put a file "load_common.lua" in .textadept:

local lfs = require 'lfs'
local common_modules = _USERHOME..'/modules/common/'
if lfs.attributes(common_modules) then
  for filename in lfs.dir(common_modules) do
    if filename:find('%.lua$') then
      require('common.'..filename:match('^(.+)%.lua$'))
    end
  end
end

That way it would be very simple to add things like the supplemental
comments from the wiki by providing a file with the instruction to
drop this into .textadept (instead of having to create a personal
init.lua).

The other and probably simplest possibility would be to always load
the modules in the "if not textadept.user_dofile('init.lua')" block.
With the changes in the package path it has become easy to load
customized core modules - the only reason for a personal init.lua now
is to not load a module (like menu.lua), but this could probably be
worked around by loading an "empty" menu.lua?
Then the user init.lua would be loaded, so people could put every
customization in it or make it load other files.
Instructions could then simply read as "Put this in your init.lua" and
it will work without having to make sure that the core modules are
correctly required.

Robert

Received on Fri 11 Jun 2010 - 04:25:13 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:45:52 EST