[code] [textadept] Fix for error in help switch handler

From: Gabriel Bertilson <arboreous.philologist.att.gmail.com>
Date: Thu, 9 Jan 2020 15:59:06 -0600

When I run "ta --help" (this is the GUI version of Textadept 10.8 on
Linux), it opens the window with a message buffer that says
"<textadept directory>/core/args.lua:70: bad argument #3 to 'format'
(no value)".

This error occurs while the handler for -h or --help is iterating over
the list of switches. There's no description text for the -l or --line
switch, so a format argument is missing. Since the handler errors out,
it fails to call os.exit(), so the window is opened or left open. I
discovered this by replacing line 70 in core/args.lua with the
following:

for k, v in pairs(switches) do
  local narg, description = table.unpack(v, 2)
  if not (narg and description) then
    io.stderr:write(("Arg %s is missing narg %q or description
%q\n"):format(k, narg, description))
  else
    print(line:format(k, narg, description))
  end
end

This can be fixed by adding a description for the arguments added in
line 357 of modules/textadept/editing.lua:

- args.register('-l', '--line', 1, function(line) M.goto_line(line - 1) end)
+ args.register('-l', '--line', 1, function(line) M.goto_line(line -
1) end, "Go to line")

I wonder if this problem hasn't been noticed because almost nobody has
tried using the --help switch since the --line argument was added!

— Gabriel

-- 
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 Thu 09 Jan 2020 - 16:59:06 EST

This archive was generated by hypermail 2.2.0 : Fri 10 Jan 2020 - 06:31:41 EST