Lumail - The console email client


Examples: address_book()

Lumail contains extensive TAB-completion support, which by default will allow completion upon the built-in primitives which it exports, as well as functions you might define yourself.

To allow you to add your own completions the on_complete() hook is defined. This will allow you to populate a Lua table whth things that can be completed.

Because all input is handled via the same primitive, and the completion table is global, you can add TAB-completion of recipients by using the on_complete() function.

The following example reads lines from ~/.address-book, if it exists and adds the addresses read (one per line) to the list of completion options:

--
-- This function is called at run-time when TAB-completion is invoked.
--
-- The function is expected to return a Lua table, the values of which
-- will be used for completion.  (The keys being ignored.)
--
-- Here we add any user-defined function the to the completion set.
-- This works because Lua uses the global "_G" table to store functions, etc.
--
-- We also add the contents of ~/.address-book, if it exists, as completions
-- to allow completion of message-recipients.
--
function on_complete()
   ret = {}

   for k,v in pairs(_G) do
      ret[k] = k .. "();"
   end

   --
   -- Add ~/.address-book if it exists
   --
   if ( exists( os.getenv( "HOME" ) .. "/.address-book" ) ) then
      file = assert(io.open( os.getenv( "HOME" ) .. "/.address-book", "r"))
      for line in file:lines() do
         ret[line]= line
      end
   end

   return(ret)
end