我的观点是,理想情况下,多行注释应该像这样出现:
/* 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。
或者,你只是从来没有按回车,让编辑器在你的编辑器屏幕的边缘包装它。但是如果你像我一样,你的编辑器比理想的换行长度宽得多。
此外,XCode嘲笑我提供了一个在编辑器中呈现80个字符的包装指南的功能,但这纯粹是一个视觉功能,没有任何机制来支持它。这感觉就像是把花园的铲子递给一个习惯于使用挖掘机的人。
我是否需要一个现实的检验--我是不是想错了--或者XCode非常缺乏基本的段落风格的注释格式?
经验丰富的、负责任的、专业的Objective-C开发人员在代码中进行大量注释时会做些什么?帮我看看这里的光芒。
注意:对于XCode 3,我编写了一个手写脚本,它重新格式化了文本并将其绑定到热键上。我还不知道如何在XCode 4中做到这一点。但是如何编写集成开发环境4的脚本与这个问题有点正交:不得不用这些基础知识来增强XCode是很糟糕的,我的问题是关于XCode开发人员的风格和文化期望。
谢谢你的建议。
发布于 2012-07-24 11:21:00
我同意它应该内置到Xcode中。但不管怎样,下面是如何通过创建调用脚本的服务项目并为其分配键盘快捷键,将其快速添加到Xcode4中:
fmt
实用程序来重新格式化文本,允许行以句点开头,折叠行中的空格,允许缩进段落,在80个字符的列处换行。有关其他选项,请查看fmt
的手册页。显然,您可以通过emacs或markdown传输文本,或者使用一个合理的名称(如"Reformat-to-80")来whatever.
现在,当您在Xcode中选择文本时,您可以通过菜单栏选择服务将其重新格式化为80个字符: Xcode / Services / Reformat- to -80。
现在,让我们为它分配一个键盘快捷键:
现在,在Xcode中,您可以使用该键盘快捷键将所选文本替换为shell脚本的输出,这会将文本重新格式化为
发布于 2013-03-05 00:02:27
显然,您可以通过管道将文本传递给emacs,这会让人抓狂。
在多年期待Emacs在回流评论时的高级特性之后,我做到了。假设您可以克服Xcode调用Emacs编写脚本的麻烦,将以下脚本另存为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)))
然后创建一个Automator服务,该服务使用适当的语言参数(例如,C/C++/Objective-C的fill-region c++-mode
)执行此脚本,并替换选定的文本。
即使您不使用Emacs,这也是上面使用的fmt
的临时替代品,它在注释格式化方面要好得多。
发布于 2015-01-10 18:59:15
添加到填充:要定制他的emacs脚本对文本进行换行的列,请在user797758's answer-region调用之前添加一个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)))
https://stackoverflow.com/questions/7353097
复制