Skip to content

Instantly share code, notes, and snippets.

@silverweed
Last active July 6, 2023 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silverweed/81cc24bbc95ec02cd1b6a7fef1c21f56 to your computer and use it in GitHub Desktop.
Save silverweed/81cc24bbc95ec02cd1b6a7fef1c21f56 to your computer and use it in GitHub Desktop.
Counts line indents in code and shows stats
-- @author silverweed, 2016
-- @license WTFPL
import System.Environment
import System.IO
import Data.List
showIndents input = header ++ (mkList input) ++ "\n"
where
header = "indent: occurrences\n"
mkList = intercalate "\n" . map (\(o,i) -> (show i) ++ ": " ++ (show o)) .
map (\l -> (length l, head l)) . group . sort . buildIndents .
filter (\x -> length x > 0) . lines
buildIndents = map indents
where
indents = length . takeWhile (== '\t')
printAllIndents [] = return ()
printAllIndents files = readAll files >>= putStrLn . showIndents
where
readAll [] = return ""
readAll (file:files) = do s <- readFile file
ss <- readAll files
return $ s ++ ss
main = getArgs >>= \x -> case length x of
0 -> interact showIndents
_ -> printAllIndents x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment