问题标签 [code-formatting]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
1448 浏览

html - Eclipse Ganymede for OS X 不包含 HTML 格式化程序。备择方案?

在 Eclipse 3.4 for Windows 中,用于格式化 Java 代码的 Source -> Format 选项被扩展为格式化 HTML 代码。但是,对于 OS X,此选项被禁用。此外,首选项中没有格式选项。我已经下载了所有 Eclipse 的 Web 工具,但该选项仍然不可用。

哪个插件/功能允许在 Eclipse OS X 上进行 HTML 格式设置(如果有的话)?否则,有什么好的基于 Web 的替代方案?

谢谢,亚当

0 投票
1 回答
428 浏览

code-formatting - 在 IM 上格式化源代码以保留缩进的最佳方式是什么?

当您将源代码粘贴给同事时,有没有办法在即时通讯程序中保留缩进?

特别是我正在尝试通过 google talk 编写一些 python 代码,但是所有选项卡都被删除了。

0 投票
2 回答
1808 浏览

visual-studio - 在 Visual Studio 2005 中保存时格式化源代码

我希望 Visual Studio 每次保存时都格式化我的源代码。我可以在 Eclipse 中做到这一点。可以在 Visual Studio 2005 中完成吗?

0 投票
5 回答
6371 浏览

c# - C# to format (indent, align) C# properly

We have a code generator that munges the schema of a given database to automate our inhouse n-tier architecture. The output is various C# partial classes, one per file.

In the code to munge all the strings, we try and keep on top of the indenting and formatting as much as possible, but invariably when you come to open the file in Visual Studio the formatting is awry. A quick ctrl-k, ctrl-d fixes it, but obviously this reformatting is lost the next time the class is generated.

What I'd like to know, is if there's a way I can somehow automatically format the contents of the textfile in the same way Visual Studio does?

Pseudocode

Any help greatly appreciated.

EDIT: I should clarify - I want to be able to invoke the formatting from my C# code that creates the textfile containing my generated C#. The format of the code can be standardised (doesn't have to be per-developer), and I don't want to have to install any 3rd-party apps.

I seem to remember there's a namespace containing loads of classes for creating C# in C#: http://msdn.microsoft.com/en-us/library/system.codedom(VS.80).aspx, but I'm not sure if it contains any classes that could help.

FURTHER EDIT: My code generator is a winforms app deployed via a click-once install. It's used by many developers in-house. I need a solution that doesn't require each developer to have a tool installed on their machine.

0 投票
4 回答
4712 浏览

emacs - 如何应用新的 Emacs C 样式来重新格式化所有源文件?

我想使用适用于 emacs 的 Google 格式化功能重新格式化所有源文件:google-c-style.el(请参见此处)。

如何一次将此功能应用于我的所有源文件,以便它们都根据 Google 样式正确格式化和缩进?

0 投票
9 回答
273 浏览

html - 传统的“HTML 仅用于内容”的思路如何处理动态格式?

这么久以来,我已经阅读并理解了以下有关 Web 开发的真理:

  1. HTML 用于内容
  2. CSS 用于演示
  3. JavaScript 用于行为。

这通常都很好,而且我发现当我严格遵循这些准则并使用外部.css.js文件时,它使我的整个网站更易于管理。但是,我想我发现了一个打破这种思路的情况。

我有一个为我的网站之一构建的自定义论坛系统。除了此类系统的常用格式(链接、图像、粗斜体和下划线等)外,我还允许我的用户设置其文本的格式,包括颜色、字体系列和大小。所有这些都以格式代码的形式保存在论坛消息数据库中,然后在查看页面时转换为相应的 HTML。(有点低效,技术上我应该在保存之前翻译,但这样我可以在系统上实时工作。)

由于这个系统和其他类似系统的性质,我最终会在生成的 HTML 代码周围出现很多标签,我认为这些标签已被非正式地弃用,因为我应该使用 CSS 进行格式化。这违反了规则一和二,即 HTML 不应该包含格式信息,而是更喜欢将这些信息放在 CSS 文档中。

有没有办法在 CSS 中实现动态格式而不在标记中包含该信息?值得麻烦吗?或者,考虑到正确代码的隐含限制,我要限制我的用户可以做什么,以便遵循“正确”的方式来格式化我的代码?

0 投票
7 回答
15183 浏览

emacs - 如何在 Emacs 中强制执行最大行长度?

在 Emacs 中,如何强制规定最大行长,例如 80 个字符?我希望它在我的代码中插入正确的换行符,就像fill-paragraph文本一样,如果可能的话,正确插入行的第二部分。

这里有一个小例子:

如果我真的这样做fill-paragraph,它会变成:

而我更喜欢这个:

0 投票
16 回答
146074 浏览

visual-studio - 在 Visual Studio 中关闭自动格式化

与 Visual Studio 的默认设置相比,我更喜欢我自己的代码格式样式。我在工具→选项中关闭了自动格式化选项。在大多数情况下,它有效。

但是,在使用任何内置重构之后,Visual Studio 会使用其默认设置破坏我的设置。我如何阻止 VS 这样做?

0 投票
4 回答
4018 浏览

.net - 来自 ide 的格式代码(VS2008)

每隔一段时间我会粘贴一些代码,它会丢失所有的标签,看起来很糟糕

我知道在 vs2008 xml 查看器中有一个按钮可以将所有代码格式化(缩进)到正确的层次结构

是否有这样的功能或宏或快捷键可以将其应用于一段代码(或该窗口中的所有代码)?

0 投票
6 回答
567 浏览

c - 仅在大括号范围内缩进代码是否很常见?

对于生成的代码,我可以选择缩进或不缩进大括号,这些大括号仅用于在范围内容纳变量。目前它没有在这个级别缩进,我想知道我是否要通过缩进来暗示嵌套结构?常见的做法是什么?

相对

澄清:使用调试器额外的缩进意味着另一个级别的循环难以阅读的代码......