Emacs 复制匹配行 [英] Emacs copy matching lines
本文介绍了Emacs 复制匹配行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Emacs 中,如何轻松复制与特定正则表达式匹配的所有行?最好在我输入时突出显示匹配的行.
In Emacs how can I easily copy all lines matching a particular regex? Preferably highlighting the matching lines as I type.
occur
通过将它们处理到缓冲区中,但它增加了许多额外的东西.
occur
gets partway there by coping them into a buffer, but it adds lots of extra stuff.
推荐答案
这个怎么样:
(defun copy-lines-matching-re (re)
"find all lines matching the regexp RE in the current buffer
putting the matching lines in a buffer named *matching*"
(interactive "sRegexp to match: ")
(let ((result-buffer (get-buffer-create "*matching*")))
(with-current-buffer result-buffer
(erase-buffer))
(save-match-data
(save-excursion
(goto-char (point-min))
(while (re-search-forward re nil t)
(princ (buffer-substring-no-properties (line-beginning-position)
(line-beginning-position 2))
result-buffer))))
(pop-to-buffer result-buffer)))
这篇关于Emacs 复制匹配行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文