Emacs评论/取消注释当前行 [英] Emacs comment/uncomment current line

查看:93
本文介绍了Emacs评论/取消注释当前行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道现在已经有了一个Emacs的问题,而且这个问题已经关闭了,但是我发现它是非常重要的。



基本上,我想评论/取消当前行的注释。我期望这是一个非常容易的宏,但我发现它真的不是。



如果当前行被注释,取消注释。如果它被取消注释,评论。我也会评论整个行,而不仅仅是从光标位置。



我尝试过这样的宏:



Ca

 'comment-dwim 

但是,这只能评论一条线,而不是取消注释,如果它已经被评论。



我不知道它是多么容易,但如果有一些方式,我真的很喜欢。



另外,我喜欢这个想法的原因很多的是,当我使用Geany时,我只是使用了 Ce ,这是完美的。

解决方案

尝试此功能,并绑定到您最喜欢的键:

 (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)))

这篇关于Emacs评论/取消注释当前行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆