[code] [textadept] Strange behavior of ui.command_entry.finish_mode

From: Brandon Irizarry <brandon.irizarry.att.gmail.com>
Date: Sat, 8 Dec 2018 23:41:23 -0500

Hello Mitchell and forum,

I'm trying out this function from the Quick Reference (4th ed.) on page 84:

function complete_filename()
    local files = {}
    local path = ui.command_entry:get_text()
    local dir, part = path:match("^(.-)([^/\\]*)$")
    if dir == "" then dir = lfs.currentdir() end
    if lfs.attributes(dir, "mode") == "directory" then
        part = "^" .. part
        lfs.dir_foreach(dir, function(f)
            f = f:match("[^/\\]+[/\\]?$")
            if f:find(part) then files[#files + 1] = f end
        end, nil, 0, true)
        table.sort(files)
        local list = table.concat(files, " ")
        ui.command_entry:auto_c_show(#part - 1, list)
    end
end

-- Define the file open mode and bind it to Ctrl+O.
keys.file_opener = {
    ["\t"] = complete_filename,
    ["\n"] = function ()
        return ui.command_entry.finish_mode(io.open_file)
    end
}

keys.co = function()
    ui.command_entry.enter_mode("file_opener")
end

However, when I try to use this to open I file, I get the following error:

/usr/local/share/textadept/core/file_io.lua:126: attempt to index a number
value (local 'encodings')

I've even tried looking at the code there, and I see this:

if encodings[i] then
      buffer.encoding, text = encodings[i], text:iconv('UTF-8',
encodings[i])
    else
<snip>

Yet, I try calling io.open_file on a single string input, and it works
file.

Any help is appreciated.

Regards,

Brandon

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Sat 08 Dec 2018 - 23:41:23 EST

This archive was generated by hypermail 2.2.0 : Sun 09 Dec 2018 - 06:43:13 EST