pandoc-vimhl 0.1.2.0 → 0.1.2.1
raw patch · 3 files changed
+42/−18 lines, 3 files
Files
- Changelog.md +5/−0
- pandoc-vimhl.cabal +20/−10
- vimhl.hs +17/−8
Changelog.md view
@@ -1,3 +1,8 @@+### 0.1.2.1++- Added Cabal flag *debug* (off by default) for printing how vim runs to+ *stderr*.+ ### 0.1.2.0 - Better treatment of handles of temporary files.
pandoc-vimhl.cabal view
@@ -1,5 +1,5 @@ name: pandoc-vimhl-version: 0.1.2.0+version: 0.1.2.1 synopsis: Pandoc filter for native Vim code highlighting description: Pandoc filter for native Vim code highlighting in HTML and PDF documents. Requires Vim and plugin@@ -15,14 +15,24 @@ build-type: Simple cabal-version: >= 1.8 +flag debug+ description: Enable debug support (print how vim runs to stderr)+ default: False+ manual: True+ executable vimhl- build-depends: base >= 4.7 && < 5- , pandoc-types >= 1.12- , directory- , filepath- , process- , temporary >= 1.1- , regex-compat- , cond >= 0.2- main-is: vimhl.hs+ build-depends: base >= 4.7 && < 5+ , pandoc-types >= 1.12+ , directory+ , filepath+ , process+ , temporary >= 1.1+ , regex-compat+ , cond >= 0.2+ extensions: CPP++ if flag(debug)+ cpp-options: -DDEBUG++ main-is: vimhl.hs
vimhl.hs view
@@ -1,5 +1,7 @@ #!/usr/bin/env runhaskell +{-# LANGUAGE CPP #-}+ -- vimhl.hs import Text.Pandoc.JSON import Text.Regex (mkRegex, splitRegex, matchRegexAll)@@ -53,6 +55,16 @@ hPutStr hsrc contents >> hFlush hsrc bracket (emptySystemTempFile "_vimhl_dst.") removeFile $ \dst -> do+ let vimcmd =+ unwords+ ["vim -Nen", cmds, vimrccmd, colorscheme+ ,"-c 'set ft=" ++ ft, "|"+ ,vimhlcmd ++ "' -c 'w!", dst ++ "' -c 'qa!'"+ ,src+ ]+#ifdef DEBUG+ hPutStr stderr $ vimcmd ++ " ... "+#endif {- vim must think that it was launched from a terminal, - otherwise it won't load its usual environment and the - syntax engine! Using WriteMode for stdin prevents vim@@ -62,15 +74,12 @@ - mode of the handle). -} hin <- openFile "/dev/tty" WriteMode hout <- openFile "/dev/null" WriteMode- (_, _, _, handle) <- createProcess- (shell $ unwords- ["vim -Nen", cmds, vimrccmd, colorscheme- ,"-c 'set ft=" ++ ft, "|", vimhlcmd ++ "' -c 'w!"- ,dst ++ "' -c 'qa!'", src- ]- ) {std_in = UseHandle hin, std_out = UseHandle hout}+ (_, _, _, handle) <- createProcess (shell vimcmd)+ {std_in = UseHandle hin, std_out = UseHandle hout} r <- waitForProcess handle- unless (r == ExitSuccess) $ exitWith r+#ifdef DEBUG+ hPutStrLn stderr "done"+#endif readFile dst return $ RawBlock fm block where namevals' = map (first $ map toLower) namevals