emacs: interactively search open buffers

前端 未结 7 802
滥情空心
滥情空心 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:07

    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)
    

提交回复
热议问题