gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

aok.el


From: Joe Corneli
Subject: aok.el
Date: Tue, 10 May 2005 22:16:53 -0500

Emacs includes `multi-occur' and `multi-occur-by-filename-regexp', but
it does not seem to include simple convenience wrappers for these
functions, e.g., to search all buffers, all buffers whose filenames
have a certain type, or all buffers in a certain mode.  The code is
easy enough to write - and since I seem to be finding it useful, I
figured I'd share it.

As further evidence that this is not particularly special code, if you
google for "multi-occur emacs" you'll find a potentially even more
exciting implementation of something similar...

   From: John Paul Wallington <jpw <at> gnu.org>
   Subject: Re: How to search through all buffers?
   Newsgroups: gmane.emacs.help

;;; aok.el -- various useful ways to do `multi-occur'

;; Copyright (C) 2004 Joe Corneli <address@hidden>

;; Time-stamp: <jac -- Tue May 10 11:01:12 CDT 2005>

;; This file is not part of GNU Emacs, but it is distributed under
;; the same terms as GNU Emacs.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation; either version 2, or (at your
;; option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;; search all buffers, all buffers whose filenames have a certain
;; type, or all buffers in a certain mode, with `all-occur',
;; `type-occur', or `mode-occur', respectively.

;;; Code:

(require 'cl)

(defun all-occur (rexp)
  "Search all buffers for REXP."
  (interactive "MRegexp: ")
  (multi-occur (buffer-list) rexp))

;; this one {c}/{sh}ould be a completing read that would read from a
;; predefined list of filetype extensions (without requiring a match).
(defun type-occur (extension rexp)
  "EXTENSION denotes a filetype extension to search.
Run occur in all buffers whose names match this type for REXP."
  (interactive "MExtension: \nMRegexp: ")
  (multi-occur-by-filename-regexp (concat ".*\." extension) rexp))

(defun mode-occur (mode rexp)
  "Search all buffers with major mode MODE for REXP."
  (interactive (list (read-command "Mode: ")
                     (read-string "Regexp: ")))
  (multi-occur (remove-if (lambda (buf)
                            (set-buffer buf)
                            (not (eq major-mode mode)))
                          (buffer-list))
               rexp))

;;; aok.el ends here




reply via email to

[Prev in Thread] Current Thread [Next in Thread]