emacs:交互式搜索打开的缓冲区 [英] emacs: interactively search open buffers

查看:20
本文介绍了emacs:交互式搜索打开的缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在所有打开的缓冲区中搜索特定模式?

Is there a way to search all the open buffers for a particular pattern?

C-s 以交互方式搜索当前缓冲区.同样,有没有什么东西可以搜索所有打开的缓冲区?

C-s interactively searches current buffer. Similarly, is there something that searches all the open buffers?

我知道我可以使用occur",但是Occur"带来了一个新的缓冲区,并且缓冲区组织发生了变化/混乱.

I know I can use "occur", but "Occur" brings a new buffer and changes/messes with the buffer organization.

推荐答案

我已经修复了 TODO:

I've fixed the TODO:

;; I know that string is in my Emacs somewhere!
(require 'cl)
(defcustom search-all-buffers-ignored-files (list (rx-to-string '(and bos (or ".bash_history" "TAGS") eos)))
  "Files to ignore when searching buffers via \[search-all-buffers]."
  :type 'editable-list)

(require 'grep)
(defun search-all-buffers (regexp prefix)
  "Searches file-visiting buffers for occurence of REGEXP.  With
prefix > 1 (i.e., if you type C-u \[search-all-buffers]),
searches all buffers."
  (interactive (list (grep-read-regexp)
                     current-prefix-arg))
  (message "Regexp is %s; prefix is %s" regexp prefix)
  (multi-occur
   (if (member prefix '(4 (4)))
       (buffer-list)
     (remove-if
      (lambda (b) (some (lambda (rx) (string-match rx  (file-name-nondirectory (buffer-file-name b)))) search-all-buffers-ignored-files))
      (remove-if-not 'buffer-file-name (buffer-list))))

   regexp))

(global-set-key [f7] 'search-all-buffers)

这篇关于emacs:交互式搜索打开的缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆