[Xmonad] darcs patch: add XSelection.hs

Andrea Rossato mailing_list at istitutocolli.org
Sat Sep 29 07:07:51 EDT 2007

Hi Gwern,

first of all sorry if I come back to our Xselection stuff so late, but
the new class branch was quite a huge job form me (I also need to get
to understand what I'm doing before actually doing it, and that
unusually takes more time then the actual getting things done, if you
know what I mean.. :)

On Sat, Sep 22, 2007 at 04:11:49PM -0400, Gwern Branwen wrote:
> > we should at least share the copyright...;-)
> Well, like I've said before: I'm not a huge fan of copyright, and I
> put everything into the public domain. So no need to credit me.

Well, me too (I'm a lawyer after all), but I don't want to take
credits for others' job. Anyway I'll respect your decision here.

>  import Control.Exception as E (catch)
> ...
>  ty ← E.catch
>                (E.catch
>                      (internAtom dpy "sTring" False)
>                      (λ_ → internAtom dpy "COMPOUND_TEXT" False⦆
>              (λ_ → internAtom dpy "UTF8_STRING" False)

This seems fine to me.

> I mean, this seems to compile and to do the right thing, but it
> looks kind of ugly. Does this actually help for anything? What
> systems that could run XMonad wouldn't return some sort of UTF-8
> string?

Well, as far as I know, and if I understand the point you are making,
it is the application that must provide the UTF8_STRING property.
Since we call internAtom with a False, if that application doesn't
provide an UTF8_STRING, xmonad is going to crash - am I right here?
I'm thinking about legacy application some user may be running, and
then she comes up with a bug you cannot even chase..:)

But I repeat it, I may be wrong.

> I recently thought of another thing, though. I use Surfraw elvi
> (<https://secure.wikimedia.org/wikipedia/en/wiki/Surfraw>) a lot for
> running Wikipedia and Google searches, and wayback even when I was
> using Ratpoison lo those many years ago, I had problems with my
> queries sometimes containing shell metacharacters. This was a
> problem with ratpoison, StumpWM and XMonad all because the obvious
> and easy way is to go through whatever their equivalent of 'spawn'
> is.
> So I wrote a 'safeSpawn' which avoids the shell:
>  safeSpawn :: FilePath -> String -> X ()
>  safeSpawn prog arg = io (try (forkProcess $ executeFile prog True [arg] Nothing) >> return ())

There's a module I contributed, RunInXTerm. I'm wondering if this
function wouldn't be perfect for that module (function to be exported
for other to use) more then in Xselection.

> This is pretty neat. Do you think it'd be worth including in
> XSelection, since I figure people will often be highlighting and
> manipulating URLs, and URLs often include characters like '&' (which
> has bad effects when passed to a shell...)?

As you know I achieve this result with hxsel from the command line,
but this could be a useful addition I think. 

I was also thinking about a prompt (with, possibly, a completion of
available searches) where you type a search engine and a query and
firefox is going to open up the appropriate page. What would you
think? Something like SearchPrompt. This is something I would like to
have (and if nobody does I'm going to write as soon as I'll have some

Once again, sorry for the delay of my answer.


More information about the Xmonad mailing list