查询搜索并注释掉行?


9

我希望弄清楚如何进行查询搜索,该搜索将注释掉一行而不是查询替换。也就是说,进行交互式查询搜索,如果我同意,请注释掉匹配所在的行。

该命令存在吗?如果没有,我该怎么写?我是elisp的新手,也不知道如何编写自己的函数。


8
使用query-replace-regexp。用注释开头的行替换该行。
提请

Answers:


1
(defun my-comment-matching-line ()
  (interactive "*")
  (call-interactively 'search-forward)
  (beginning-of-line)
  ;; don't comment the region maybe
  (push-mark)
  (comment-line 1))

如果注释行不可用,请访问最新的newcomment.el:

(defun comment-line (n)
  "Comment or uncomment current line and leave point after it.
With positive prefix, apply to N lines including current one.
With negative prefix, apply to -N lines above.  Also, further
consecutive invocations of this command will inherit the negative
argument.

If region is active, comment lines in active region instead.
Unlike `comment-dwim', this always comments whole lines."
  (interactive "p")
  (if (use-region-p)
      (comment-or-uncomment-region
       (save-excursion
         (goto-char (region-beginning))
         (line-beginning-position))
       (save-excursion
         (goto-char (region-end))
         (line-end-position)))
    (when (and (eq last-command 'comment-line-backward)
               (natnump n))
      (setq n (- n)))
    (let ((range
           (list (line-beginning-position)
                 (goto-char (line-end-position n)))))
      (comment-or-uncomment-region
       (apply #'min range)
       (apply #'max range)))
    (forward-line 1)
    (back-to-indentation)
    (unless (natnump n) (setq this-command 'comment-line-backward))))

为此,您在此处返回的内容已返回“符号的函数定义无效:注释行”
Jaime Arturo Gomez 2016年

@JaimeArturoGomez似乎最近被引入。提供了副本。
AndreasRöhler'16
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.