one pretty printer “to rule them all”

前端 未结 5 972
天涯浪人
天涯浪人 2021-01-06 02:41

I\'m looking for a tool that can pretty-print (AKA tidy or beautify) source code in as many languages as possible. Those I\'m particularly keen on include:

  • Jav
相关标签:
5条回答
  • 2021-01-06 03:24

    I use Vim to do this all the time. It doesn't handle HTML very well, but it does the others. It's easy to use the Vim commands to automate running it on a number of files.

    0 讨论(0)
  • 2021-01-06 03:26

    I use UltraEdit and find it's generally pretty good. It's not free, but it's also not that expensive.

    0 讨论(0)
  • 2021-01-06 03:30

    Wikipedia has a good-sized list. I'm interested to see what consensus might emerge here, though.

    Several handle multiple languages; e.g.

    PrettyPrinter, (an Open Source beautifier for every programming language)

    UniversalIndentGUI (A graphical user interface for any pretty printer with live preview for the formatting settings)

    prettyprinter.de, (an online beautifier for PHP, Java, C++, C, Perl, JavaScript, CSS)

    0 讨论(0)
  • 2021-01-06 03:37

    Emacs is a personal favorite of mine. There are add-ons that allow for almost every language you can thing of.

    0 讨论(0)
  • 2021-01-06 03:38

    For Haskell, I have this in ~/bin/pp.hs:

    #!/usr/bin/env runhaskell
    module Main (main) where
    import Language.Haskell.Parser
    import Language.Haskell.Pretty
    import System.Environment
    pp f = case parseModule f
            of ParseOk m -> prettyPrint m
               a -> show a
    main = do args <- getArgs
              mapM_ (>>= putStrLn . pp) $
                if null args then [getContents] else map readFile args
    

    In Vim, :set equalprg=~/bin/pp.hs, select a region, hit =, and boom, it gets prettified.

    Okay, it's not very general. But I figure it has a small chance of helping somebody if I add it here.

    0 讨论(0)
提交回复
热议问题