[Xmonad] darcs patch: add XSelection.hs
Gwern Branwen
gwern0 at gmail.com
Sat Sep 22 16:11:49 EDT 2007
On 2007.09.14 18:52:10 +0200, Andrea Rossato <mailing_list at istitutocolli.org> scribbled 29 lines:
> On Sat, Sep 15, 2007 at 09:07:01AM -0400, Gwern Branwen wrote:
> > So I said I'd send in Andrea's X selection stuff when 0.3 was finalized and XMonadContrib/ opened up again. Here it is! I hope someone besides myself finds it useful.
>
> I'm thinking about some improvements that probably should be provided
> before pushing this patch (the same applies to Hxsel, the companion of
> this piece of code):
>
> > +-- |
> > +-- Module : XMonadContrib.XSelection
> > +-- Copyright : (C) 2007 Andrea Rossato
>
> 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.
> > + ty <- internAtom dpy "UTF8_STRING" False
>
> this should be protected with a `catch` \_ -> internAtom dpy "sTRING"
> False, or even better, falling back first to COMPOUND_TEXT and then to
> string, right? Just in case UTF8_STRING is not present.
I suppose you could do something like:
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)
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?
> > +{- UTF-8 decoding for internal use in getSelection. This code is totally stolen from Eric Mertens's utf-string library
> [...]
> > +decode :: [Word8] -> String
>
> I may be wrong but there should be an accepted patch to x11-extras
> that provides the function needed here, but, I repeat it, I cuold be
> plainly wrong.
Well, I looked through x11-extra's Haddock, but I didn't see anything with that type signature, but I probably missed something.
> Cheers,
> Andrea
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 ())
This is pretty neat. D'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...)?
--
gwern
DSD e95 BfV h MI5 Bush TRANSEC passwd Council Rivera
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/xmonad/attachments/20070922/5680de4e/attachment.bin
More information about the Xmonad
mailing list