-- Put this file (or the parts of it you find useful) in your ~/.elinks/hooks.lua, then -- start elinks and to look up page on a symbol in HyperSpec just type -- "hs " in location window. -- One more thing I will tell you: on my machine elinks fails to run lua code if -- there is any other elinks open. Just to let you know -- if you see that something -- is not working, first check this. -- This one is needed for openfile --- enable_systems_functions () -- I used this for debugging debug_file = "/home/jdz/tmp/lua.debug" debug_on = 1 function debug (str) if debug_on and str then f = openfile (debug_file, "a+") if f then write (f, str) write (f, "\n") closefile (f) end -- Someone on irc told me this works for him. But not for me... --xdialog (str) end end clhs_root = "file:///usr/share/doc/hyperspec/" clhs_map_path = "/usr/share/doc/hyperspec/Data/Map_Sym.txt" -- Filled on first use clhs_table = nil -- Loads CLHS symbol map -- ** Maybe it is possible to use some of the elinks function to fetch -- the file by URI? -- function clhs_fill_table (table) local fh = openfile (clhs_map_path, "r") if fh then -- I could not find any sensible looping construct to accomplish this local symbol, path repeat -- read returns nil on EOF symbol = read (fh, "*l") path = read (fh, "*l") if symbol then table[symbol] = strsub (path, 4) else break end until nil closefile (fh) else debug ("Could not open HyperSpec map file: "..clhs_map_path) end end function clhs_dump_table (table) debug ("table dump:") for key, val in table do debug (key.." -> "..val) end end function clhs_lookup (str) -- Table not filled yet. Do it now. if not clhs_table then clhs_table = {} clhs_fill_table (clhs_table) end str = strupper (str) -- This was named suffix once, and I could not understand why my program -- does not work. I don't understand that now, either. It must be some -- kind of *magical* name that lua interpreter doesn't tell I should not -- use. local url_suffix = clhs_table[str] if url_suffix then return clhs_root..url_suffix else debug ("HyperSpec entry for: '"..str.."' not found!") return nil end end function match (prefix, url) return strsub (url, 1, strlen (prefix)) == prefix end -- Store the previous value of goto_url_hook. If we do not process the -- url, we call the original handler (if there was one). old_goto_url_hook = goto_url_hook function goto_url_hook (url, current_url) -- Common Lisp HyperSpec lookup if match ("hs", url) then return clhs_lookup (strsub (url, 4)) else if old_goto_url_hook then return call (old_goto_url_hook, url, current_url) else return url end end end