Emacs同时复制区域/行和注释

egd*_*try 5 emacs elisp evil-mode

我正在尝试实现以下内容:复制当前选定的区域或一行(如果没有选择)并在帮助下注释掉原始区域comment-or-uncomment-region-or-line.

我想我可以使用kill-region后跟,yank但后来我的原始选择丢失了,所以我无法发表评论.另一方面,如果我先发表评论,我会将我所在地区的两份副本都注释掉.

我有的另一个想法(我认为更好,因为我使用邪恶模式)是使用evil-yank然后evil-visual-restore恢复选择,以便我可以评论它.但我无法确定要传递给哪些参数evil-yank来指定所选区域.

我在这里错过了什么?

Dre*_*rew 5

你缺少的主要是功能copy-region-as-kill.

(defun copy-and-comment-region (beg end &optional arg)
  "Duplicate the region and comment-out the copied text.
See `comment-region' for behavior of a prefix arg."
  (interactive "r\nP")
  (copy-region-as-kill beg end)
  (goto-char end)
  (yank)
  (comment-region beg end arg))
Run Code Online (Sandbox Code Playgroud)