summaryrefslogtreecommitdiff
path: root/support/texdoc/script
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2024-02-03 03:02:06 +0000
committerNorbert Preining <norbert@preining.info>2024-02-03 03:02:06 +0000
commit8d5a9f6bbecb297f513b9ed16e574db1c1310228 (patch)
tree4d9e1be6863ce68eb23b545add6e000edff4817c /support/texdoc/script
parentb5a938a222c59addea5ca0a22cd53b2bbf66e1fa (diff)
CTAN sync 202402030302
Diffstat (limited to 'support/texdoc/script')
-rw-r--r--support/texdoc/script/texdoclib-cli.tlu32
-rw-r--r--support/texdoc/script/texdoclib-const.tlu20
-rw-r--r--support/texdoc/script/texdoclib-score.tlu19
3 files changed, 42 insertions, 29 deletions
diff --git a/support/texdoc/script/texdoclib-cli.tlu b/support/texdoc/script/texdoclib-cli.tlu
index 5eddc8f7f5..79c202600d 100644
--- a/support/texdoc/script/texdoclib-cli.tlu
+++ b/support/texdoc/script/texdoclib-cli.tlu
@@ -21,32 +21,36 @@ local err_print = texdoc.util.err_print
-- modified Alternative GetOpt
-- cf. http://lua-users.org/wiki/AlternativeGetOpt
local function getopt(arg, options)
- local tmp = nil
+ local tmp
local tab = {}
local saved_arg = {table.unpack(arg)}
for k, v in ipairs(saved_arg) do
- if string.sub(v, 1, 2) == '--' then
+ if v:sub(1, 2) == '--' then
table.remove(arg, 1)
- local x = string.find(v, '=', 1, true)
+ if v == '--' then -- terminate parsing
+ break
+ end
+
+ local x = v:find('=', 1, true)
if x then
- table.insert(tab, {string.sub(v, 3, x - 1), string.sub(v, x+1)})
+ table.insert(tab, {v:sub(3, x - 1), v:sub(x+1)})
else
- table.insert(tab, {string.sub(v, 3), true})
+ table.insert(tab, {v:sub(3), true})
end
- elseif string.sub(v, 1, 1) == '-' then
+ elseif v:sub(1, 1) == '-' then
table.remove(arg, 1)
local y = 2
- local l = string.len(v)
+ local l = v:len()
local jopt
while (y <= l) do
- jopt = string.sub(v, y, y)
+ jopt = v:sub(y, y)
- if string.find(options, jopt, 1, true) then
+ if options:find(jopt, 1, true) then
if y < l then
- tmp = string.sub(v, y + 1)
+ tmp = v:sub(y + 1)
y = l
else
table.remove(arg, 1)
@@ -60,7 +64,7 @@ local function getopt(arg, options)
os.exit(C.exit_error)
end
- if string.match(tmp, '^%-') then
+ if tmp:match('^%-') then
table.insert(tab, {jopt, false})
else
table.insert(tab, {jopt, tmp})
@@ -102,14 +106,14 @@ local function parse_options()
end
for i, o in ipairs(C.options) do
- if k == o["short"] or k == o["long"] then
+ if k == o['short'] or k == o['long'] then
k = i
break
end
end
option = C.options[k]
- if option['group'] == 'action' then
+ if option ~= nil and option['group'] == 'action' then
if option['long'] == 'just-view' then
return true, 'view', cl_config
elseif option['long'] == 'print-completion' then
@@ -117,7 +121,7 @@ local function parse_options()
else
return true, option['long'], cl_config
end
- elseif option['group'] then
+ elseif option~=nil and option['group'] then
if option['type'] == 'boolean' then
option['action'](cl_config, curr_arg)
elseif option['type'] == 'string' then
diff --git a/support/texdoc/script/texdoclib-const.tlu b/support/texdoc/script/texdoclib-const.tlu
index c551bf40ef..1088c25e5e 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.1'
-release_date = '2023-02-27'
+version = '4.0.2'
+release_date = '2024-02-02'
-- make sure to update setup_config_from_cl() accordingly
-- and set a default value in setup_config_from_defaults() if relevant
@@ -50,8 +50,8 @@ Website: <https://tug.org/texdoc/>
Repository: <https://github.com/TeX-Live/texdoc>
Please email bugs to <texdoc@tug.org>.]]
-zsh_completion = [[
-compdef __texdoc texdoc
+zsh_completion = [=[
+#compdef texdoc
__texdoc() {
local options=(
@@ -72,7 +72,15 @@ __texdoc() {
;;
esac
}
-]]
+
+if [[ $zsh_eval_context[-1] == loadautofunc ]]; then
+ # autoload from fpath, call function directly
+ __texdoc "$@"
+else
+ # eval/source/. command, register function for later
+ compdef __texdoc texdoc
+fi
+]=]
--[[ structure of the options table
@@ -260,7 +268,7 @@ options = {
}
copyright_msg = [[
-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.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.]]
diff --git a/support/texdoc/script/texdoclib-score.tlu b/support/texdoc/script/texdoclib-score.tlu
index 7124a834e4..11befc7ed9 100644
--- a/support/texdoc/script/texdoclib-score.tlu
+++ b/support/texdoc/script/texdoclib-score.tlu
@@ -212,7 +212,7 @@ local function set_score(df, original_kw)
-- bonus for locale
local config_lang = texdoc.config.get_value('lang')
- if not is_alias and config_lang ~= nil then
+ if not is_alias then
local file_lang = df.lang
if not file_lang then
@@ -220,10 +220,12 @@ local function set_score(df, original_kw)
file_lang = texdoc.const.lang_codes[file_lang]
end
- if config_lang == file_lang then
+ if config_lang ~= nil and config_lang == file_lang then
score = score + 1
dbg_score('Locale match bonus: +1.0')
- elseif file_lang ~= nil then
+ 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)
score = score - 0.1
dbg_score('Locale unmatch: -0.1')
end
@@ -308,19 +310,18 @@ end
-- returns the index of the most specific extension of file in ext_list,
-- or config.ext_list_max + 1
-function M.ext_pos(file)
+function M.ext_pos(filename)
-- remove zipext if applicable
- file = texdoc.util.parse_zip(file)
+ filename = texdoc.util.parse_zip(filename)
-- now find the extension
local p, e, pos, ext
for p, e in ipairs(texdoc.config.get_value('ext_list')) do
if (e == '*') and (ext == nil) then
pos, ext = p, e
- elseif (e == '') and not string.find(file, '.', 1, true) then
+ elseif (e == '') and not filename:find('.', 1, true) then
pos, ext = p, e
- elseif string.sub(file, -string.len(e)-1) == '.' .. e then
- if (ext == nil) or (ext == '*')
- or (string.len(e) > string.len(ext)) then
+ elseif filename:sub(-e:len() - 1) == '.' .. e then
+ if (ext == nil) or (ext == '*') or (e:len() > ext:len()) then
pos, ext = p, e
end
end