Emacs 注释/取消注释当前行 [英] Emacs comment/uncomment current line
问题描述
我知道 Emacs 上已经有一个关于此的问题,并且已经关闭,但我发现它非常相关且重要.
I know there's already an Emacs question on this, and that it was closed, but I find it quite relevant and important.
基本上,我想注释/取消注释当前行.我原以为使用宏会很容易做到这一点,但我发现事实并非如此.
Basically, I want to comment/uncomment the current line. I was expecting this to be fairly easy with a macro, but I found that it really isn't.
如果当前行被注释,则取消注释.如果未注释,请对其进行注释.而且我还想注释掉整行,而不仅仅是从光标位置.
If the current line is commented, uncomment. If it is uncommented, comment it. And I would also to comment out the whole line, not just from cursor position.
我试过这样的宏:
C-a
'comment-dwim
但这只适用于注释一行,而不是取消注释,如果它已经被注释了.
But this only work to comment a line, not to uncomment it, if it's already commented.
我不确定这有多容易,但如果有办法,我真的很喜欢.
I'm not sure of how easy it is, but if there's some way, I'd really like it.
另外,我非常喜欢这个想法的原因是,当我使用 Geany 时,我只使用了 C-e,它非常完美.
Also, the reason I love this idea so much is that when I used Geany, I just used C-e and it was perfect.
推荐答案
试试这个功能,绑定你最喜欢的键:
Try this function, and bind to your favorite key:
(defun toggle-comment-on-line ()
"comment or uncomment current line"
(interactive)
(comment-or-uncomment-region (line-beginning-position) (line-end-position)))
这篇关于Emacs 注释/取消注释当前行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!