rasa-ext-bufs (empty) → 0.1.1
raw patch · 4 files changed
+127/−0 lines, 4 filesdep +basedep +containersdep +data-defaultsetup-changed
Dependencies added: base, containers, data-default, lens, rasa, text
Files
- LICENSE +21/−0
- Setup.hs +2/−0
- rasa-ext-bufs.cabal +33/−0
- src/Rasa/Ext/Bufs.hs +71/−0
+ LICENSE view
@@ -0,0 +1,21 @@+The MIT License++Copyright (c) 2016 Chris Penner++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ rasa-ext-bufs.cabal view
@@ -0,0 +1,33 @@+name: rasa-ext-bufs+version: 0.1.1+cabal-version: >=1.10+build-type: Simple+license: MIT+license-file: LICENSE+copyright: 2016 Chris Penner+maintainer: christopher.penner@gmail.com+homepage: https://github.com/ChrisPenner/rasa/+synopsis: Rasa Ext for useful buffer utilities+description:+ Rasa Ext for useful buffer utilities+category: Extension+author: Chris Penner++source-repository head+ type: git+ location: https://github.com/ChrisPenner/rasa++library+ exposed-modules:+ Rasa.Ext.Bufs+ build-depends:+ base >=4.8 && <5,+ rasa >=0.1.4 && <0.2,+ data-default >=0.7.1.1 && <0.8,+ lens ==4.14.*,+ text >=1.2.2.1 && <1.3,+ containers >=0.5.7.1 && <0.6+ default-language: Haskell2010+ hs-source-dirs: src+ ghc-options: -Wall+
+ src/Rasa/Ext/Bufs.hs view
@@ -0,0 +1,71 @@+{-# LANGUAGE TemplateHaskell #-}++module Rasa.Ext.Bufs+ ( focusDo+ , getFocus+ , setFocus+ , nextBuf+ , prevBuf+ , bufs+ ) where++import Rasa.Ext++import Control.Lens+import Data.Default+import Data.Typeable++data Focused = Focused+ { _focused' :: Maybe BufRef+ } deriving (Typeable, Show)+makeLenses ''Focused++instance Default Focused where+ def = Focused+ { _focused'=Nothing+ }++bufs :: Scheduler ()+bufs = onBufAdded initFocus+ where+ initFocus bufRef = do+ mBuf <- use focused+ case mBuf of+ Nothing -> setFocus bufRef+ Just _ -> return ()++focused :: HasEditor e => Lens' e (Maybe BufRef)+focused = ext.focused'++getFocus :: Action (Maybe BufRef)+getFocus = use focused++setFocus :: BufRef -> Action ()+setFocus ref = focused ?= ref++focusDo :: BufAction a -> Action (Maybe a)+focusDo bufAct = do+ mFoc <- use focused+ case mFoc of+ Just foc -> bufDo foc bufAct+ Nothing -> return Nothing++-- | Switches focus to the next buffer+nextBuf :: Action ()+nextBuf = do+ mFoc <- use focused+ case mFoc of+ Nothing -> return ()+ Just foc -> do+ next <- nextBufRef foc+ focused ?= next++-- | Switches focus to the previous buffer+prevBuf :: Action ()+prevBuf = do+ mFoc <- use focused+ case mFoc of+ Nothing -> return ()+ Just foc -> do+ prev <- prevBufRef foc+ focused ?= prev