diff options
author | gwern0 <gwern0@gmail.com> | 2007-10-19 20:11:37 +0200 |
---|---|---|
committer | gwern0 <gwern0@gmail.com> | 2007-10-19 20:11:37 +0200 |
commit | 3bb80ca741f6999edf2d4efc6c8a7e6a6de3c478 (patch) | |
tree | 910f8291aa9de4696637fabd541014d1a529b89c | |
parent | 7ce28a9d0c84179bd0beceab29264542b9d2adcc (diff) | |
download | XMonadContrib-3bb80ca741f6999edf2d4efc6c8a7e6a6de3c478.tar.gz XMonadContrib-3bb80ca741f6999edf2d4efc6c8a7e6a6de3c478.tar.xz XMonadContrib-3bb80ca741f6999edf2d4efc6c8a7e6a6de3c478.zip |
XSelection.hs: +2 functions, safePromptSelection and unsafePromptSelection
Analogous to Run.hs patch; these use safeSpawn and unsafeSpawn respectively.
darcs-hash:20071019181137-f7719-95fbfe642137e957f8b5aa0bb1b10297a9ba4d8f.gz
-rw-r--r-- | XSelection.hs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/XSelection.hs b/XSelection.hs index 80353a8..dea9ad8 100644 --- a/XSelection.hs +++ b/XSelection.hs @@ -18,7 +18,10 @@ module XMonadContrib.XSelection ( -- * Usage -- $usage - getSelection, promptSelection, putSelection) where + getSelection, + promptSelection, + safePromptSelection, + putSelection) where -- getSelection, putSelection's imports: import Graphics.X11.Xlib (allocaXEvent, createSimpleWindow, defaultScreen, destroyWindow, internAtom, nextEvent, openDisplay, rootWindow, selectionNotify, Display(), Atom(), XEventPtr(), selectionRequest, sendEvent, noEventMask, sync) @@ -124,9 +127,15 @@ putSelection text = do {- | A wrapper around getSelection. Makes it convenient to run a program with the current selection as an argument. This is convenient for handling URLs, in particular. For example, in your Config.hs you could bind a key to @promptSelection \"firefox\"@; -this would allow you to highlight a URL string and then immediately open it up in Firefox. -} -promptSelection :: String -> X () -promptSelection app = spawn . ((app ++ " ") ++) =<< io getSelection +this would allow you to highlight a URL string and then immediately open it up in Firefox. + +promptSelection passes strings through the shell; if you do not wish your selected text to be interpreted/mangled +by the shell, use safePromptSelection which will bypass the shell using safeSpawn from Run.hs; see Run.hs for more +details on the advantages/disadvantages of this. -} +promptSelection, safePromptSelection, unsafePromptSelection :: String -> X () +promptSelection = unsafePromptSelection +safePromptSelection app = join $ io $ liftM (safeSpawn app) (getSelection) +unsafePromptSelection app = join $ io $ liftM unsafeSpawn $ fmap (\x -> app ++ " " ++ x) getSelection {- UTF-8 decoding for internal use in getSelection. This code is copied from Eric Mertens's utf-string library <http://code.haskell.org/utf8-string/> (version 0.1), which is BSD-3 licensed, as is this module. |