emacs: interactively search open buffers

前端 未结 7 769
滥情空心
滥情空心 2020-12-05 07:52

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

C-s interactively searches current buffer. Similarly, is there something that searches all th

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 08:25

    The built-in multi-occur-in-matching-buffers hasn't been mentioned. I use a modified version of this (because I invariably want to search all buffers, and specifying a buffer name pattern each time is annoying).

    (defun my-multi-occur-in-matching-buffers (regexp &optional allbufs)
      "Show lines matching REGEXP in all file-visiting buffers.
    
    Given a prefix argument, search in ALL buffers."
      (interactive (occur-read-primary-args))
      (multi-occur-in-matching-buffers "." regexp allbufs))
    
    (global-set-key (kbd "M-s /") 'my-multi-occur-in-matching-buffers)
    

    To invert the behaviour of the prefix argument so that the default behaviour is to search all buffers, change the call to:

    (multi-occur-in-matching-buffers "." regexp (not allbufs))
    

    (and, of course, update the docstring accordingly.)

提交回复
热议问题