更新时间:2023-01-27 23:40:49
尝试此功能,并绑定到您最喜欢的键:
(defun toggle-comment-on-line()
评论或取消注释当前行
(interactive)
(comment-or-uncomment-region(line-begin-position)(line-end-position)))
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.
I tried a macro like this:
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.
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)))