由于外部强制执行的编码标准,我需要在所有四个方面编写带有对齐边框的代码注释。
在Emacs中,最简单的方法是:
评论格式示例:
#*****************************************************************************#
#* This is a block comment. It has right-aligned borders. *#
#* *#
#* It can have separate paragraphs. Text in a long paragraph flows from one *#
#* line to the next with one space of internal padding. *#
#* *#
#* The right hand border is at char 78 *#
#*****************************************************************************#
sub MySub
{
#***************************************************************************#
#* The left hand edge of the comment is aligned with the current code *#
#* block, but the right hand border is still at char 78 *#
#***************************************************************************#
my $var = 3;
}
auto-fill-mode
本身并不保留右手边框。
答案 0 :(得分:3)
古老而多功能的图书馆“rebox2”可以做到这一点。
要安装,请将https://raw.github.com/lewang/rebox2/master/rebox2.el下载到您的site-lisp目录中,然后将以下内容添加到.emacs
文件中:
(require 'rebox2)
; The following template defines the specific style required here,
; which does not correspond to any built-in rebox2 style.
;
; "75" means that the style is registered as x75, where "x" depends
; on the current langauge mode. The "?" char is switched for the language
; specific comment char
;
; "999" is the weighting used for recognising this comment style.
; This value works for me.
(rebox-register-template
75
999
'("?*************?"
"?* box123456 *?"
"?*************?"))
(add-hook 'perl-mode-hook (lambda ()
; The "style loop" specifies a list of box styles which rebox will cycle
; through if you refill (M-q) a box repeatedly. Having "11" in this loop
; will allow you to easily "unbox" a comment block, e.g. for "uncomment-region"
(set (make-local-variable 'rebox-style-loop) '(75 11))
; The "min-fill-column" setting ensures that the box is not made narrower
; when the text is short
(set (make-local-variable 'rebox-min-fill-column) 79)
(rebox-mode 1)))
现在:
M-q
M-q
请求重排。)答案 1 :(得分:2)
M-x自定义变量RET注释样式RET
然后从value-menue
中选择“box”答案 2 :(得分:1)
您可以使用yasnippet
进行插入,使用overwrite-mode
进行编辑。
如果你想要自动换行,你也可以杀死矩形 C-x r k , 切换到临时缓冲区 C-x b , yank矩形 C-x r y 。根据你的内心编辑那里。然后, 从临时缓冲区中删除矩形并粘贴到源中。
这是块开始/结束片段:
# -*- mode: snippet -*-
# name: block comment
# key: bb
# --
`(concat "#" (make-string (- 80 aya-tab-position) ?*) "#")`
$0
`(concat "#" (make-string (- 80 aya-tab-position) ?*) "#")`
这是块行代码段:
# -*- mode: snippet -*-
# name: block comment line
# key: bl
# --
`"#* "`$1${1:$(make-string (- 78 aya-tab-position (length text)) ? )}#
请注意,我在这里使用auto-yasnippet
包变量aya-tab-position
。
要在代码段中使用它,您必须使用aya-open-line
展开代码段。
您可以从MELPA获得这两个包。
答案 3 :(得分:0)
对(1)的部分回答(但我希望听到更好的回答):
M-x set-fill-column 76
M-x set-fill-prefix
M-q
重排段落请参阅http://www.gnu.org/software/emacs/manual/html_node/emacs/Fill-Prefix.html
同样的方法可以用于(2)中的一些:
set-fill-column
和set-fill-prefix
正确无误(见上文)M-q