[xmonad] XMonad.Actions.Search: Issue with escaped URL
Platon Pronko
platon7pronko at gmail.com
Fri Jun 12 17:17:22 UTC 2020
Hi!
The issue is that search/promptSearch use safeSpawn internally, and safeSpawn does not deal with non-ASCII characters correctly (see https://mail.haskell.org/pipermail/xmonad/2020-April/015370.html and https://mail.haskell.org/pipermail/xmonad/2020-April/015371.html).
You can work around that, but since the call stack is slightly deep you will need quite a lot of code. Here's the snippet I that I tested on my machine, seems to work correctly:
safeSpawnUnicode :: MonadIO m => FilePath -> [String] -> m ()
safeSpawnUnicode prog args = io $ void $ forkProcess $ do
uninstallSignalHandlers
_ <- createSession
executeFile prog True args Nothing
ponsSearchEngine = searchEngineF "pons" (\s -> "https://de.pons.com/übersetzung/französisch-deutsch/" ++ (escape s))
-- copied from XMonad.Actions.Search because it does not exort Search constructor
data SearchCopy = SearchCopy Name
instance XPrompt SearchCopy where
showXPrompt (SearchCopy name) = "SearchCopy [" ++ name ++ "]: "
nextCompletion _ = getNextCompletion
commandToComplete _ c = c
promptSearchUnicode :: XPConfig -> SearchEngine -> X ()
promptSearchUnicode config (SearchEngine name site) =
mkXPrompt (SearchCopy name) config (historyCompletionP ("SearchCopy [" `isPrefixOf`)) (\query -> safeSpawnUnicode "firefox" [site query])
showSearchPrompt = promptSearchUnicode myXPConfig ponsSearchEngine
Best regards,
Platon Pronko
On 2020-06-12 15:59, Christian Heinrich wrote:
> Hi everyone,
>
> I've started to use XMonad.Actions.Search and I'm trying to define my own SearchEngine as follows:
>
>> searchFunc :: String -> String
>> searchFunc s = "https://de.pons.com/übersetzung/französisch-deutsch/" ++ (escape s)
>> pons = searchEngineF "pons" searchFunc
>
> The german umlauts ü and ö are actually part of the URL. According to the documentation,
> searchEngineF should not handle any escaping (unlike searchEngine), but the URL that is opened for "a" is
>
> https://de.pons.com/%C3%83%C2%BCbersetzung/franz%C3%83%C2%B6sisch-deutsch/a
>
> I can't find what I'm doing wrong even when looking at the source.
>
> Could anyone point out to me how to open that URL without escaping anything? I'm just surprised that
> the base-URL is escaped as well, and not just the argument. I'm pretty new to Haskell and would be
> grateful for any hint.
>
> Thanks!
>
> Christian
>
>
> _______________________________________________
> xmonad mailing list
> xmonad at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad
>
More information about the xmonad
mailing list