lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

I've added a new patch to: http://lua-users.org/wiki/LuaPowerPatches

Advanced readline support
-------------------------

This patch adds the following features to the existing readline support
in Lua 5.x: 

* Completion of keywords and global variable names. 
* Recursive and metatable-aware completion of variable names. 
* Context sensitive delimiter completion. 
* Save/restore of the history to/from a file (LUA_HISTORY environment
  variable). 
* Setting a limit for the size of the history (LUA_HISTSIZE environment
  variable). 
* Setting the application name to allow for $if lua ... $endif in ~/.inputrc. 

After applying the patch start lua and try these (replace ~ with the TAB key): 

~~
fu~foo() ret~fa~end<CR>
io~~~s~~~o~~~w~"foo\n")<CR>

The ~~ are just for demonstration purposes (io~s~o~w~ suffices, of course).

If you are used to zsh/tcsh-style completion support, try adding
'TAB: menu-complete' and 'C-d: possible-completions' to your ~/.inputrc.

It has been verified to work with Lua 5.0, 5.0.2, 5.1-work0 and
GNU readline 2.2.1, 4.0, 4.3 or NETBSD libedit 2.6.5, 2.6.9.

Here is the direct download link:

http://lua-users.org/files/wiki_insecure/power_patches/5.0/advanced-readline.patch

Please try it and see if you like it. If you have any comments, please
send them either to the list or directly to me (mikelu AT mike "(.)" de).
Thank you!

I'm especially interested to hear if the recursive completion works with
complex libraries that use metatables extensively. I've already tried it
with luasocket and a few others and they work just fine.

Please note that the context sensitivity has some weak spots. These are
either due to the limited lua RTTI ('.' vs. ':') or due to restrictions
in the readline library (expanding 'foo.a~' to 'foo["a b"]' does not
work well).

BTW: There is an old entry in the LuaPowerPatches section referring to
     a similar patch. However the download link is broken and it's probably
     outdated anyway. That's why I wrote my patch from scratch for Lua 5.x.
     I assume my patch is a superset -- so I think the old entry should be
     removed. Any objections?

Bye,
     Mike