Xcode4 XCode 4注释格式(换行)
我认为,多行注释在理想情况下应该如下所示:Xcode4 XCode 4注释格式(换行),xcode4,formatting,comments,Xcode4,Formatting,Comments,我认为,多行注释在理想情况下应该如下所示: /* 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
/* 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不支持管理这种风格的注释。您必须在适当的时间手动点击return以适当的宽度包装注释,然后编辑它们就成了一个完整的PITA
或者,您永远不会点击return,让编辑器在编辑器屏幕的边缘将其包装起来。但是,如果你像我一样,你的编辑器比理想的单词换行长度要宽得多
此外,XCode还嘲笑我,它提供了一个在编辑器中以80个字符呈现包装指南的功能,但这纯粹是一个视觉功能,没有任何机制来支持它。这感觉就像把花园里的铲子交给习惯使用反铲的人
我是否需要在这里做一个现实检查——我是不是想错了——或者XCode在基本段落风格的注释格式方面极度缺乏
经验丰富、负责任、专业的Objective-C开发人员在代码中发表实质性评论时会做什么?帮我看看这里的灯
注意:对于XCode 3,我编写了一个手动脚本,它重新格式化文本并将其绑定到热键。我还没有弄明白如何在XCode 4中实现这一点。但是如何编写XCode 4的脚本与这个问题有点正交:必须用这些基础知识来扩充IDE的味道很糟糕,我的问题是关于XCode开发人员的风格和文化期望
谢谢你的建议。嗯,事情的格式对我来说从来都不是什么大问题(就我个人而言,我也从来没有对大量的文本进行过评论),但我认为这里有一些东西非常有用。 要注释掉一段代码,可以按如下方式快速注释掉一段代码:
Select one or more lines of code to comment
Command-/
我同意它应该内置到Xcode中。但无论如何,下面介绍如何通过创建调用脚本的服务项并为其分配键盘快捷键,将其快速添加到Xcode4:
fmt
实用程序来重新格式化文本,允许行以句点开头,折叠行中的空格,允许缩进段落,在80个字符的列中换行。查看手册页中的fmt
了解其他选项。显然,您可以在这里通过emacs或markdown或其他方式来处理文本fill region
(或类似内容),并使其可执行
#!/usr/bin/env emacs --script
(with-temp-buffer
;; Would like to implement --help but Emacs eats that before I can
;; process it here.
(let ((param (nth 0 command-line-args-left)))
(if param (funcall (intern param))))
(condition-case nil
(while t
(insert (read-from-minibuffer ""))
(insert "\n"))
(error nil))
(fill-region (point-min) (point-max))
(princ (buffer-string)))
然后创建一个自动机服务,该服务使用适当的语言参数(例如,c/c++/Objective-c的填充区域c++-mode
)执行该脚本,并替换所选文本
即使您不使用Emacs,这也是使用上面的fmt
的替代品,它在注释格式方面有相当好的效果。添加到:要自定义Emacs脚本包装文本的列,请在填充区域调用之前添加一个set fill column调用。例如,下面的脚本将换行100个字符
#!/usr/bin/env emacs --script
(with-temp-buffer
(let ((param (nth 0 command-line-args-left)))
(if param (funcall (intern param))))
(condition-case nil
(while t
(insert (read-from-minibuffer ""))
(insert "\n"))
(error nil))
(set-fill-column 100)
(fill-region (point-min) (point-max))
(princ (buffer-string)))
“我从来没有对大量文本进行过评论”——我认为这是操作上的问题。XCode开发人员都必须经过训练,才能写出零碎的注释,因为编辑器不能处理长注释谢谢你的提示,它在某些情况下是有用的。仍然在寻找XCode中勤奋/丰富评论风格的解决方案!天哪,谢谢你。我原以为这个问题永远得不到回答。很高兴这有帮助。现在我们所需要的是一些命令行绝地武士来加入,这样重新格式化脚本就可以智能地处理文档语法,比如@user577888它对appledoc段落很好,我认为这是主要的用例。另外,
-s
压缩行内的空格,但在句子后也强制使用双空格。谢谢,很好的脚本。不过,它的结尾似乎是70个字符左右,而不是80个字符。有没有办法改变这种行为?我对Emacs脚本一点也不熟悉。我认为您需要将其设置为Emacs首选项,下面是另一篇s.O.文章,介绍如何实现这一点: