我通常在Debian(GNU/Linux)下使用Geany或Hi-Tide进行固件开发,主要是C(但也读旧的汇编程序).我使用单行注释来记录代码,当我重新输入某些内容并且必须手动重新打破每个后续行以使其保持在80个字符的边距时,它真的很烦人.
是否有文本编辑器可以重新包装连续的单行注释(并在我键入时自动执行此操作)?那是,给定:
/// This is a really long line that should have been wrapped at "that" but was not. /// This sentence is in the same /// paragraph as the last.
...我想要一个能重新包装它的编辑器
/// This is a really long line that /// should have been wrapped at "that" /// but was not. This sentence is in /// the same paragraph as the last.
...最好在我输入时明智地做这件事.
我试过了:
Hi-Tide(基于Eclipse 3.3)
Geany
jEdit的
UniversalIndentGUI +一堆美化剂(我找不到任何有效的格式化工具,而且它也不是一个很好的工作流程)
GVim - 下一行开始//should have been
...而不是/// should have been
......
更新:只是详细说明我接受的答案 - 我已经使用了快照emacs并且还需要额外的filladapt模式
Vim当然可以做到这一点.
首先,你需要告诉Vim"///"是一个注释前缀(默认情况下不是这样):
:set comments^=:///
如果希望换行按类型进行,请设置首选textwidth:
:set textwidth=80
要格式化现有段落,请使用gq命令的任何变体.例如,您可以:
直观地选择一个段落并键入gq或
键入gqj以从当前行重新换行到段落的末尾
在Emacs中,要开始自动换行,请输入auto-fill-mode.要设置线宽,请运行.Emacs,或真正的CC模式,将预测您的评论结构,以便输入 将导致C-u ⟨columns⟩ C-x f/// This is a really long line that shoul
/// This is a really long line that /// shoul?
你可以随时补充一个段落M-q.
如果你想用每个按键自动重新填充,那么很可能会有一些内部命令或第三方库,但是你可以使用这个elisp代码:
;;; Can't advise SELF-INSERT-COMMAND, so create a wrapper procedure. (defun self-insert-refill (n) (interactive "p") (self-insert-command n)) ;;; Advise SELF-INSERT-REFILL to execute FILL-PARAGRAPH after every ;;; keypress, but *only* if we're inside a comment (defadvice self-insert-refill (after refill-paragraph) (let ((face (or (get-char-property (point) 'read-face-name) (get-char-property (point) 'face))) ) (if (and (eq face 'font-lock-comment-face) (not (string= " " (this-command-keys)))) ; Spaces would get deleted on refill. (fill-paragraph)))) (ad-activate 'self-insert-refill) (add-hook 'c-mode-hook ;; Remap SELF-INSERT-COMMAND to be SELF-INSERT-REFILL. (local-set-key [remap self-insert-command] 'self-insert-refill) ))
这可能不是非常强劲或与最佳做法,并有可能不尽如人意的地方,因为它不会对一般的编辑,例如工作C-d和backspace,而且它会减慢编辑一些,但它是一个开始.