emacs中是否有命令取消注释整个注释块而不必先将其标记?
例如,让我们说这一点在以下代码的注释中:
(setq doing-this t)
;; (progn |<--This is the point
;; (er/expand-region 1)
;; (uncomment-region (region-beginning) (region-end)))
我想要一个把它变成这个的命令:
(setq doing-this t)
(progn
(er/expand-region 1)
(uncomment-region (region-beginning) (region-end)))
编写一个(un)注释单行的命令相当容易,但我还没有找到一个尽可能多注释掉一行的命令。有可用吗?
答案 0 :(得分:3)
快速回复---代码可以改进并变得更有用。例如,您可能希望将其扩展到其他类型的注释,而不是;;;
。
(defun uncomment-these-lines ()
(interactive)
(let ((opoint (point))
beg end)
(save-excursion
(forward-line 0)
(while (looking-at "^;;; ") (forward-line -1))
(unless (= opoint (point))
(forward-line 1)
(setq beg (point)))
(goto-char opoint)
(forward-line 0)
(while (looking-at "^;;; ") (forward-line 1))
(unless (= opoint (point))
(setq end (point)))
(when (and beg end)
(comment-region beg end '(4))))))
关键是comment-region
。 FWIW,我将comment-region
绑定到C-x C-;
。只需将其与C-u
一起使用即可取消注释。
答案 1 :(得分:3)
您可以使用Emacs的评论处理函数来制作Drew命令的通用版本。
(defun uncomment-current ()
(interactive)
(save-excursion
(goto-char (point-at-eol))
(goto-char (nth 8 (syntax-ppss)))
(uncomment-region
(progn
(forward-comment -10000)
(point))
(progn
(forward-comment 10000)
(point)))))