require ("awful") require ("naughty") -- Many of what's used here should have been loaded already! local spawn = awful.util.spawn local gsub = string.gsub local match = string.match -- `mypromptbox' should be defined. -- {{{ Helper functions local function open_in_term (command, notify) if notify then naughty.notify ({ text = command }) end spawn (terminal .." -geometry ".. TERM_GEOMETRY .. " -e " .. command) end local function url_encode (str) if str then local function repchar (c) return string.format ("%%%02X", string.byte (c)) end str = gsub (str, "\n", "\r\n") str = gsub (str, "([^%w ])", repchar) str = gsub (str, " ", "+") end return str end -- }}} -- {{{ Hack for some publishing site at verimag... local xbrowser="firefox" function query_open_gate6_link (from_selection) local function append_to_hostname (httphostname, to_append) return gsub (httphostname, "([^/]*://[^/]+)(.*)", "%1"..to_append.."%2") end -- Basic check: we have an adress: local function is_an_address (str) return match (str, "^[^/]*://[^/]+.*$") end local function openit (address) if not is_an_address (address) then naughty.notify ({ text = "Needs a valid URI!" }) return false end local command = xbrowser.." \"".. append_to_hostname (address, ".gate6.inist.fr").. "\"" naughty.notify ({ text = command }) spawn (command) end if from_selection then local str = selection () if str == "" then naughty.notify ({ text = "Needs a selection!" }) else openit (str) end else awful.prompt.run ({ prompt = "Address: " }, mypromptbox[mouse.screen].widget, openit) end end -- }}} --{{{ Translations and language tools... --local term_browser="w3m -o use_mouse=true -o anchor_color=cyan -o bg_color=black" local term_browser="w3m" --local term_browser="links" function find_translation (langs, from_selection) local function launch_wrlinks (string) open_in_term (term_browser.. " \"http://www.wordreference.com/".. langs.."/"..string.."\"") end if from_selection then local str = selection () if str == "" then naughty.notify ({ text = "Needs a selection!" }) else launch_wrlinks (str) end else awful.prompt.run ({ prompt = "Word: " }, mypromptbox[mouse.screen].widget, launch_wrlinks, nil, awful.util.getdir ("cache") .. "/history_transl_"..langs) end end -- This does not really work since function find_conj (lang, from_selection) local function openit (string) if lang == "fr" then open_in_term (term_browser.. " \"http://leconjugueur.com/php5/index.php?v=".. url_encode (string).."\"") -- else -- open_in_term (mplex, term_browser.." -I iso-8859-1 ".. -- "\"http://dico.isc.cnrs.fr/dico/en/search?b=1&send=Look+it+up&r=".. -- url_encode (string).."\"") end end if from_selection then local str = selection () if str == "" then naughty.notify ({ text = "Needs a selection!" }) else openit (str) end else awful.prompt.run ({ prompt = "Verb: " }, mypromptbox[mouse.screen].widget, openit, nil, awful.util.getdir ("cache") .. "/history_conj_"..lang) end end function find_synonym (lang, from_selection) local function openit (string) local req if lang == "fr" then req = "fr/search?r=" else req = "en/search?b=1&r=" end open_in_term (term_browser.. " -I iso-8859-1 \"http://dico.isc.cnrs.fr/dico/".. req.. url_encode (string).. --"&send=Look+it+up".. "\"") end if from_selection then local str = selection () if str == "" then naughty.notify ({ text = "Needs a selection!" }) else openit (str) end else -- XXX: Note I have a huge problem with accents in prompts... awful.prompt.run ({ prompt = "Word: " }, mypromptbox[mouse.screen].widget, openit, nil, awful.util.getdir ("cache") .. "/history_synonym_"..lang) end end --}}}