diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index a1b267c93..63141e4a4 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -88,9 +88,8 @@ format = "journal" -- | Does the given file path and data look like it might be hledger's journal format ? detect :: FilePath -> String -> Bool detect f s - | f /= "-" = takeExtension f `elem` ['.':format, ".j"] -- from a file: yes if the extension is .journal or .j - -- from stdin: yes if we can see something that looks like a journal entry (digits in column 0 with the next line indented) - | otherwise = regexMatches "^[0-9]+.*\n[ \t]+" s + | f /= "-" = takeExtension f `elem` ['.':format, ".j"] -- from a known file name: yes if the extension is this format's name or .j + | otherwise = regexMatches "(^|\n)[0-9]+.*\n[ \t]+" s -- from stdin: yes if we can see something that looks like a journal entry (digits in column 0 with the next line indented) -- | Parse and post-process a "Journal" from hledger's journal file -- format, or give an error. @@ -275,6 +274,7 @@ includedirectivep = do txt <- readFileOrError outerPos filepath let inIncluded = show outerPos ++ " in included file " ++ show filename ++ ":\n" r <- runParserT journalp outerState filepath txt + case r of Right (ju, ctx) -> do u <- combineJournalUpdates [ return $ journalAddFile (filepath,txt) diff --git a/hledger-lib/Hledger/Read/TimedotReader.hs b/hledger-lib/Hledger/Read/TimedotReader.hs index 51558f12b..b9dfd7ce3 100644 --- a/hledger-lib/Hledger/Read/TimedotReader.hs +++ b/hledger-lib/Hledger/Read/TimedotReader.hs @@ -60,9 +60,9 @@ format = "timedot" -- | Does the given file path and data look like it might contain this format ? detect :: FilePath -> String -> Bool -detect f _s - | f /= "-" = takeExtension f == '.':format -- from a file: yes if the extension matches the format name - | otherwise = False -- from stdin: yes if... +detect f s + | f /= "-" = takeExtension f == '.':format -- from a file: yes if the extension matches the format name + | otherwise = regexMatches "(^|\n)[0-9]" s -- from stdin: yes if we can see a possible timedot day entry (digits in column 0) -- | Parse and post-process a "Journal" from the timedot format, or give an error. parse :: Maybe FilePath -> Bool -> FilePath -> String -> ExceptT String IO Journal diff --git a/hledger-lib/Hledger/Read/TimelogReader.hs b/hledger-lib/Hledger/Read/TimelogReader.hs index bf9e253d9..71ae7e390 100644 --- a/hledger-lib/Hledger/Read/TimelogReader.hs +++ b/hledger-lib/Hledger/Read/TimelogReader.hs @@ -51,7 +51,7 @@ import Prelude () import Prelude.Compat import Control.Monad (liftM) import Control.Monad.Except (ExceptT) -import Data.List (isPrefixOf, foldl') +import Data.List (foldl') import Data.Maybe (fromMaybe) import Test.HUnit import Text.Parsec hiding (parse) @@ -75,8 +75,8 @@ format = "timelog" -- | Does the given file path and data look like it might be timeclock.el's timelog format ? detect :: FilePath -> String -> Bool detect f s - | f /= "-" = takeExtension f == '.':format -- from a file: yes if the extension is .timelog - | otherwise = "i " `isPrefixOf` s || "o " `isPrefixOf` s -- from stdin: yes if it starts with "i " or "o " + | f /= "-" = takeExtension f == '.':format -- from a known file name: yes if the extension is this format's name + | otherwise = regexMatches "(^|\n)[io] " s -- from stdin: yes if any line starts with "i " or "o " -- | Parse and post-process a "Journal" from timeclock.el's timelog -- format, saving the provided file path and the current time, or give an