summaryrefslogtreecommitdiff
authorplurSKI <black.gavin@gmail.com>2010-10-25 01:09:51 (GMT)
committer plurSKI <black.gavin@gmail.com>2010-10-25 01:09:51 (GMT)
commit0d7841c77b4acb2c5bf48989fce0f42ef9213546 (patch)
tree080731808700462746927c5928112b8618074b6a
downloadtaim-master.zip
taim-master.tar.gz
Initial Commitmaster
-rw-r--r--LICENSE30
-rw-r--r--README6
-rw-r--r--Setup.hs3
-rw-r--r--taim.hs73
-rw-r--r--taim.vim81
-rw-r--r--taimReleaseAlpha.cabal68
6 files changed, 261 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..f4d8ae6
--- a/dev/null
+++ b/LICENSE
@@ -0,0 +1,30 @@
+Copyright Gavin Black 2010
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * 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.
+
+ * Neither the name of Gavin Black nor the names of other
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+OWNER 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.
diff --git a/README b/README
new file mode 100644
index 0000000..70c632d
--- a/dev/null
+++ b/README
@@ -0,0 +1,6 @@
+USAGE INSTRUCTIONS:
+ > Run cabal install
+ > Run the taimReleaseAlpha program, under ~/.cabal/bin/taimReleaseAlpha
+ > Open up vim and source taim.vim, or just install taim.vim as a plugin
+ > In vim :StartTaim which will split the window for you
+ > In command mode press<C-x><C-e> (Control+x followed by Control+e) to evaluate the line the cursor is currently at.
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
index 0000000..cd7dc32
--- a/dev/null
+++ b/Setup.hs
@@ -0,0 +1,3 @@
+#!/usr/bin/env runhaskell
+import Distribution.Simple
+main = defaultMain
diff --git a/taim.hs b/taim.hs
new file mode 100644
index 0000000..deec62e
--- a/dev/null
+++ b/taim.hs
@@ -0,0 +1,73 @@
+-- TAIM: Haskell integration with vim
+-- Version: 0.1
+
+import Network.Socket
+import Network.BSD
+import System.Process
+import System.IO (Handle, hGetLine, hPutStrLn, hIsEOF, hClose)
+import Control.Concurrent (forkIO, threadDelay)
+import Control.Monad (forever, unless)
+import IO
+import System.IO (Handle, IOMode(ReadWriteMode), hPutStrLn, hGetLine, hClose, hGetContents, hFlush)
+import Control.Monad (liftM)
+import Control.Concurrent (forkIO)
+import Control.Exception (finally)
+
+portAddr = 12356
+
+listenAt :: Int -> (Handle -> IO ()) -> IO ()
+listenAt port_ f = do
+ let port = toEnum port_
+ lsock <- socket AF_INET Stream 0
+ bindSocket lsock $ SockAddrInet port iNADDR_ANY
+ listen lsock sOMAXCONN
+ loop lsock `finally` sClose lsock
+ where
+ loop lsock = do
+ (sock,SockAddrInet _ _) <- accept lsock
+ handle <- socketToHandle sock ReadWriteMode
+ f handle
+ loop lsock
+
+server = withSocketsDo $ do
+ (input, output, serr) <- makePipes
+ listenAt portAddr (\h -> forkIO (do
+ forkIO $ readerL output
+ forkIO $ readerL serr
+ threadDelay 100000
+ line <- hGetLine h
+ inputLoop input h line
+ `finally` hClose h) >> return ())
+
+makePipes :: IO (Handle, Handle, Handle)
+makePipes = do
+ (Just input, Just output, Just serr, _) <- createProcess (proc "ghci" []) {
+ std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe }
+ return (input, output, serr)
+
+inputLoop h conn line | line == "ping" = hPutStrLn conn "Received PING"
+ | otherwise = do
+ hFlush stdout
+ hPutStrLn h line
+ hFlush h
+ hPutStrLn conn ("Ran " ++ line)
+ threadDelay 100
+
+readerL h = forever $ hGetLine h >>= client -- hGetLine h >>= putStrLn
+
+client line = withSocketsDo $ do
+ h <- connectTo "localhost" 12357
+ hPutStrLn h line
+ hClose h
+
+connectTo :: String -> Int -> IO Handle
+connectTo host port_ = do
+ let port = toEnum port_
+ sock <- socket AF_INET Stream 0
+ addrs <- liftM hostAddresses $ getHostByName host
+ if null addrs then error $ "no such host : " ++ host else return ()
+ connect sock $ SockAddrInet port (head addrs)
+ handle <- socketToHandle sock ReadWriteMode
+ return handle
+
+main = server
diff --git a/taim.vim b/taim.vim
new file mode 100644
index 0000000..d6379bb
--- a/dev/null
+++ b/taim.vim
@@ -0,0 +1,81 @@
+" TAIM: Haskell integration with vim
+" Version: 0.1
+
+python << endpython
+import vim
+import time
+import thread
+import socket
+import sys
+
+def makeConnection():
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ host = "localhost"
+ port = 12356
+ s.connect((host, port))
+ return s
+
+def listenConnection():
+ outpWindow = vim.current.window
+ vim.command("wincmd w")
+ serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ serversocket.bind(("localhost", 12357))
+ #outpWindow.buffer.append(socket.gethostname())
+ serversocket.listen(5)
+ while 1:
+ (clientsocket, address) = serversocket.accept()
+ data = recv_basic(clientsocket)
+ outpWindow.buffer.append(data)
+ vim.command("wincmd w")
+ vim.command("normal! G")
+ vim.command("wincmd w")
+
+def sendCommand():
+ s = makeConnection()
+ (row, col) = vim.current.window.cursor
+ line = vim.current.buffer[row-1]
+ s.send(line)
+ s.close()
+
+def recv_basic(the_socket):
+ total_data=[]
+ while True:
+ data = the_socket.recv(8192)
+ if not data: break
+ total_data.append(data)
+ return ''.join(total_data)
+
+def myfunction(string,sleeptime,*args):
+ outpWindow = vim.current.window
+ while 1:
+ s = makeConnection()
+ s.send("ping\n")
+ data = recv_basic(s)
+ s.close()
+ time.sleep(sleeptime)
+
+def startTaim():
+ vim.command('below split +view ghci')
+ thread.start_new_thread(myfunction,("Thread No:1",2))
+ thread.start_new_thread(listenConnection,())
+endpython
+
+function! s:evalCodeP()
+python << endpython
+sendCommandP()
+endpython
+endfunction
+function! s:evalCode()
+python << endpython
+sendCommand()
+endpython
+endfunction
+function! s:startTaim()
+python << endpython
+startTaim()
+endpython
+endfunction
+
+command StartTaim :call <SID>startTaim()
+command EvalCode :call <SID>evalCode()
+nmap <C-x><C-e> :EvalCode<CR>
diff --git a/taimReleaseAlpha.cabal b/taimReleaseAlpha.cabal
new file mode 100644
index 0000000..371552d
--- a/dev/null
+++ b/taimReleaseAlpha.cabal
@@ -0,0 +1,68 @@
+-- taimReleaseAlpha.cabal auto-generated by cabal init. For additional
+-- options, see
+-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.
+-- The name of the package.
+Name: taimReleaseAlpha
+
+-- The package version. See the Haskell package versioning policy
+-- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for
+-- standards guiding when and how versions should be incremented.
+Version: 0.1
+
+-- A short (one-line) description of the package.
+Synopsis: VIM integration with GHCI
+
+-- A longer description of the package.
+-- Description:
+
+-- URL for the project homepage or repository.
+Homepage: http://devrand.org/
+
+-- The license under which the package is released.
+License: BSD3
+
+-- The file containing the license text.
+License-file: LICENSE
+
+-- The package author(s).
+Author: Gavin Black
+
+-- An email address to which users can send suggestions, bug reports,
+-- and patches.
+Maintainer: black.gavin@gmail.com
+
+-- A copyright notice.
+-- Copyright:
+
+-- Stability of the pakcage (experimental, provisional, stable...)
+Stability: Alpha
+
+Category: Development
+
+Build-type: Simple
+
+-- Extra files to be distributed with the package, such as examples or
+-- a README.
+-- Extra-source-files:
+
+-- Constraint on the version of Cabal needed to build this package.
+Cabal-version: >=1.2
+
+
+Executable taimReleaseAlpha
+ -- .hs or .lhs file containing the Main module.
+ Main-is: taim.hs
+
+ -- Packages needed in order to build this package.
+ Build-depends:
+ base >= 4 && < 5,
+ haskell98,
+ process,
+ network
+
+ -- Modules not exported by this package.
+ -- Other-modules:
+
+ -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.
+ -- Build-tools:
+