phi*_*ils 28
从Emacs 24开始,occur确实提供了一个简单的解决方案:
C-uM-so .*pattern.* RET
当您C-u自己使用作为前缀参数时,每行的匹配部分将插入*Occur*缓冲区,而不包含所有正常的装饰.
请注意,因为只有相匹配的正则表达式行的一部分用于(不像一个正常的发生),你需要的前端和后端.*,以确保您捕捉到整条生产线.
occur处理参数的细节有点棘手,所以C-hf occur RET如果你想了解更多,请仔细阅读.
Tre*_*son 12
这个怎么样:
(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)))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3005 次 |
| 最近记录: |