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)))
编写一个对单行进行注释(取消注释)的命令相当容易,但我还没有找到一个可以尽可能多地取消注释的命令。有空的吗?
快速回复---代码可以得到改进,变得更加有用。例如,您可能希望将其扩展到除;;;
之外的其他类型的注释。
(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,I将comment-region
与C-x C-;
结合。只需将其与C-u
一起使用即可取消注释。
您可以使用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)))))