texbuilder 0.1.3.0 → 0.1.4.0
raw patch · 7 files changed
+53/−44 lines, 7 files
Files
- ChangeLog.md +4/−0
- README.md +7/−0
- TexBuilder/CompileThread.hs +10/−10
- TexBuilder/Engine.hs +4/−4
- TexBuilder/TexBuilder.hs +17/−17
- TexBuilder/Utils/Hashing.hs +10/−12
- texbuilder.cabal +1/−1
ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for tex-builder +0.1.4.0+---+* Simplify code by reducing continuation foo somewhat.+ 0.1.3.0 --- * Add new option to force an initial compile run.
README.md view
@@ -14,6 +14,13 @@ * a recent cabal / ghc * (currently only works with) mupdf * working latex with lualatex, xelatex or pdflatex and ideally latexmk+ * make sure to compile this with the -threaded ghc option, otherwise it will not work!++## Build with Cabal from Hackage++```sh+cabal install --bindir . --ghc-option=-threaded texbuilder+``` ## How to build from git
TexBuilder/CompileThread.hs view
@@ -36,16 +36,16 @@ compileLoop = do path <- lift . takeMVar =<< gets watchMVar -- ^ Wait for watcher thread to signal potential changes- withHash path $ \newHash -> do- table <- gets oldHashes- case M.lookup path table of -- ^ lookup old hash- Nothing -> go- Just oldHash -> when (oldHash /= newHash) go- -- ^ Compile when file was changed- modify $ \st ->- st { oldHashes = M.insert path newHash table }- -- ^ Write new hash value- compileLoop+ newHash <- computeHash path+ table <- gets oldHashes+ case M.lookup path table of -- ^ lookup old hash+ Nothing -> go+ Just oldHash -> when (oldHash /= newHash) go+ -- ^ Compile when file was changed+ modify $ \st ->+ st { oldHashes = M.insert path newHash table }+ -- ^ Write new hash value+ compileLoop go = lift $ do run >>= PP.putDoc
TexBuilder/Engine.hs view
@@ -71,16 +71,16 @@ recompileSt :: IO (Either String FilePath) -> StateT RecompileState IO (Either String FilePath) recompileSt run = get >>= \case- StInitial maxNum -> go $ succ maxNum+ StInitial maxNum -> step $ succ maxNum StSucc i path oldHash -> if i <= 0 then done path- else go $ \path hash ->+ else step $ \path hash -> if hash == oldHash then done path else succ i path hash where- go k = lift run >>= \case+ step k = lift run >>= \case Left err -> failed err- Right path -> withHash path $ k path+ Right path -> computeHash path >>= k path succ i path hash = do put $ StSucc (i-1) path hash
TexBuilder/TexBuilder.hs view
@@ -65,18 +65,18 @@ -- ^ Do an initial compile run if appropriate sem <- newBinSem -- ^ Signaling semaphore connecting the threads- withInitialHashes listSrcFiles $ \hashes -> do- watchMVar <- newEmptyMVar- wtid <- forkIO $ - setupWatches depth texDir fileFilter watchMVar- ctid <- forkIO $- compileThread run sem watchMVar hashes- -- ^ The thread which compiles the tex code- onFileEx pdffile ( mupdfView pdffile sem )- -- ^ Enter the main thread which updates the pdf view- putStrLn "mupdf exited, terminating"- killThread wtid- killThread ctid+ hashes <- computeInitialHashes listSrcFiles+ watchMVar <- newEmptyMVar+ wtid <- forkIO $ + setupWatches depth texDir fileFilter watchMVar+ ctid <- forkIO $+ compileThread run sem watchMVar hashes+ -- ^ The thread which compiles the tex code+ onFileEx pdffile ( mupdfView pdffile sem )+ -- ^ Enter the main thread which updates the pdf view+ putStrLn "mupdf exited, terminating"+ killThread wtid+ killThread ctid where fileFilter = extFilter exts @@ -103,12 +103,12 @@ listSubdirs depth texDir >>= searchFilesWith fileFilter -withInitialHashes :: IO [FilePath]- -> ( M.Map FilePath (Digest MD5) -> IO b)- -> IO b-withInitialHashes listSrc k = do+computeInitialHashes :: IO [FilePath]+ -> IO ( M.Map FilePath (Digest MD5) )+computeInitialHashes listSrc = do files <- listSrc- withHashes files $ k . M.fromList . zip files+ hashes <- computeHashes files+ pure . M.fromList $ zip files hashes withDirSetup :: FilePath
TexBuilder/Utils/Hashing.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE PackageImports #-} module TexBuilder.Utils.Hashing- ( withHash- , withHashes+ ( computeHash+ , computeHashes , module Crypto.Hash ) where @@ -13,26 +13,24 @@ import qualified Data.ByteString.Lazy as LB -- import qualified Data.ByteString as B --withHash :: (MonadIO io,HashAlgorithm a)- => FilePath -> (Digest a -> io b) -> io b-withHash path k = do+computeHash :: (MonadIO io,HashAlgorithm a)+ => FilePath -> io (Digest a)+computeHash path = do hash <- liftIO (hashlazy <$> LB.readFile path)- deepseq hash $ k hash+ pure $ deepseq hash hash -- ^ deepseq is neccessary to force reading to -- actually happen here (we want to capture the -- _current_ state of the file). -withHashes ::+computeHashes :: (MonadIO io,HashAlgorithm a,Traversable t,NFData (t (Digest a)))- => t FilePath -> (t (Digest a) -> io b) -> io b-withHashes paths k = do+ => t FilePath -> io (t (Digest a))+computeHashes paths = do hashes <- forM paths $ \path -> liftIO (hashlazy <$> LB.readFile path)- deepseq hashes $ k hashes+ pure $ deepseq hashes hashes -- ^ deepseq is neccessary to force reading to -- actually happen here (we want to capture the -- _current_ state of the file).-
texbuilder.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: texbuilder-version: 0.1.3.0+version: 0.1.4.0 synopsis: View your latex output while editing description: This program allows you to view your latex document in your pdf viewer while