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

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

Re: search in loaded buffers


From: Greg Hill
Subject: Re: search in loaded buffers
Date: Wed, 23 Feb 2005 13:19:41 -0800

Dave,

I have my own home-brewed function for doing that. Here is what I have in my .emacs file. It is not bullet-proof, but it gets the job done (i.e. "No warrantee is expressed or implied ...") Hope it helps.

--Greg


(defun search-multiple-buffers (search-string)
  "Search through all currently loaded \"normal\" buffers for the next
occurance of SEARCH-STRING"
  (interactive
   (list (read-string
          (concat "Search for (" (car search-ring) "): ")
          nil
          'search-ring
          (car search-ring))))

  (unless (interactive-p)
    (push search-string search-ring))

  (let ((start-buffer (current-buffer))
        (buflist (cdr (buffer-list)))
        (save-point (point))
        (start-point (point))
        buffer-type)

    (catch 'buflist
      (while
          (progn
            (setq buffer-type
                  (string-to-char (buffer-name (current-buffer))))
            (if (or (= buffer-type ?*) (= buffer-type ?\ ))
                t
;;            (not (search-forward search-string nil t))))
              (not (let ((case-fold-search nil))
                     (search-forward search-string nil t)))))
        (goto-char save-point)
        (if buflist
            (progn
              (bury-buffer)
              (set-buffer (car buflist))
              (setq buflist (cdr buflist))
              (setq save-point (point))
              (goto-char (point-min)))
          (set-buffer start-buffer)
          (beginning-of-buffer)
          (if (or (not (let ((case-fold-search nil))
                         (search-forward search-string nil t)))
                  (>= (point) (start-point)) )
              (progn
                (message "not found: %s" search-string)
                (goto-char start-point)
                (throw 'buflist nil) ) ) ) ) )

    (set-window-buffer (selected-window) (current-buffer))))


(global-set-key [A-f5] 'search-multiple-buffers)

(defun more-search-multiple-buffers () (interactive)
  (search-multiple-buffers (car search-ring)))

(global-set-key [?\A-g] 'more-search-multiple-buffers)

(defun smb-this-symbol ()
  (interactive)
  (search-multiple-buffers (symbol-name (symbol-at-point))) )

(global-set-key [C-A-f5] 'smb-this-symbol)


On Feb 23, 2005, at 12:10 PM, J. David Boyd wrote:


I've scanned the docs, and don't seem to be able to locate what I'm searching
for.

Is there a way in emacs to search (or grep) through all the loaded buffers,
and only the loaded buffers?

Dave in Largo, FL



_______________________________________________
Help-gnu-emacs mailing list
Help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs





reply via email to

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