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:
我正在寻找一种能够以尽可能多的语言打印(AKA整洁或美化)源代码的工具。我特别热衷的包括:
- Java
- JSP
- HTML
- JavaScript
- SQL
- JSON
- XML
Ideally, the tool should be able to update source files in-place and be able to format more than a single file at-a-time. It would be great if it could format files containing multiple languages (e.g. a JSP containing HTML, Java, and JavaScript source code), but that's probably asking for a bit much.
理想情况下,该工具应该能够就地更新源文件,并且能够一次格式化多个文件。如果它可以格式化包含多种语言的文件(例如包含HTML,Java和JavaScript源代码的JSP),那将会很棒,但这可能要求更多。
I've already found a commercial tool that seems to cover a lot of languages, but a free one would be even better :)
我已经找到了一个似乎涵盖了很多语言的商业工具,但是免费的一个会更好:)
BTW, I know there is a pretty printer available for most languages, but what I'm looking for is a "one-stop shop".
顺便说一句,我知道大多数语言都有可用的打印机,但我正在寻找的是“一站式服务”。
Cheers, Don
5 个解决方案
#1
5
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.
我使用Vim一直这样做。它不能很好地处理HTML,但它可以处理其他HTML。使用Vim命令可以很容易地在许多文件上自动运行它。
#2
4
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)
PrettyPrinter,(适用于各种编程语言的开源美化)
UniversalIndentGUI (A graphical user interface for any pretty printer with live preview for the formatting settings)
UniversalIndentGUI(任何漂亮的打印机的图形用户界面,具有格式化设置的实时预览)
prettyprinter.de, (an online beautifier for PHP, Java, C++, C, Perl, JavaScript, CSS)
prettyprinter.de,(PHP,Java,C ++,C,Perl,JavaScript,CSS的在线美化器)
#3
3
For Haskell, I have this in ~/bin/pp.hs
:
对于Haskell,我在〜/ 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.
在Vim中:设置equalprg =〜/ bin / pp.hs,选择一个区域,命中=和繁荣,它会得到美化。
Okay, it's not very general. But I figure it has a small chance of helping somebody if I add it here.
好吧,这不是很一般。但我认为如果我在这里添加它,它很有可能帮助某人。
#4
1
Emacs is a personal favorite of mine. There are add-ons that allow for almost every language you can thing of.
Emacs是我个人的最爱。有些附加组件几乎涵盖了您可以使用的所有语言。
#5
0
I use UltraEdit and find it's generally pretty good. It's not free, but it's also not that expensive.
我使用UltraEdit并发现它通常非常好。它不是免费的,但也不是那么贵。
#1
5
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.
我使用Vim一直这样做。它不能很好地处理HTML,但它可以处理其他HTML。使用Vim命令可以很容易地在许多文件上自动运行它。
#2
4
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)
PrettyPrinter,(适用于各种编程语言的开源美化)
UniversalIndentGUI (A graphical user interface for any pretty printer with live preview for the formatting settings)
UniversalIndentGUI(任何漂亮的打印机的图形用户界面,具有格式化设置的实时预览)
prettyprinter.de, (an online beautifier for PHP, Java, C++, C, Perl, JavaScript, CSS)
prettyprinter.de,(PHP,Java,C ++,C,Perl,JavaScript,CSS的在线美化器)
#3
3
For Haskell, I have this in ~/bin/pp.hs
:
对于Haskell,我在〜/ 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.
在Vim中:设置equalprg =〜/ bin / pp.hs,选择一个区域,命中=和繁荣,它会得到美化。
Okay, it's not very general. But I figure it has a small chance of helping somebody if I add it here.
好吧,这不是很一般。但我认为如果我在这里添加它,它很有可能帮助某人。
#4
1
Emacs is a personal favorite of mine. There are add-ons that allow for almost every language you can thing of.
Emacs是我个人的最爱。有些附加组件几乎涵盖了您可以使用的所有语言。
#5
0
I use UltraEdit and find it's generally pretty good. It's not free, but it's also not that expensive.
我使用UltraEdit并发现它通常非常好。它不是免费的,但也不是那么贵。