xcode4 - XCode 4 注释格式(换行)

我认为多行注释最好是这样的:

/* this is a mult-line comment, which wraps lines at some reasonable length,
 * usually approximately 80 characters. this way, comments are easy to read
 * and, with any half way capable text editor, easy to edit without having
 * to manually reshuffle lines, line breaks, and the comment leader. */

// this is a mult-line comment, which wraps lines at some reasonable length,
// usually approximately 80 characters. this way, comments are easy to read
// and, with any half way capable text editor, easy to edit without having
// to manually reshuffle lines, line breaks, and the comment leader.

/* this is a mult-line comment, which wraps lines at some reasonable length,
   usually approximately 80 characters. this way, comments are easy to read
   and, with any half way capable text editor, easy to edit without having
   to manually reshuffle lines, line breaks, and the comment leader. */

但是,XCode 不支持以这种风格管理评论。您必须在正确的时间手动按回车键以适当的宽度包装评论,然后编辑它们成为完整的 PITA。

或者,您永远不会按回车键并让编辑器将其包装在编辑器屏幕的边缘。但如果你像我一样,你的编辑器比理想的自动换行行长度要宽得多。

此外,XCode 通过提供一个在编辑器中以 80 个字符呈现包装指南的功能来 mock 我,但这纯粹是一个视觉功能,没有任何机制来支持它。这感觉就像把一把花园铲子交给习惯使用反铲的人。

我是否需要在这里进行实际检查 - 我的想法是否错误 - 还是 XCode 极度缺乏基本的段落式注释格式?

经验丰富、负责任、专业的 Objective-C 开发人员在代码中发表大量注释时会怎么做?帮我看看这里的光。

注意:对于 XCode 3,我编写了一个手卷脚本,它重新格式化文本并将其绑定(bind)到一个热键。我还没有弄清楚如何在 XCode 4 中做到这一点。但是如何编写 XCode 4 脚本与这个问题有点正交:必须用这些基础知识来扩充 IDE 听起来很糟糕,我的问题是关于 XCode 开发人员的风格和文化期望。

感谢您的建议。

最佳答案

我同意它应该内置在 Xcode 中。但无论如何,这里是如何通过创建一个调用脚本的服务项并为其分配键盘快捷键来快速将其添加到 Xcode4:

  1. 打开 Automator。创建服务。
  2. 将服务设置为让输出替换所选文本,并在您选择的 Xcode 副本中接收所选文本。
  3. 将“运行 Shell 脚本”操作拖入您的服务中作为唯一操作。
  4. 将默认的 shell 脚本“cat”替换为“fmt -n -s -p -w80”。这会调用 fmt 实用程序来重新格式化您的文本,允许行以句点开头,折叠行内的空格,允许缩进段落,在 80 个字符列处换行。查看 fmt 的手册页以了解其他选项。显然,您可以在这里通过 emacs 或 markdown 或其他方式传递文本来发疯。
  5. 使用合理的名称保存服务,例如“Reformat-to-80”

现在,当您在 Xcode 中选择文本后,您可以通过菜单栏选择服务将其重新格式化为 80 个字符:Xcode/Services/Reformat-to-80。

现在让我们为其分配一个键盘快捷键:

  1. 打开键盘首选项 Pane ,转到键盘快捷键选项卡。
  2. 在左侧 Pane 中选择应用程序快捷方式
  3. 在右侧 Pane 中,使用添加按钮(+)为您之前选择的 Xcode 副本添加新的快捷方式。输入您用于服务的确切名称并添加您选择的键盘快捷键。

现在,在 Xcode 中,您可以使用该键盘快捷键将所选文本替换为 shell 脚本的输出,这会将文本重新格式化为

https://stackoverflow.com/questions/7353097/

相关文章:

javascript - 使用纯 JavaScript 将电话号码格式化为用户类型

powershell - 在 PowerShell 中导出为 CSV 时如何指定列顺序?

formatting - 好的评论用例

arrays - 填充表格数据的打印输出

r - 如何在 R Shiny 中对数据帧进行条件格式设置?

c++ - 使用 Visual Studio 进行高级 (C++) 源代码重新格式化?

string - 固定宽度数字格式化python 3

url - 查询字符串中是否有任何格式约定?

html - 在 Rails 中,如何在文本区域中允许一些 html?

php - 保持我的 PHP 漂亮