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

From: Brandon Irizarry <brandon.irizarry.att.gmail.com>
Date: Sun, 9 Dec 2018 08:34:22 -0500

Hi Mitchell,

I added those parentheses, and it works now. Thanks!

- Brandon

On Sat, Dec 8, 2018 at 11:48 PM Mitchell <m.att.foicica.com> wrote:

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

-- 
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 Sun 09 Dec 2018 - 08:34:22 EST

This archive was generated by hypermail 2.2.0 : Mon 10 Dec 2018 - 06:38:07 EST