summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Pégourié-Gonnard <mpg@elzevir.fr>2008-07-25 23:58:05 +0000
committerManuel Pégourié-Gonnard <mpg@elzevir.fr>2008-07-25 23:58:05 +0000
commitc331ebf222e05ae278abb62bfa66cd223cf68a0c (patch)
tree5cce7f2329d811552e8dfe8fe0b7591418071d36
parentc8350a940eb070c0270dd3d8837f08bd526405f6 (diff)
New menu feature. Also changed mixed_search to use original_docname, better catching errors while viewing, and fixed the commands for default text-mode viewers.
git-svn-id: svn://tug.org/texlive/trunk@9776 c570f23f-e606-0410-a88d-b1316a301751
-rwxr-xr-xMaster/texmf/scripts/texlive/texdoc.tlu106
1 files changed, 81 insertions, 25 deletions
diff --git a/Master/texmf/scripts/texlive/texdoc.tlu b/Master/texmf/scripts/texlive/texdoc.tlu
index 2ac6cffcdbf..bd080a6caa4 100755
--- a/Master/texmf/scripts/texlive/texdoc.tlu
+++ b/Master/texmf/scripts/texlive/texdoc.tlu
@@ -199,12 +199,12 @@ function filename_search (filename)
end
-- do a filename search and try a full search if unsuccessfull
-function mixed_search (filename)
+function mixed_search (filename, alternative)
results = filename_search (filename)
if not results[1] then
print ("texdoc info: No result with simple search, "..
"trying full search mode.")
- results = pattern_search (filename)
+ results = pattern_search (alternative)
end
return results
end
@@ -352,46 +352,46 @@ function setup_config_from_defaults()
viewer_html = '(open %s)',
viewer_pdf = '(open %s)',
viewer_ps = '(open %s)',
- viewer_txt = '(less %s)',
+ viewer_txt = 'less',
}
else
set_config_list {
viewer_dvi = first_in_path {
- {'see', '(see %s) &'},
{'evince', '(evince %s) &'},
{'okular', '(okular %s) &'},
{'kdvi', '(kdvi %s) &'},
- {'xdvi', '(xdvi %s) &'}
+ {'xdvi', '(xdvi %s) &'},
+ {'see', '(see %s) &'}
},
viewer_html = first_in_path {
- {'see', '(see %s) &'},
{'firefox', '(firefox %s) &'},
{'mozilla', '(mozilla %s) &'},
{'konqueror', '(konqueror %s) &'},
{'epiphany', '(epiphany %s) &'},
{'opera', '(opera %s) &'},
- {'w3m', '(w3m %s) &'},
- {'links', '(links %s) &'},
- {'lynx', '(lynx %s) &'}
+ {'w3m', 'w3m'},
+ {'links', 'links'},
+ {'lynx', 'lynx'},
+ {'see', 'see'}
},
viewer_pdf = first_in_path {
- {'see', '(see %s) &'},
{'evince', '(evince %s) &'},
{'okular', '(okular %s) &'},
{'kpdf', '(kpdf %s) &'},
- {'xpdf', '(xpdf %s) &'}
+ {'xpdf', '(xpdf %s) &'},
+ {'see', '(see %s) &'}
},
viewer_ps = first_in_path {
- {'see', '(see %s) &'},
{'evince', '(evince %s) &'},
{'okular', '(okular %s) &'},
{'kghostview', '(kghostview %s) &'},
- {'gv', '(gv %s) &'}
+ {'gv', '(gv %s) &'},
+ {'see', '(see %s) &'}
},
viewer_txt = first_in_path {
- {'most', '(most %s)'},
- {'less', '(less %s)'},
- {'more', '(more %s)'}
+ {'most', 'most'},
+ {'less', 'less'},
+ {'more', 'more'}
}
}
end
@@ -503,6 +503,57 @@ function print_ordered_byext (files_list)
end
end
+-- compare two files with the following rule:
+-- 1. extensions are ordered as in ext_list first,
+-- 2. then filenames lexicograhpicaly.
+function file_order (a, b)
+ local ext_a = string.match (a, '^.*%.(.*)$')
+ local ext_b = string.match (b, '^.*%.(.*)$')
+ if ext_pos(ext_a) < ext_pos(ext_b) then
+ return true
+ elseif ext_pos(ext_a) > ext_pos(ext_b) then
+ return false
+ else
+ return (a < b)
+ end
+end
+
+-- return the position of ext in ext_list, and greater value if not in ext_list
+-- magic inside: compute ext_reverse only once
+function ext_pos (ext)
+ local ext_rev = {}
+ local max
+ for i, ext in ipairs (config.ext_list) do
+ ext_rev[ext] = i
+ max = i
+ end
+ ext_pos = function (e)
+ return ext_rev[e] or (max + 1)
+ end
+ return ext_pos (ext)
+end
+
+-- print a list of files as a menu
+function print_menu (files)
+ local n = #files
+ if n > 20 then
+ io.write (n, " files found. Display the complete list? (y/N) ")
+ local ans = io.read(1)
+ if not ((ans == 'y') or (ans == 'Y')) then return end
+ end
+ -- table.sort(results, file_order)
+ for i, file in ipairs (files) do
+ print (i, file)
+ end
+ io.write ("Please enter the number of the file to view, or 0 to exit: ")
+ local num = io.read('*number')
+ if num and files[num] then
+ print ("Viewing file '"..files[num].."'.")
+ elseif num ~= 0 then
+ print ("Incorrect input, skipping.")
+ end
+end
+
-- apologize/complain if something went wrong
function apologize (reason, name)
if reason == 'notfound' then
@@ -612,37 +663,42 @@ end
-- the main loop over the args
exit_code = 0
for docname in list (arg) do
+ original_docname = docname
if (alias[docname] and (config.enable_alias == 'true')) then
print ("texdoc info: "..docname.." aliased to "..alias[docname])
- original_docname = docname
- docname = alias[original_docname]
+ docname = alias[docname]
end
local docfound = false
if (config.mode == 'search') then
results = pattern_search (docname)
- print_ordered_byext (results)
+ if results[1] then
+ print_menu (results)
+ else
+ apologize ('notfound', docname)
+ end
elseif (config.mode == 'list') then
- results = mixed_search (docname)
+ results = mixed_search (docname, original_docname)
if results[1] then
- print_ordered_byext (results)
+ print_menu (results)
else
apologize ('notfound', docname)
end
elseif (config.mode == 'view') then
- results = mixed_search (docname)
+ results = mixed_search (docname, original_docname)
if results[1] then
try_viewing (how_to_view(results[1]))
else
apologize ('notfound', docname)
end
elseif (config.mode == 'mixed') then
- results = mixed_search (docname)
+ results = mixed_search (docname, original_docname)
if (not results[1]) then -- no results
apologize ('notfound', docname)
elseif (not results[2]) then -- 1 result (faster than table.maxn)
- try_viewing (how_to_view(results[1]))
+ local ok = try_viewing (how_to_view(results[1]))
+ if not ok then apologize ('oops') end
else -- 2 or more results
- print_ordered_byext (results)
+ print_menu (results)
end
end -- if construct "case config.mode in"
end -- for docname in arg