4 -- Many of what's used here should have been loaded already!
5 local spawn = awful.util.spawn
6 local gsub = string.gsub
7 local match = string.match
9 -- `mypromptbox' should be defined.
11 -- {{{ Helper functions
13 local function open_in_term (command, notify)
15 naughty.notify ({ text = command })
17 spawn (terminal .." -geometry ".. TERM_GEOMETRY .. " -e " .. command)
20 local function url_encode (str)
22 local function repchar (c)
23 return string.format ("%%%02X", string.byte (c))
25 str = gsub (str, "\n", "\r\n")
26 str = gsub (str, "([^%w ])", repchar)
27 str = gsub (str, " ", "+")
34 -- {{{ Hack for some publishing site at verimag...
36 local xbrowser="firefox"
38 function query_open_gate6_link (from_selection)
40 local function append_to_hostname (httphostname, to_append)
41 return gsub (httphostname,
42 "([^/]*://[^/]+)(.*)", "%1"..to_append.."%2")
45 -- Basic check: we have an adress:
46 local function is_an_address (str)
47 return match (str, "^[^/]*://[^/]+.*$")
50 local function openit (address)
52 if not is_an_address (address) then
53 naughty.notify ({ text = "Needs a valid URI!" })
57 local command = xbrowser.." \""..
58 append_to_hostname (address, ".gate6.inist.fr")..
60 naughty.notify ({ text = command })
64 if from_selection then
65 local str = selection ()
67 naughty.notify ({ text = "Needs a selection!" })
72 awful.prompt.run ({ prompt = "Address: " },
73 mypromptbox[mouse.screen].widget,
81 --{{{ Translations and language tools...
83 --local term_browser="w3m -o use_mouse=true -o anchor_color=cyan -o bg_color=black"
84 local term_browser="w3m"
85 --local term_browser="links"
87 function find_translation (langs, from_selection)
89 local function launch_wrlinks (string)
90 open_in_term (term_browser..
91 " \"http://www.wordreference.com/"..
92 langs.."/"..string.."\"")
95 if from_selection then
96 local str = selection ()
98 naughty.notify ({ text = "Needs a selection!" })
103 awful.prompt.run ({ prompt = "Word: " },
104 mypromptbox[mouse.screen].widget,
106 awful.util.getdir ("cache") ..
107 "/history_transl_"..langs)
111 -- This does not really work since
112 function find_conj (lang, from_selection)
114 local function openit (string)
116 open_in_term (term_browser..
117 " \"http://leconjugueur.com/php5/index.php?v="..
118 url_encode (string).."\"")
120 -- open_in_term (mplex, term_browser.." -I iso-8859-1 "..
121 -- "\"http://dico.isc.cnrs.fr/dico/en/search?b=1&send=Look+it+up&r="..
122 -- url_encode (string).."\"")
126 if from_selection then
127 local str = selection ()
129 naughty.notify ({ text = "Needs a selection!" })
134 awful.prompt.run ({ prompt = "Verb: " },
135 mypromptbox[mouse.screen].widget,
137 awful.util.getdir ("cache") ..
138 "/history_conj_"..lang)
142 function find_synonym (lang, from_selection)
144 local function openit (string)
149 req = "en/search?b=1&r="
151 open_in_term (term_browser..
152 " -I iso-8859-1 \"http://dico.isc.cnrs.fr/dico/"..
153 req.. url_encode (string)..
154 --"&send=Look+it+up"..
158 if from_selection then
159 local str = selection ()
161 naughty.notify ({ text = "Needs a selection!" })
166 -- XXX: Note I have a huge problem with accents in prompts...
167 awful.prompt.run ({ prompt = "Word: " },
168 mypromptbox[mouse.screen].widget,
170 awful.util.getdir ("cache") ..
171 "/history_synonym_"..lang)