📄 hooks.lua.in
字号:
-- Example hooks.lua file, put in ~/.elinks/ as hooks.lua.-- $Id: hooks.lua.in,v 1.27 2004/05/01 05:29:36 miciah Exp $-- TODO: Bookmarks stuff should be completely moved to bm.lua. --pasky-- Take care about @SOMETHING@, we're processed with autoconf!------------------------------------------------------------------------ Load configuration----------------------------------------------------------------------dofile ("@sysconfdir@/config.lua")home_dir = (getenv and (getenv ("HOME") or "/home/"..getenv("USER"))) or "."dofile (elinks_home.."/config.lua")------------------------------------------------------------------------ case-insensitive gsub------------------------------------------------------------------------ Please note that this is not completely correct yet.-- It will not handle pattern classes like %a properly.-- FIXME: Handle pattern classes.function gisub (s, pat, repl, n) pat = gsub (pat, '(%a)', function (v) return '['..strupper(v)..strlower(v)..']' end) if n then return gsub (s, pat, repl, n) else return gsub (s, pat, repl) endend------------------------------------------------------------------------ goto_url_hook----------------------------------------------------------------------function match (prefix, url) return strsub (url, 1, strlen (prefix)) == prefixendfunction hx (c) return strchar((c >= 10 and (c - 10) + strbyte ('A')) or c + strbyte ('0'))endfunction char2hex (c) return '%'..hx (strbyte (c) / 16)..hx (mod(strbyte (c), 16))endfunction escape (str) return gsub (str, "(%W)", char2hex)end-- You can write smt like "gg" to goto URL dialog and it'll go to google.com.-- Note that this is obsoleted by the URI rewrite plugin.dumbprefixes = { arc = "http://web.archive.org/web/*/%c", b = "http://babelfish.altavista.com/babelfish/tr", bz = "http://bugzilla.elinks.or.cz", bug = "http://bugzilla.elinks.or.cz", d = "http://www.dict.org", g = "http://www.google.com/", gg = "http://www.google.com/", go = "http://www.google.com/", fm = "http://www.freshmeat.net/", sf = "http://www.sourceforge.net/", dbug = "http://bugs.debian.org/", dpkg = "http://packages.debian.org/", -- Hm, is this Debian-centric? -- Miciah lua = "file:///usr/share/doc/lua40-doc/manual/idx.html", pycur = "http://www.python.org/doc/current/", pydev = "http://www.python.org/dev/doc/devel/", pyhelp = "http://starship.python.net/crew/theller/pyhelp.cgi", pyvault = "http://www.vex.net/parnassus/", e2 = "http://www.everything2.org/", sd = "http://www.slashdot.org/", vhtml = "http://validator.w3.org/check?uri=%c", vcss = "http://jigsaw.w3.org/css-validator/validator?uri=%c",}function debian_contents (url) local t = {} url = gsub(url, '(%w+):(%w+)', function (key, val) %t[key] = val end) return 'http://packages.debian.org/cgi-bin/search_contents.pl?word=' ..escape(gsub(url, '%s*([^%s]+)%s*', '%1')) ..'&searchmode='..(t.searchmode or 'searchfilesanddirs') ..'&case='..(t.case or 'insensitive') ..'&version='..(t.version or pipe_read('cut -d/ -f1 /etc/debian_version | tr -d \\\\n') or 'stable') ..'&arch='..(t.arch or gsub(pipe_read('uname -m | tr -d \\\\n'), 'i%d86', 'i386') or 'i386') -- like this'll work...endfunction cvsweb (base, project, url) local t = {n=0} local file, old, new local replacements -- allow <file>:<revision>[-><revision>] url,replacements = gsub(url, "^(.*):(.*)->(.*)$", "%1 %2 %3") if replacements == 0 then url = gsub(url, "^(.*):(.*)$", "%1 %2") end -- split into words gsub(url, "([^%s]+)", function (w) tinsert(%t, w) end) file, old, new = t[1], t[2], t[3] if t[4] then error('this smartprefix takes only two to three arguments') return nil end if not file then error('no file given') return nil end if new then return base..project.."/"..file..".diff?r1="..old.."&r2="..new.."&f=u" elseif old then return base.."~checkout~/"..project.."/"..file..(old ~= "latest" and "?rev="..old or "") else return base..project.."/"..file endendfunction gmane (url) local group, words _,_,group,words = strfind(url, "([^%s]+)%s%s*(.*)$") if not words then return nil end return "http://search.gmane.org/search.php?query="..words.."&group="..groupend-- You can write "gg:foo" or "gg foo" to goto URL dialog and it'll ask google-- for it automagically.-- Note that this is _mostly_ obsoleted by the URI rewrite plugin. (It can't do the-- metas, though.)smartprefixes = { arc = "http://web.archive.org/web/*/%s", bb = "http://babelfish.altavista.com/babelfish/tr?urltext=%s", bb_fr_en = "http://babelfish.altavista.com/babelfish/tr?lp=fr_en&submit=1&urltext=%s", bb_en_fr = "http://babelfish.altavista.com/babelfish/tr?lp=en_fr&submit=1&urltext=%s", bug = "http://bugzilla.elinks.or.cz/show_bug.cgi?id=%s", cambridge = "http://dictionary.cambridge.org/results.asp?searchword=%s", cliki = "http://www.cliki.net/admin/search?words=%s", -- If you want to add a smartprefix for another project's CVSweb, -- just create a lambda like this. Aren't high-level languages fun? cvs = function (x) return cvsweb ("http://cvsweb.elinks.or.cz/cvsweb.cgi/", "elinks", x) end, d = "http://www.dict.org/bin/Dict?Query=%s&Form=Dict1&Strategy=*&Database=*&submit=Submit+query", debcontents = debian_contents, dmoz = "http://search.dmoz.org/cgi-bin/search?search=%s", foldoc = "http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?%s", g = "http://www.google.com/search?q=%s&btnG=Google+Search", gd = "http://www.google.com/search?q=%s&cat=gwd/Top", gg = "http://www.google.com/search?q=%s&btnG=Google+Search", -- Whose idea was it to use 'gg' for websearches? -- Miciah --gg = "http://groups.google.com/groups?q=%s", gi = "http://images.google.com/images?q=%s", gmane = gmane, gn = "http://news.google.com/news?q=%s", go = "http://www.google.com/search?q=%s&btnG=Google+Search", gwho = "http://www.googlism.com/?ism=%s&name=1", gwhat = "http://www.googlism.com/?ism=%s&name=2", gwhere = "http://www.googlism.com/?ism=%s&name=3", gwhen = "http://www.googlism.com/?ism=%s&name=4", fm = "http://www.freshmeat.net/search/?q=%s", savannah = "http://savannah.nongnu.org/search/?words=%s&type_of_search=soft&exact=1", sf = "http://sourceforge.net/search/?q=%s", sfp = "http://sourceforge.net/projects/%s", sd = "http://www.slashdot.org/search.pl?query=%s", sdc = "http://www.slashdot.org/search.pl?query=%s&op=comments", sdu = "http://www.slashdot.org/search.pl?query=%s&op=users", sdp = "http://www.slashdot.org/search.pl?query=%s&op=polls", sdj = "http://www.slashdot.org/search.pl?query=%s&op=journals", dbug = "http://bugs.debian.org/%s", dpkg = "http://packages.debian.org/%s", emacs = "http://www.emacswiki.org/cgi-bin/wiki.pl?search=%s", lyrics = "http://music.lycos.com/lyrics/results.asp?QT=L&QW=%s", lxr = "http://lxr.linux.no/ident?i=%s", onelook = "http://onelook.com/?w=%s&ls=a", py = "http://starship.python.net/crew/theller/pyhelp.cgi?keyword=%s&version=current", pydev = "http://starship.python.net/crew/theller/pyhelp.cgi?keyword=%s&version=devel", pyvault = "http://py.vaults.ca/apyllo.py?find=%s", e2 = "http://www.everything2.org/?node=%s", encz = "http://www.slovnik.cz/bin/ecd?ecd_il=1&ecd_vcb=%s&ecd_trn=translate&ecd_trn_dir=0&ecd_lines=15&ecd_hptxt=0", czen = "http://www.slovnik.cz/bin/ecd?ecd_il=1&ecd_vcb=%s&ecd_trn=translate&ecd_trn_dir=1&ecd_lines=15&ecd_hptxt=0", dict = "http://dictionary.reference.com/search?q=%s", thes = "http://thesaurus.reference.com/search?q=%s", a = "http://acronymfinder.com/af-query.asp?String=exact&Acronym=%s", imdb = "http://imdb.com/Find?%s", mw = "http://www.m-w.com/cgi-bin/dictionary?book=Dictionary&va=%s", mwt = "http://www.m-w.com/cgi-bin/thesaurus?book=Thesaurus&va=%s", whatis = "http://uptime.netcraft.com/up/graph/?host=%s", wiki = "http://www.wikipedia.org/w/wiki.phtml?search=%s", wn = "http://www.cogsci.princeton.edu/cgi-bin/webwn1.7.1?stage=1&word=%s", -- rfc by number rfc = "http://www.rfc-editor.org/rfc/rfc%s.txt", -- rfc search rfcs = "http://www.rfc-editor.org/cgi-bin/rfcsearch.pl?searchwords=%s&format=http&abstract=abson&keywords=keyon&num=25", cr = "http://www.rfc-editor.org/cgi-bin/rfcsearch.pl?searchwords=%s&format=http&abstract=abson&keywords=keyon&num=25", -- Internet Draft search rfcid = "http://www.rfc-editor.org/cgi-bin/idsearch.pl?searchwords=%s&format=http&abstract=abson&keywords=keyon&num=25", id = "http://www.rfc-editor.org/cgi-bin/idsearch.pl?searchwords=%s&format=http&abstract=abson&keywords=keyon&num=25", draft = "http://www.rfc-editor.org/cgi-bin/idsearch.pl?searchwords=%s&format=http&abstract=abson&keywords=keyon&num=25",}function goto_url_hook (url, current_url) if dumbprefixes[url] then if current_url then return gsub(dumbprefixes[url], "%%c", current_url) else return dumbprefixes[url] end end if strfind(url,'%s') or strfind(url, ':') then local _,_,nick,val = strfind(url, "^([^%s:]+)[:%s]%s*(.-)%s*$") if nick and smartprefixes[nick] then if type(smartprefixes[nick]) == 'function' then return smartprefixes[nick](val) elseif type(smartprefixes[nick]) == 'string' then return format(smartprefixes[nick], escape(val)) else error('smartprefix "'..nick..'" has unsupported type "' ..type(smartprefixes[nick])..'".') return nil end end end -- Expand ~ to home directories. if match ("~", url) then if strsub(url, 2, 2) == "/" or strlen(url) == 1 then -- ~/foo return home_dir..strsub(url, 2) else -- ~foo/bar return "/home/"..strsub(url, 2) end end -- Don't take localhost as directory name if match("localhost", url) then return "http://"..url end -- Unmatched. return urlend------------------------------------------------------------------------- follow_url_hook---------------------------------------------------------------------function follow_url_hook (url) -- Using bookmark addon. if bookmark_addon then if bm_is_category (url) then return nil else return bm_get_bookmark_url (url) or url end -- Not using bookmark addon. else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -