emacs:C-c%在auctex中做了什么,我怎样才能让它表现得更好?

时间:2010-11-24 16:45:01

标签: emacs auctex

C-c %应该是用于评论内容的emacs auctex模式快捷方式。 (还有C-c ;注释了标记区域,但是有效)。现在有时它会注释掉一行,有时会注释掉一行以及它上面的一行。它似乎没有非常一致的行为。

我真正想要做的是注释光标所在的行,除非它在开始或结束标记上,在这种情况下注释掉整个环境。 (实际上,我只是理解了评论宏的略微奇怪的行为......)

1 个答案:

答案 0 :(得分:3)

C-c %运行TeX-comment-or-uncomment-paragraph。有关段落的确切内容,请参阅manual

  

命令: TeX-comment-or-uncomment-paragraph
  (C-c %)从当前段落中每行的开头添加或删除%。删除%个字符时,段落被视为包含以%开头的所有前后行,直到第一个非注释行。


这是一个评论功能,或多或少地做你想要的。取消评论环境仅在LaTeX-syntactic-commentst时才有效(并且即使那时也不总是很好)。

(defun LaTeX-comment-environment-or-line (arg)
  "Comment or uncomment the current line.
If the current line is the \\begin or \\end line of an environment, comment
or uncomment the whole environment."
  (interactive "*P")
  (save-match-data
    (save-excursion
      (beginning-of-line)
      (cond
       ((looking-at (concat "\\s-*\\(" TeX-comment-start-regexp "\\)?\\s-*"
                            (regexp-quote TeX-esc) "begin"))
        (let ((begin (point)))
          (goto-char (match-end 0))
          (LaTeX-find-matching-end)
          (TeX-comment-or-uncomment-region begin (point) arg)))
       ((looking-at (concat "\\s-*\\(" TeX-comment-start-regexp "\\)?\\s-*"
                            (regexp-quote TeX-esc) "end"))
        (let ((end (save-excursion (end-of-line) (point))))
          (LaTeX-find-matching-begin)
          (beginning-of-line)
          (TeX-comment-or-uncomment-region (point) end arg)))
       (t
        (TeX-comment-or-uncomment-region
         (point) (save-excursion (end-of-line) (point)) arg))))))
相关问题