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

From: Mitchell <m.att.foicica.com>
Date: Sat, 8 Dec 2018 23:47:41 -0500 (EST)

Hi Brandon,

On Sat, 8 Dec 2018, Brandon Irizarry wrote:

> 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.

I think you've found a bug. If you modify *modules/textadept/command_entry.lua:106* by changing

   if f then f(M:get_text()) end

to

   if f then f((M:get_text())) end

it should work. (Note the extra parentheses around `M:get_text()`.)

I'll commit a fix that will be in the nightly for 09 December (too late for tonight's nightly).

Sorry for the inconvenience, but thanks for the report.

Cheers,
Mitchell

-- 
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:47:41 EST

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