Java geany 中提供智能自动缩进吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18828162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Smart auto-indentation available in geany?
提问by Connor Leech
I'm writing javascript using Geany IDE. My indentation is all messed up and I'd like to make it look nice. When I write Java in Eclipse I can do ctrl + i to make all the spacing in order.
我正在使用Geany IDE编写 javascript 。我的缩进全乱了,我想让它看起来不错。当我在 Eclipse 中编写 Java 时,我可以按 ctrl + i 来按顺序排列所有间距。
What is the indentation option available in Geany?
Geany 中可用的缩进选项是什么?
采纳答案by Tobiasz
The document formatting option is on the Geany's plugin wishlist (ref. Auto Correct Indentation section in Geany's Plugin Wishlist).
文档格式设置选项对Geany的插件心愿(参见自动更正缩进Geany的部分插件收藏)。
However, Geany allows tosend text using custom commands.
但是,Geany 允许使用自定义命令发送文本。
As you may suspect this opens a pretty wide selection of new "doors" behind which lies the solution of your problem, e.g. Artistic Styleis a cross-platform code auto-formatter for C, C++, C#, and Java. So the solution is:
正如您可能怀疑这打开了许多新“门”的选择,这背后隐藏着您的问题的解决方案,例如,艺术风格是 C、C++、C# 和 Java 的跨平台代码自动格式化程序。所以解决办法是:
- get a copy of any code formatting tool that accepts text from standard input and returns the resulting text to standard output,
- in Geany go to Send Selection to->Set Custom Commandsand add an appropriate command for your tool
- 获取任何代码格式化工具的副本,该工具接受来自标准输入的文本并将结果文本返回到标准输出,
- 在 Geany 中,转到Send Selection to->Set Custom Commands并为您的工具添加适当的命令
I am not an agitator for Artistic Style, you can just use any tool that formats Java code. It has been done this way with HTML Tidy or PHP Beautifier, results look like this:
我不是艺术风格的鼓动者,您可以使用任何格式化 Java 代码的工具。已经用 HTML Tidy 或 PHP Beautifier 以这种方式完成了,结果如下所示:
回答by Francky
command for html simple smart indentationthat finaly work in geany :
用于最终在 geany 中工作的html简单智能缩进的命令:
bash -c "tidy --indent auto --indent-spaces 2 --char-encoding utf8 --quiet yes 2>/dev/null; true"
回答by user3796218
PHPFormatter is a php script found here -- https://github.com/NathanWong/phpformatterIt can be run via the command line and does an awesome job of formatting PHP,HTML,and Javascript. From the authors description:
PHPFormatter 是一个在这里找到的 php 脚本——https: //github.com/NathanWong/phpformatter它可以通过命令行运行,并且在格式化 PHP、HTML 和 Javascript 方面做得非常出色。来自作者的描述:
"This PHP script will format another PHP script using my arbitrarily set formatting rules (real tabs, 97 chars per line, brackets on their own line, indentation based on operator hierarchy not alignment, spaces around most operators but not commas or brackets, space after if, etc.). It will also format inline HTML, and if JS Beautify is available, it'll use that for inline Javascript in inline HTML too."
“这个 PHP 脚本将使用我任意设置的格式规则来格式化另一个 PHP 脚本(真正的制表符,每行 97 个字符,自己行上的括号,基于运算符层次结构的缩进而不是对齐,大多数运算符周围的空格但不是逗号或括号,后面的空格如果,等等。它还会格式化内联 HTML,如果 JS Beautify 可用,它也会将其用于内联 HTML 中的内联 Javascript。”
I simply unzipped the 2 files : format.php and jsbeautify.php to my home directory and then added the following custom command in Geany:
我只是将 2 个文件:format.php 和 jsbeautify.php 解压缩到我的主目录,然后在 Geany 中添加以下自定义命令:
php /home/myusername/format.php -
php /home/myusername/format.php -
(Note the dash at the end. This tells the script to accept input from the standard input stream which is where Geany sends the text.)Now all you have to do is a quick Ctrl+a (SelectAll) then Ctrl+1 (or whichever number you put the command on) and ...
(注意末尾的破折号。这告诉脚本接受来自标准输入流的输入,这是 Geany 发送文本的地方。)现在你所要做的就是快速 Ctrl+a (SelectAll) 然后 Ctrl+1(或无论您将命令放在哪个数字上)和...
Voila...
瞧...
Beautifully formatted code!! Thanks Nathan!
格式优美的代码!!谢谢内森!
回答by MIRMIX
Based on geany documentationtype of auto-indentation are like below:
基于geany 文档类型的自动缩进如下所示:
Geany knows four types of auto-indentation:
None:Disables auto-indentation completely.
Basic:Adds the same amount of whitespace on a new line as on the last line.
Current chars:Does the same as Basic but also indents a new line after an opening brace '{', and de-indents when typing a closing brace '}'. For Python, a new line will be indented after typing ':' at the end of the previous line.
Match braces:Similar to Current chars but the closing brace will be aligned to match the indentation of the line with the opening brace.
Geany 知道四种类型的自动缩进:
无:完全禁用自动缩进。
基本:在新行上添加与上一行相同数量的空格。
当前字符:与 Basic 相同,但也在左大括号 '{' 后缩进新行,并在键入右大括号 '}' 时取消缩进。对于 Python,在上一行的末尾键入 ':' 后将缩进一个新行。
匹配大括号:类似于当前字符,但右大括号将对齐以匹配行与左大括号的缩进。
You have just following options. You may improve and extend these options using Scintilla.
您只有以下选项。您可以使用Scintilla改进和扩展这些选项。