{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving, TypeOperators #-}-- Copyright (c) 2008 Jean-Philippe Bernardy-- | Various high-level functions to further classify.moduleYi.Commandwhere{- Standard Library Module Imports -}importData.BinaryimportSystem.Exit(ExitCode(ExitSuccess,ExitFailure))importControl.OldExceptionimportControl.Monad.Trans(MonadIO(..)){- External Library Module Imports -}{- Local (yi) module imports -}importPrelude()importYi.CoreimportYi.MiniBufferimportqualifiedYi.Mode.CompilationasCompilationimportYi.ProcessimportYi.UI.CommonimportqualifiedYi.Mode.InteractiveasInteractiveimportqualifiedData.RopeasR----------------------------- | Changing the buffer name quite useful if you have-- several the same. This also breaks the relation with the file.changeBufferNameE::YiM()changeBufferNameE=withMinibufferFree"New buffer name:"strFunwherestrFun::String->YiM()strFun=withBuffer.putAidentA.Left------------------------------ | shell-command with argument promptshellCommandE::YiM()shellCommandE=dowithMinibufferFree"Shell command:"shellCommandV------------------------------ | shell-command with a known argumentshellCommandV::String->YiM()shellCommandVcmd=do(cmdOut,cmdErr,exitCode)<-liftIO$runShellCommandcmdcaseexitCodeofExitSuccess->withEditor$newBufferE(Left"Shell Command Output")(R.fromStringcmdOut)>>return()-- FIXME: here we get a string and convert it back to utf8; this indicates a possible bug.ExitFailure_->msgEditorcmdErr------------------------------ Cabal-related commands-- TODO: rename to "BuildBuffer" or something.newtypeCabalBuffer=CabalBuffer{cabalBuffer::MaybeBufferRef}deriving(Initializable,Typeable,Binary)instanceYiVariableCabalBuffer------------------------------ | cabal-configurecabalConfigureE::CommandArguments->YiM()cabalConfigureE=cabalRun"configure"configureExitconfigureExit::EitherExceptionExitCode->YiM()configureExit(RightExitSuccess)=reloadProjectE"."configureExit_=return()reloadProjectE::String->YiM()reloadProjectEs=withUI$\ui->reloadProjectuis-- | Run the given commands with args and pipe the ouput into the build buffer,-- which is shown in an other window.buildRun::String->[String]->(EitherExceptionExitCode->YiMx)->YiM()buildRuncmdargsonExit=withOtherWindow$dob<-startSubprocesscmdargsonExitwithEditor$domaybeMdeleteBuffer=<<cabalBuffer<$>getDynamicsetDynamic$CabalBuffer$JustbwithBuffer0$setModeCompilation.modereturn()makeBuild::CommandArguments->YiM()makeBuild(CommandArgumentsargs)=buildRun"make"args(const$return())cabalRun::String->(EitherExceptionExitCode->YiMx)->CommandArguments->YiM()cabalRuncmdonExit(CommandArgumentsargs)=buildRun"cabal"(cmd:args)onExit------------------------- | cabal-buildcabalBuildE::CommandArguments->YiM()cabalBuildE=cabalRun"build"(const$return())shell::YiMBufferRefshell=dosh<-ioshellFileNameInteractive.interactivesh["-i"]-- use the -i option for interactive mode (assuming bash)-- | Search the source files in the project.searchSources::String:::RegexTag->YiM()searchSources=grepFind(Doc"*.hs")-- | Perform a find+grep operationgrepFind::String:::FilePatternTag->String:::RegexTag->YiM()grepFind(DocfilePattern)(DocsearchedRegex)=withOtherWindow$dodiscard$startSubprocess"find"[".","-name","_darcs","-prune","-o","-name",filePattern,"-exec","grep","-Hnie",searchedRegex,"{}",";"](const$return())withBuffer$setModeCompilation.modereturn()