From d0e99dfc632984d24851f9160409ef583a011f48 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 11 Mar 2024 03:02:52 +0000 Subject: CTAN sync 202403110302 --- support/texdoc/script/texdoclib-config.tlu | 2 +- support/texdoc/script/texdoclib-const.tlu | 4 +- support/texdoc/script/texdoclib-score.tlu | 12 ++- support/texdoc/script/texdoclib-view.tlu | 138 +++++++++++++++++------------ support/texdoc/script/texdoclib.tlu | 2 +- 5 files changed, 96 insertions(+), 62 deletions(-) (limited to 'support/texdoc/script') diff --git a/support/texdoc/script/texdoclib-config.tlu b/support/texdoc/script/texdoclib-config.tlu index ad9f852ea7..881a556805 100644 --- a/support/texdoc/script/texdoclib-config.tlu +++ b/support/texdoc/script/texdoclib-config.tlu @@ -592,7 +592,7 @@ local function setup_config_from_defaults() suffix_list = '', verbosity_level = C.def_verbosity, debug_list = '', - max_lines = '20', + max_lines = '10', fuzzy_level = '3', online_url = 'https://texdoc.org/serve/PKGNAME/0', } diff --git a/support/texdoc/script/texdoclib-const.tlu b/support/texdoc/script/texdoclib-const.tlu index 1088c25e5e..5a6b8256d3 100644 --- a/support/texdoc/script/texdoclib-const.tlu +++ b/support/texdoc/script/texdoclib-const.tlu @@ -22,8 +22,8 @@ end -- progname and version fullname = kpse.find_file('texdoc/texdoclib', 'lua') progname = 'Texdoc' -version = '4.0.2' -release_date = '2024-02-02' +version = '4.1' +release_date = '2024-03-10' -- make sure to update setup_config_from_cl() accordingly -- and set a default value in setup_config_from_defaults() if relevant diff --git a/support/texdoc/script/texdoclib-score.tlu b/support/texdoc/script/texdoclib-score.tlu index 11befc7ed9..3fcccf8788 100644 --- a/support/texdoc/script/texdoclib-score.tlu +++ b/support/texdoc/script/texdoclib-score.tlu @@ -213,8 +213,15 @@ local function set_score(df, original_kw) -- bonus for locale local config_lang = texdoc.config.get_value('lang') if not is_alias then - local file_lang = df.lang + local file_lang + -- from its catalogue + if df.lang then + -- take first two letters; it may have country codes + file_lang = df.lang:sub(1, 2) + end + + -- from its filename if not file_lang then _, file_lang, _ = parse(name) file_lang = texdoc.const.lang_codes[file_lang] @@ -225,7 +232,8 @@ local function set_score(df, original_kw) dbg_score('Locale match bonus: +1.0') elseif file_lang ~= nil and file_lang ~= 'en' then -- normally, english documents do not have file_lang, - -- but sometimes the catalog includes en info (e.g., geometry) + -- but sometimes catalogue includes en info (e.g., geometry) + -- we want to treat both cases similar score = score - 0.1 dbg_score('Locale unmatch: -0.1') end diff --git a/support/texdoc/script/texdoclib-view.tlu b/support/texdoc/script/texdoclib-view.tlu index 3bf6860a35..15fd5c940b 100644 --- a/support/texdoc/script/texdoclib-view.tlu +++ b/support/texdoc/script/texdoclib-view.tlu @@ -161,76 +161,101 @@ end ----------------------------- display results ----------------------------- +-- length of the list to be shown +local function count_list_length(doclist, showall) + local res = 0 + for _, doc in pairs(doclist) do + if doc:get_quality() == 'good' or + (showall and doc:get_quality() ~= 'killed') then + res = res + 1 + end + end + return res +end + +-- parse user response and view the file +local function view_selected_doc(doclist, num_str, last_i) + -- That returns the empty string on an empty line, nil on EOF. + -- We only want to default to viewing 1 on an empty line. + -- Use Lua's faked ternary operator for fun and brevity: + num = (num_str == '' and 1 or tonumber(num_str)) + if num and doclist[num] and num <= last_i then + view_doc(doclist[num]) + end +end + -- print a list of docfile objects (see texdoclib-search.tlu) as a menu -- if showall is false, stop as soon as a bad result is encountered -local function print_menu(name, doclist, showall) +local function print_doclist(name, doclist, showall) local max_lines = tonumber(texdoc.config.get_value('max_lines')) - if texdoc.config.get_value('interact_switch') and doclist[max_lines + 1] then - -- there may be too many lines, count them - local n = 0 - for _, doc in pairs(doclist) do - if doc:get_quality() == 'good' or - (showall and doc:get_quality() ~= 'killed') then - n = n + 1 - end - end + local interact = texdoc.config.get_value('interact_switch') + + local last_i = 0 + local prompt_more = false + + local len = count_list_length(doclist, showall) + if interact and len > max_lines then + local msg = '%d results. Only the top %d are shown below.' + print(msg:format(len, max_lines)) + prompt_more = true + elseif len == 0 then -- nothing to show + return last_i + end - if n > max_lines then - io.write(n, ' results. Display them all? (y/N) ') - local ans = io.read('*line') - if not ((ans == 'y') or (ans == 'Y') - -- io.read had a bug wrt windows eol on some versions of texlua - or (ans == '\ry') or (ans == '\rY')) then - return + for i, doc in ipairs(doclist) do + if doc:get_quality() == 'killed' then break end + if doc:get_quality() ~= 'good' and not showall then break end + + last_i = i -- save for testing + if texdoc.config.get_value('machine_switch') == true then + -- for machine-readable output, list all results in a certain format + print(name, doc.score, texdoc.util.w32_path(doc.realpath), + doc.lang or '', doc.details or '') + else + print(string.format('%2d %s', i, texdoc.util.w32_path(doc.realpath))) + if doc.details or doc.lang then + local line = ' = ' + if doc.lang then line = line .. '[' .. doc.lang .. '] ' end + if doc.details then line = line .. doc.details end + print(line) end - end - end - local last_i - while true do - for i, doc in ipairs(doclist) do - if doc:get_quality() == 'killed' then break end - if doc:get_quality() ~= 'good' and not showall then break end - - last_i = i -- save for test below - if texdoc.config.get_value('machine_switch') == true then - print(name, doc.score, texdoc.util.w32_path(doc.realpath), - doc.lang or '', doc.details or '') - else - print(string.format('%2d %s', i, texdoc.util.w32_path(doc.realpath))) - if doc.details or doc.lang then - local line = ' = ' - if doc.lang then line = line .. '[' .. doc.lang .. '] ' end - if doc.details then line = line .. doc.details end - print(line) + + if i >= max_lines and prompt_more then + io.write('Enter number of file to view, RET to view 1, S to show all results, ' .. + 'or any other key to exit: ') + local ans = io.read('*line') + if ans == 'S' then + prompt_more = false -- and continue this loop + else + view_selected_doc(doclist, ans, last_i) + return last_i -- which should be always positive end end end + end - if last_i or showall then - break - else - err_print('warning', 'No good result found, showing all results.') - showall = true - end + if interact then + io.write('Enter number of file to view, RET to view 1, anything else to skip: ') + view_selected_doc(doclist, io.read('*line'), last_i) + end + + return last_i +end + +-- wrapper function for print_doclist(): we could call it twice +local function print_list_menu(name, doclist, showall) + local last_i = print_doclist(name, doclist, showall) + + if not showall and last_i == 0 then + err_print('warning', 'No good result found, showing all results.') + last_i = print_doclist(name, doclist, true) end - if not last_i then + if last_i == 0 then local msg = string.gsub(C.notfound_msg, C.notfound_msg_ph, name) io.stderr:write(msg .. '\n') -- get rid of gsub's 2nd value os.exit(C.exit_notfound) end - - if texdoc.config.get_value('interact_switch') then - io.write('Enter number of file to view, RET to view 1, anything else to skip: ') - local num_str = io.read('*line') - -- That returns the empty string on an empty line, nil on EOF. - -- We only want to default to viewing 1 on an empty line. - -- Use Lua's faked ternary operator for fun and brevity: - num = (num_str == '' and 1 or tonumber(num_str)) - if num and doclist[num] and num <= last_i then - view_doc(doclist[num]) - end - end end local function search_online(name, doclist) @@ -296,6 +321,7 @@ function M.deliver_results(name, doclist, many) io.stderr:write(msg .. '\n') -- get rid of gsub's 2nd value os.exit(C.exit_notfound) end + -- shall we show all of them or only the "good" ones? local mode = texdoc.config.get_value('mode') @@ -310,7 +336,7 @@ function M.deliver_results(name, doclist, many) if many and not texdoc.config.get_value('machine_switch') then print('*** Results for: ' .. name .. ' ***') end - print_menu(name, doclist, mode == 'showall') + print_list_menu(name, doclist, mode == 'showall') else search_online(name, doclist) end diff --git a/support/texdoc/script/texdoclib.tlu b/support/texdoc/script/texdoclib.tlu index 83c300833e..d2c7d8996a 100644 --- a/support/texdoc/script/texdoclib.tlu +++ b/support/texdoc/script/texdoclib.tlu @@ -1,7 +1,7 @@ -- texdoclib.tlu: the texdoc library --[[ -Copyright 2008-2023 Manuel Pégourié-Gonnard, Takuto Asakura, the TeX Live Team. +Copyright 2008-2024 Manuel Pégourié-Gonnard, Takuto Asakura, the TeX Live Team. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software -- cgit v1.2.3