mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 11:30:22 -07:00
revamp Search.hs to export a replacement for simpleEngine
It's called searchEngine now, and is a wrapper around the SearchEngine type. Different type as well
This commit is contained in:
parent
e3974a91b3
commit
12e54671a5
@ -1,21 +1,20 @@
|
|||||||
{- |
|
{- | Module : XMonad.Actions.Search
|
||||||
Module : XMonad.Actions.Search
|
Copyright : (C) 2007 Gwern Branwen
|
||||||
Copyright : (C) 2007 Gwern Branwen
|
License : None; public domain
|
||||||
License : None; public domain
|
|
||||||
|
|
||||||
Maintainer : <gwern0@gmail.com>
|
Maintainer : <gwern0@gmail.com>
|
||||||
Stability : unstable
|
Stability : unstable
|
||||||
Portability : unportable
|
Portability : unportable; depends on XSelection, XPrompt
|
||||||
|
|
||||||
A module for easily running Internet searches on web sites through xmonad.
|
A module for easily running Internet searches on web sites through xmonad.
|
||||||
Modeled after the handy Surfraw CLI search tools at <https://secure.wikimedia.org/wikipedia/en/wiki/Surfraw>.
|
Modeled after the handy Surfraw CLI search tools at <https://secure.wikimedia.org/wikipedia/en/wiki/Surfraw>.
|
||||||
|
|
||||||
Additional sites welcomed.
|
Additional sites welcomed. -}
|
||||||
-}
|
|
||||||
module XMonad.Actions.Search ( -- * Usage
|
module XMonad.Actions.Search ( -- * Usage
|
||||||
-- $usage
|
-- $usage
|
||||||
search,
|
search,
|
||||||
SearchEngine,
|
SearchEngine,
|
||||||
|
searchEngine,
|
||||||
promptSearch,
|
promptSearch,
|
||||||
promptSearchBrowser,
|
promptSearchBrowser,
|
||||||
selectSearch,
|
selectSearch,
|
||||||
@ -66,7 +65,7 @@ import XMonad.Util.XSelection (getSelection)
|
|||||||
want, the browser you want, and anything special they might need;
|
want, the browser you want, and anything special they might need;
|
||||||
this whole line is then bound to a key of you choosing in your
|
this whole line is then bound to a key of you choosing in your
|
||||||
xmonad.hs. For specific examples, see each function. This module
|
xmonad.hs. For specific examples, see each function. This module
|
||||||
is easily extended to new sites by using 'simpleEngine'.
|
is easily extended to new sites by using 'searchEngine'.
|
||||||
|
|
||||||
The currently available search engines are:
|
The currently available search engines are:
|
||||||
|
|
||||||
@ -175,37 +174,38 @@ data SearchEngine = SearchEngine Name Site
|
|||||||
search :: Browser -> Site -> Query -> X ()
|
search :: Browser -> Site -> Query -> X ()
|
||||||
search browser site query = safeSpawn browser (site ++ (escape query))
|
search browser site query = safeSpawn browser (site ++ (escape query))
|
||||||
|
|
||||||
{- | Given a base URL, create the SearchEngine that escapes the query and
|
{- | Given a base URL, create the 'SearchEngine' that escapes the query and
|
||||||
appends it to the base. You can easily define a new engine locally using SearchEngine
|
appends it to the base. You can easily define a new engine locally using
|
||||||
without needing to modify Search.hs:
|
exported functions without needing to modify "XMonad.Actions.Search":
|
||||||
|
|
||||||
> newEngine = SearchEngine "site" "http://site.com/search="
|
> myNewEngine = searchEngine "site" "http://site.com/search="
|
||||||
|
|
||||||
The important thing is that the site has a interface which accepts the query
|
The important thing is that the site has a interface which accepts the escaped query
|
||||||
string as part of the URL. Alas, the exact URL to feed simpleEngine varies
|
string as part of the URL. Alas, the exact URL to feed searchEngine varies
|
||||||
from site to site, often considerably. Generally, examining the resultant URL
|
from site to site, often considerably, so there's no general way to cover this.
|
||||||
of a search will allow you to reverse-engineer it if you can't find the
|
|
||||||
necessary URL already described in other projects such as Surfraw. -}
|
Generally, examining the resultant URL of a search will allow you to reverse-engineer
|
||||||
--simpleEngine :: Name -> Query -> SearchEngine
|
it if you can't find the necessary URL already described in other projects such as Surfraw. -}
|
||||||
--simpleEngine site query = site ++ escape query
|
searchEngine :: Name -> Site -> SearchEngine
|
||||||
|
searchEngine name site = SearchEngine name site
|
||||||
|
|
||||||
-- The engines.
|
-- The engines.
|
||||||
amazon, dictionary, google, hoogle, imdb, maps, mathworld,
|
amazon, dictionary, google, hoogle, imdb, maps, mathworld,
|
||||||
scholar, wayback, wikipedia, youtube :: SearchEngine
|
scholar, wayback, wikipedia, youtube :: SearchEngine
|
||||||
amazon = SearchEngine "amazon" "http://www.amazon.com/exec/obidos/external-search?index=all&keyword="
|
amazon = searchEngine "amazon" "http://www.amazon.com/exec/obidos/external-search?index=all&keyword="
|
||||||
dictionary = SearchEngine "dictionary" "http://dictionary.reference.com/browse/"
|
dictionary = searchEngine "dictionary" "http://dictionary.reference.com/browse/"
|
||||||
google = SearchEngine "google" "http://www.google.com/search?num=100&q="
|
google = searchEngine "google" "http://www.google.com/search?num=100&q="
|
||||||
hoogle = SearchEngine "hoogle" "http://www.haskell.org/hoogle/?q="
|
hoogle = searchEngine "hoogle" "http://www.haskell.org/hoogle/?q="
|
||||||
imdb = SearchEngine "imdb" "http://www.imdb.com/Find?select=all&for="
|
imdb = searchEngine "imdb" "http://www.imdb.com/Find?select=all&for="
|
||||||
maps = SearchEngine "maps" "http://maps.google.com/maps?q="
|
maps = searchEngine "maps" "http://maps.google.com/maps?q="
|
||||||
mathworld = SearchEngine "mathworld" "http://mathworld.wolfram.com/search/?query="
|
mathworld = searchEngine "mathworld" "http://mathworld.wolfram.com/search/?query="
|
||||||
scholar = SearchEngine "scholar" "http://scholar.google.com/scholar?q="
|
scholar = searchEngine "scholar" "http://scholar.google.com/scholar?q="
|
||||||
wikipedia = SearchEngine "wikipedia" "https://secure.wikimedia.org/wikipedia/en/wiki/Special:Search?go=Go&search="
|
wikipedia = searchEngine "wikipedia" "https://secure.wikimedia.org/wikipedia/en/wiki/Special:Search?go=Go&search="
|
||||||
youtube = SearchEngine "youtube" "http://www.youtube.com/results?search_type=search_videos&search_query="
|
youtube = searchEngine "youtube" "http://www.youtube.com/results?search_type=search_videos&search_query="
|
||||||
{- This doesn't seem to work, but nevertheless, it seems to be the official
|
{- This doesn't seem to work, but nevertheless, it seems to be the official
|
||||||
method at <http://web.archive.org/collections/web/advanced.html> to get the
|
method at <http://web.archive.org/collections/web/advanced.html> to get the
|
||||||
latest backup. -}
|
latest backup. -}
|
||||||
wayback = SearchEngine "wayback" "http://web.archive.org/"
|
wayback = searchEngine "wayback" "http://web.archive.org/"
|
||||||
|
|
||||||
{- | Like 'search', but for use with the output from a Prompt; it grabs the
|
{- | Like 'search', but for use with the output from a Prompt; it grabs the
|
||||||
Prompt's result, passes it to a given searchEngine and opens it in a given
|
Prompt's result, passes it to a given searchEngine and opens it in a given
|
||||||
@ -236,4 +236,4 @@ selectSearchBrowser browser (SearchEngine _ site) = search browser site =<< getS
|
|||||||
This specializes "selectSearchBrowser" by supplying the browser argument as
|
This specializes "selectSearchBrowser" by supplying the browser argument as
|
||||||
supplied by 'getBrowser' from "XMonad.Prompt.Shell". -}
|
supplied by 'getBrowser' from "XMonad.Prompt.Shell". -}
|
||||||
selectSearch :: SearchEngine -> X ()
|
selectSearch :: SearchEngine -> X ()
|
||||||
selectSearch engine = liftIO getBrowser >>= \browser -> selectSearchBrowser browser engine
|
selectSearch engine = liftIO getBrowser >>= \browser -> selectSearchBrowser browser engine
|
||||||
|
Loading…
x
Reference in New Issue
Block a user