changeset 106328:5475f1c5e4ed

(multi-isearch-read-buffers) (multi-isearch-read-matching-buffers): New functions. (multi-isearch-buffers, multi-isearch-buffers-regexp): Use them in the `interactive' spec. Doc fix. (multi-isearch-read-files, multi-isearch-read-matching-files): New functions. (multi-isearch-files, multi-isearch-files-regexp): Use them in the `interactive' spec. Doc fix. (Bug#4725)
author Juri Linkov <juri@jurta.org>
date Mon, 30 Nov 2009 19:42:16 +0000
parents 8cb95e673f03
children 1328c6aa3dec
files etc/NEWS lisp/ChangeLog lisp/misearch.el
diffstat 3 files changed, 108 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/etc/NEWS	Mon Nov 30 16:14:48 2009 +0000
+++ b/etc/NEWS	Mon Nov 30 19:42:16 2009 +0000
@@ -304,6 +304,14 @@
 and `comint-history-isearch-backward-regexp' (bound to M-r) start Isearch
 in the input history regardless of the value of `comint-history-isearch'.
 
+*** Interactively `multi-isearch-buffers' and `multi-isearch-buffers-regexp'
+read buffer names to search, one by one, ended with RET.  With a prefix
+argument, they ask for a regexp, and search in buffers whose names match
+the specified regexp.  Interactively `multi-isearch-files' and
+`multi-isearch-files-regexp' read file names to search, one by one,
+ended with RET.  With a prefix argument, they ask for a wildcard, and
+search in file buffers whose file names match the specified wildcard.
+
 +++
 *** Autorevert Tail mode now works also for remote files.
 
--- a/lisp/ChangeLog	Mon Nov 30 16:14:48 2009 +0000
+++ b/lisp/ChangeLog	Mon Nov 30 19:42:16 2009 +0000
@@ -1,3 +1,14 @@
+2009-11-30  Juri Linkov  <juri@jurta.org>
+
+	* misearch.el (multi-isearch-read-buffers)
+	(multi-isearch-read-matching-buffers): New functions.
+	(multi-isearch-buffers, multi-isearch-buffers-regexp):
+	Use them in the `interactive' spec.  Doc fix.
+	(multi-isearch-read-files, multi-isearch-read-matching-files):
+	New functions.
+	(multi-isearch-files, multi-isearch-files-regexp):
+	Use them in the `interactive' spec.  Doc fix.  (Bug#4725)
+
 2009-11-30  Juri Linkov  <juri@jurta.org>
 
 	* doc-view.el (doc-view-continuous):
--- a/lisp/misearch.el	Mon Nov 30 16:14:48 2009 +0000
+++ b/lisp/misearch.el	Mon Nov 30 19:42:16 2009 +0000
@@ -224,9 +224,46 @@
 	(car buffers)
       (cadr (member (or buffer (current-buffer)) buffers)))))
 
+(defun multi-isearch-read-buffers ()
+  "Return a list of buffers specified interactively, one by one."
+  ;; Most code from `multi-occur'.
+  (let* ((bufs (list (read-buffer "First buffer to search: "
+				  (current-buffer) t)))
+	 (buf nil)
+	 (ido-ignore-item-temp-list bufs))
+    (while (not (string-equal
+		 (setq buf (read-buffer
+			    (if (eq read-buffer-function 'ido-read-buffer)
+				"Next buffer to search (C-j to end): "
+			      "Next buffer to search (RET to end): ")
+			    nil t))
+		 ""))
+      (add-to-list 'bufs buf)
+      (setq ido-ignore-item-temp-list bufs))
+    (nreverse (mapcar #'get-buffer bufs))))
+
+(defun multi-isearch-read-matching-buffers ()
+  "Return a list of buffers whose names match specified regexp."
+  ;; Most code from `multi-occur-in-matching-buffers'
+  ;; and `kill-matching-buffers'.
+  (let ((bufregexp
+	 (read-regexp "Search in buffers whose names match regexp")))
+    (when bufregexp
+      (delq nil (mapcar (lambda (buf)
+			  (when (string-match bufregexp (buffer-name buf))
+			    buf))
+			(buffer-list))))))
+
 ;;;###autoload
 (defun multi-isearch-buffers (buffers)
-  "Start multi-buffer Isearch on a list of BUFFERS."
+  "Start multi-buffer Isearch on a list of BUFFERS.
+Interactively read buffer names to search, one by one, ended with RET.
+With a prefix argument, ask for a regexp, and search in buffers
+whose names match the specified regexp."
+  (interactive
+   (list (if current-prefix-arg
+	     (multi-isearch-read-matching-buffers)
+	   (multi-isearch-read-buffers))))
   (let ((multi-isearch-next-buffer-function
 	 'multi-isearch-next-buffer-from-list)
 	(multi-isearch-buffer-list buffers))
@@ -236,7 +273,14 @@
 
 ;;;###autoload
 (defun multi-isearch-buffers-regexp (buffers)
-  "Start multi-buffer regexp Isearch on a list of BUFFERS."
+  "Start multi-buffer regexp Isearch on a list of BUFFERS.
+Interactively read buffer names to search, one by one, ended with RET.
+With a prefix argument, ask for a regexp, and search in buffers
+whose names match the specified regexp."
+  (interactive
+   (list (if current-prefix-arg
+	     (multi-isearch-read-matching-buffers)
+	   (multi-isearch-read-buffers))))
   (let ((multi-isearch-next-buffer-function
 	 'multi-isearch-next-buffer-from-list)
 	(multi-isearch-buffer-list buffers))
@@ -264,9 +308,43 @@
 	 (car files)
        (cadr (member (buffer-file-name buffer) files))))))
 
+(defun multi-isearch-read-files ()
+  "Return a list of files specified interactively, one by one."
+  ;; Most code from `multi-occur'.
+  (let* ((files (list (read-file-name "First file to search: "
+				      default-directory
+				      buffer-file-name)))
+	 (file nil))
+    (while (not (string-equal
+		 (setq file (read-file-name
+			     "Next file to search (RET to end): "
+			     default-directory
+			     default-directory))
+		 default-directory))
+      (add-to-list 'files file))
+    (nreverse files)))
+
+(defun multi-isearch-read-matching-files ()
+  "Return a list of files whose names match specified wildcard."
+  ;; Most wildcard code from `find-file-noselect'.
+  (let ((filename (read-regexp "Search in files whose names match wildcard")))
+    (when (and filename
+	       (not (string-match "\\`/:" filename))
+	       (string-match "[[*?]" filename))
+      (condition-case nil
+	  (file-expand-wildcards filename t)
+	(error (list filename))))))
+
 ;;;###autoload
 (defun multi-isearch-files (files)
-  "Start multi-buffer Isearch on a list of FILES."
+  "Start multi-buffer Isearch on a list of FILES.
+Interactively read file names to search, one by one, ended with RET.
+With a prefix argument, ask for a wildcard, and search in file buffers
+whose file names match the specified wildcard."
+  (interactive
+   (list (if current-prefix-arg
+	     (multi-isearch-read-matching-files)
+	   (multi-isearch-read-files))))
   (let ((multi-isearch-next-buffer-function
 	 'multi-isearch-next-file-buffer-from-list)
 	(multi-isearch-file-list files))
@@ -276,7 +354,14 @@
 
 ;;;###autoload
 (defun multi-isearch-files-regexp (files)
-  "Start multi-buffer regexp Isearch on a list of FILES."
+  "Start multi-buffer regexp Isearch on a list of FILES.
+Interactively read file names to search, one by one, ended with RET.
+With a prefix argument, ask for a wildcard, and search in file buffers
+whose file names match the specified wildcard."
+  (interactive
+   (list (if current-prefix-arg
+	     (multi-isearch-read-matching-files)
+	   (multi-isearch-read-files))))
   (let ((multi-isearch-next-buffer-function
 	 'multi-isearch-next-file-buffer-from-list)
 	(multi-isearch-file-list files))