gpt4 book ai didi

emacs - Emacs复制匹配行

转载 作者:行者123 更新时间:2023-12-03 15:07:11 29 4
gpt4 key购买 nike

在Emacs中,如何轻松复制与特定正则表达式匹配的所有行?最好在输入时突出显示匹配的行。

occur通过将它们处理到缓冲区中来达到目的,但是它增加了很多额外的东西。

最佳答案

这个怎么样:

(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 - Emacs复制匹配行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2289883/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com