3

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

编写一个(取消)注释一行的命令相当容易,但我还没有找到一个尽可能多地取消注释的命令。有没有可用的?

4

2 回答 2

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-regionC-x C-;. 只需使用它C-u来取消注释。

于 2013-08-17T23:41:21.973 回答
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)))))
于 2013-08-18T03:38:09.703 回答