packages feed

xmonad-eval (empty) → 0.1

raw patch · 4 files changed

+157/−0 lines, 4 filesdep +X11dep +basedep +containerssetup-changed

Dependencies added: X11, base, containers, directory, hint, mtl, old-locale, old-time, process, random, unix, xmonad, xmonad-contrib

Files

+ LICENSE view
@@ -0,0 +1,27 @@+Copyright (c) The Xmonad Community++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:+1. Redistributions of source code must retain the above copyright+   notice, this list of conditions and the following disclaimer.+2. Redistributions in binary form must reproduce the above copyright+   notice, this list of conditions and the following disclaimer in the+   documentation and/or other materials provided with the distribution.+3. Neither the name of the author nor the names of his contributors+   may be used to endorse or promote products derived from this software+   without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF+SUCH DAMAGE.
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ XMonad/Actions/Eval.hs view
@@ -0,0 +1,98 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  XMonad.Actions.Eval+-- Copyright   :  (c) 2009 Daniel Schoepe+-- License     :  BSD3-style (see LICENSE)+--+-- Maintainer  :  Daniel Schoepe <asgaroth_@gmx.de>+-- Stability   :  unstable+-- Portability :  unportable+--+-- Evaluate haskell expressions at runtime in the running xmonad instance.+--+-----------------------------------------------------------------------------++module XMonad.Actions.Eval (+                            -- * Usage+                            -- $usage+                            +                            -- * Documentation+                            -- $documentation+                            +                             evalExpression+                           , evalExpressionWithReturn+                           , EvalConfig(..)+                           , defaultEvalConfig+                           ) where++import XMonad.Core+import XMonad.Util.Run+import Language.Haskell.Interpreter+import Control.Monad+import Data.List++-- $usage+-- This module provides functions to evaluate haskell expressions at runtime+-- To use it, bind a key to evalExpression, for example in combination with a prompt:+--+-- > import XMonad+-- > import XMonad.Actions.Eval+-- > import XMonad.Prompt.Input+-- > ..+-- >   , ((modMask,xK_t), inputPrompt defaultXPConfig "Eval" >>= flip whenJust (evalExpression defaultEvalConfig))+--+-- For detailed instructions on editing your key bindings, see+-- "XMonad.Doc.Extending#Editing_key_bindings".++-- $documentation++-- In here due to the apparent lack of a replace function in the standard library.+-- (Used for correctly displaying newlines in error messages)+replace :: Eq a => [a] -> [a] -> [a] -> [a]+replace lst@(x:xs) sub repl | sub `isPrefixOf` lst = repl ++ replace (drop (length sub) lst) sub repl+                            | otherwise = x:(replace xs sub repl)+replace _ _ _ = []++-- | Configuration structure+data EvalConfig = EvalConfig { handleError :: InterpreterError -> X String+                             -- ^ Function to handle errors+                             , imports     :: [(ModuleName,Maybe String)]+                             -- ^ Modules to import for interpreting the expression.+                             -- The pair consists of the module name and an optional+                             -- qualification of the imported module.+                             , modules     :: [String] +                             -- ^ Other source files that should be loaded+                             -- The definitions of these modules will be visible+                             -- regardless of whether they are exported.+                             }++-- | Defaults for evaluating expressions.+defaultEvalConfig :: EvalConfig +defaultEvalConfig = EvalConfig { handleError = handleErrorDefault+                               , imports = [("Prelude",Nothing),("XMonad",Nothing),+                                            ("XMonad.StackSet",Just "W"),("XMonad.Core",Nothing)]+                               , modules = []+                               }++-- | Default way to handle(in this case: display) an error during interpretation of an expression.+handleErrorDefault :: InterpreterError -> X String+handleErrorDefault err = io (safeSpawn "/usr/bin/xmessage" $ replace (show err) "\\n" "\n") >>+                         return "Error"++-- | Returns an Interpreter action that loads the desired modules and interprets the expression.+interpret' :: EvalConfig -> String -> Interpreter (X String)+interpret' conf s = do+  loadModules $ modules conf+  setTopLevelModules =<< getLoadedModules+  setImportsQ $ imports conf+  interpret ("show `fmap` ("++s++")") (return "")++-- | Evaluates a given expression whose result type has to be an instance of Show+evalExpressionWithReturn :: EvalConfig -> String -> X String+evalExpressionWithReturn conf s = io (runInterpreter $ interpret' conf s) >>=+                                  either (handleError conf) id++-- | Evaluates a given expression, but discard the returned value. Provided for+-- more convenient use in keybindings+evalExpression :: EvalConfig -> String -> X ()+evalExpression cnf = (>> return ()) . evalExpressionWithReturn cnf
+ xmonad-eval.cabal view
@@ -0,0 +1,29 @@+name:               xmonad-eval+version:            0.1+homepage:           http://xmonad.org/+synopsis:           Module for evaluation Haskell expressions in the running xmonad instance+description:+    This modules allows the evaluation of Haskell expressions in the context of the currently+    running xmonad, similar to emacs' eval feature.+    .+category:           System+license:            BSD3+license-file:       LICENSE+author:             Daniel Schoepe+maintainer:         asgaroth_@gmx.de+cabal-version:      >= 1.2.1+build-type:         Simple++flag small_base+  description: Choose the new smaller, split-up base package.++library+    if flag(small_base)+        build-depends: base >= 3 && < 4, containers, directory, process, random, old-time, old-locale+    else+        build-depends: base < 3++    build-depends:      hint, mtl, unix, X11>=1.4.3, xmonad>=0.8, xmonad<0.9, xmonad-contrib>=0.8+    ghc-options:        -Wall++    exposed-modules:    XMonad.Actions.Eval