Emacs复制匹配行 [英] Emacs copy matching lines
本文介绍了Emacs复制匹配行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
发生
通过将它们应对到缓冲区中途,但是它添加了许多额外的东西。
解决方案
这样做如何:
(defun copy-lines-matching-re(re)
找到与当前缓冲区中的regexp RE匹配的所有行
将匹配行放在名为*匹配*
(interactivesRegexp to match:)
(let((result-buffer(get-buffer-create* matching *)))
(with-current-缓冲区结果缓冲区
(擦除缓冲区))
(save-match-data
(save-excursion
(goto-char(point-min))
(while(re-search-forward re nil t)
(princ(buffer-substring-no-properties(line-begin-position))
(line-begin-position 2))
result-buffer))))
(pop-to-buffer result-buffer)))
In Emacs how can I easily copy all lines matching a particular regex? Preferably highlighting the matching lines as I type.
occur
gets partway there by coping them into a buffer, but it adds lots of extra stuff.
解决方案
How about this:
(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屋!
查看全文