command entry suggestion

From: Jay <>
Date: Wed, 28 Apr 2010 00:46:08 -0700 (PDT)

The last one for today...
as I was fixing stuff here and there today I was using the "command
entry" for debug purposes.
and realized how much typing was required.
so I came up with an idea to bind a utility environment to the
incoming command functions

my prototype yet functional code looks like this:

local util = setmetatable({},{__index = function(e,k)
        -- most operations are buffer shortcut
        local v = buffer[k]
        if v then
                if type(v)=="function" then
                        v = function(...)
        else -- or bindings to textadept
                v = textadept[k] or _G[k] -- if nothing was found default to global
        e[k] = v --memoize the key
        return v
  function(command) -- execute a Lua command
    local f, err = loadstring(command)
    if err then error(err) end
    textadept.command_entry.focus() -- toggle focus to hide

This way the command entry allows stuff like
> insert_text(current_pos,"hello")
instead of the more verbose
> buffer:insert_text(buffer.current_pos,"hello")

another cool feature of this is that we can define util functions for
the command entry like this:

util.insertf = function (text,...)
        buffer:insert_text(buffer.current_pos, tostring(text):format(...))

so we can do this
> insertf("current position is: %d",current_pos)

Any suggestions about what to do with this?


You received this message because you are subscribed to the Google Groups "textadept" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at
Received on Wed 28 Apr 2010 - 03:46:08 EDT

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