annotate lisp/misearch.el @ 106458:3b1d7962549d

Fixed Bug#5008.
author Ulf Jasper <ulf.jasper@web.de>
date Sun, 06 Dec 2009 18:13:19 +0000
parents a620dcf767e8
children 1d1d5d9bd884
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
1 ;;; misearch.el --- isearch extensions for multi-buffer search
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
2
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 100737
diff changeset
3 ;; Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
4
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
5 ;; Author: Juri Linkov <juri@jurta.org>
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
6 ;; Keywords: matching
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
7
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
9
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
13 ;; (at your option) any later version.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
14
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
19
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
22
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
23 ;;; Commentary:
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
24
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
25 ;; This file adds more dimensions to the search space. It implements
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
26 ;; various features that extend isearch. One of them is an ability to
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
27 ;; search through multiple buffers.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
28
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
29 ;;; Code:
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
30
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
31 ;;; Search multiple buffers
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
32
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
33 ;;;###autoload (add-hook 'isearch-mode-hook 'multi-isearch-setup)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
34
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
35 (defgroup multi-isearch nil
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
36 "Using isearch to search through multiple buffers."
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
37 :version "23.1"
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
38 :group 'isearch)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
39
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
40 (defcustom multi-isearch-search t
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
41 "Non-nil enables searching multiple related buffers, in certain modes."
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
42 :type 'boolean
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
43 :version "23.1"
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
44 :group 'multi-isearch)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
45
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
46 (defcustom multi-isearch-pause t
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
47 "A choice defining where to pause the search.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
48 If the value is nil, don't pause before going to the next buffer.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
49 If the value is `initial', pause only after a failing search in the
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
50 initial buffer.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
51 If t, pause in all buffers that contain the search string."
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
52 :type '(choice
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
53 (const :tag "Don't pause" nil)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
54 (const :tag "Only in initial buffer" initial)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
55 (const :tag "All buffers" t))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
56 :version "23.1"
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
57 :group 'multi-isearch)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
58
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
59 ;;;###autoload
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
60 (defvar multi-isearch-next-buffer-function nil
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
61 "Function to call to get the next buffer to search.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
62
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
63 When this variable is set to a function that returns a buffer, then
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
64 after typing another \\[isearch-forward] or \\[isearch-backward] \
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
65 at a failing search, the search goes
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
66 to the next buffer in the series and continues searching for the
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
67 next occurrence.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
68
100737
ee29f2a93b76 (multi-isearch-next-buffer-function): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 96950
diff changeset
69 This function should return the next buffer (it doesn't need to switch
ee29f2a93b76 (multi-isearch-next-buffer-function): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 96950
diff changeset
70 to it), or nil if it can't find the next buffer (when it reaches the
ee29f2a93b76 (multi-isearch-next-buffer-function): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 96950
diff changeset
71 end of the search space).
ee29f2a93b76 (multi-isearch-next-buffer-function): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 96950
diff changeset
72
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
73 The first argument of this function is the current buffer where the
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
74 search is currently searching. It defines the base buffer relative to
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
75 which this function should find the next buffer. When the isearch
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
76 direction is backward (when `isearch-forward' is nil), this function
100737
ee29f2a93b76 (multi-isearch-next-buffer-function): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 96950
diff changeset
77 should return the previous buffer to search.
ee29f2a93b76 (multi-isearch-next-buffer-function): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 96950
diff changeset
78
ee29f2a93b76 (multi-isearch-next-buffer-function): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 96950
diff changeset
79 If the second argument of this function WRAP is non-nil, then it
ee29f2a93b76 (multi-isearch-next-buffer-function): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 96950
diff changeset
80 should return the first buffer in the series; and for the backward
ee29f2a93b76 (multi-isearch-next-buffer-function): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 96950
diff changeset
81 search, it should return the last buffer in the series.")
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
82
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
83 ;;;###autoload
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
84 (defvar multi-isearch-next-buffer-current-function nil
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
85 "The currently active function to get the next buffer to search.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
86 Initialized from `multi-isearch-next-buffer-function' when
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
87 Isearch starts.")
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
88
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
89 ;;;###autoload
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
90 (defvar multi-isearch-current-buffer nil
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
91 "The buffer where the search is currently searching.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
92 The value is nil when the search still is in the initial buffer.")
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
93
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
94 (defvar multi-isearch-orig-search-fun nil)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
95 (defvar multi-isearch-orig-wrap nil)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
96 (defvar multi-isearch-orig-push-state nil)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
97
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
98
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
99 ;;;###autoload
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
100 (defun multi-isearch-setup ()
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
101 "Set up isearch to search multiple buffers.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
102 Intended to be added to `isearch-mode-hook'."
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
103 (when (and multi-isearch-search
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
104 multi-isearch-next-buffer-function)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
105 (setq multi-isearch-current-buffer nil
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
106 multi-isearch-next-buffer-current-function
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
107 multi-isearch-next-buffer-function
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
108 multi-isearch-orig-search-fun
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
109 (default-value 'isearch-search-fun-function)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
110 multi-isearch-orig-wrap
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
111 (default-value 'isearch-wrap-function)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
112 multi-isearch-orig-push-state
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
113 (default-value 'isearch-push-state-function))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
114 (setq-default isearch-search-fun-function 'multi-isearch-search-fun
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
115 isearch-wrap-function 'multi-isearch-wrap
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
116 isearch-push-state-function 'multi-isearch-push-state)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
117 (add-hook 'isearch-mode-end-hook 'multi-isearch-end)))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
118
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
119 (defun multi-isearch-end ()
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
120 "Clean up the multi-buffer search after terminating isearch."
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
121 (setq multi-isearch-current-buffer nil
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
122 multi-isearch-next-buffer-current-function nil)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
123 (setq-default isearch-search-fun-function multi-isearch-orig-search-fun
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
124 isearch-wrap-function multi-isearch-orig-wrap
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
125 isearch-push-state-function multi-isearch-orig-push-state)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
126 (remove-hook 'isearch-mode-end-hook 'multi-isearch-end))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
127
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
128 (defun multi-isearch-search-fun ()
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
129 "Return the proper search function, for isearch in multiple buffers."
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
130 (lambda (string bound noerror)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
131 (let ((search-fun
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
132 ;; Use standard functions to search within one buffer
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
133 (cond
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
134 (isearch-word
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
135 (if isearch-forward 'word-search-forward 'word-search-backward))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
136 (isearch-regexp
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
137 (if isearch-forward 're-search-forward 're-search-backward))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
138 (t
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
139 (if isearch-forward 'search-forward 'search-backward))))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
140 found buffer)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
141 (or
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
142 ;; 1. First try searching in the initial buffer
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
143 (let ((res (funcall search-fun string bound noerror)))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
144 ;; Reset wrapping for all-buffers pause after successful search
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
145 (if (and res (eq multi-isearch-pause t))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
146 (setq multi-isearch-current-buffer nil))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
147 res)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
148 ;; 2. If the above search fails, start visiting next/prev buffers
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
149 ;; successively, and search the string in them. Do this only
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
150 ;; when bound is nil (i.e. not while lazy-highlighting search
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
151 ;; strings in the current buffer).
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
152 (when (and (not bound) multi-isearch-search)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
153 ;; If no-pause or there was one attempt to leave the current buffer
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
154 (if (or (null multi-isearch-pause)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
155 (and multi-isearch-pause multi-isearch-current-buffer))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
156 (condition-case nil
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
157 (progn
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
158 (while (not found)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
159 ;; Find the next buffer to search
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
160 (setq buffer (funcall multi-isearch-next-buffer-current-function
106332
a620dcf767e8 (multi-isearch-search-fun): Always provide a non-nil
Juri Linkov <juri@jurta.org>
parents: 106329
diff changeset
161 (or buffer (current-buffer)) nil))
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
162 (with-current-buffer buffer
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
163 (goto-char (if isearch-forward (point-min) (point-max)))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
164 (setq isearch-barrier (point) isearch-opoint (point))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
165 ;; After visiting the next/prev buffer search the
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
166 ;; string in it again, until the function in
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
167 ;; multi-isearch-next-buffer-current-function raises
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
168 ;; an error at the beginning/end of the buffer sequence.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
169 (setq found (funcall search-fun string bound noerror))))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
170 ;; Set buffer for isearch-search-string to switch
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
171 (if buffer (setq multi-isearch-current-buffer buffer))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
172 ;; Return point of the new search result
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
173 found)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
174 ;; Return nil when multi-isearch-next-buffer-current-function fails
100737
ee29f2a93b76 (multi-isearch-next-buffer-function): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 96950
diff changeset
175 ;; (`with-current-buffer' raises an error for nil returned from it).
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
176 (error nil))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
177 (signal 'search-failed (list string "Repeat for next buffer"))))))))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
178
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
179 (defun multi-isearch-wrap ()
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
180 "Wrap the multiple buffers search when search is failed.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
181 Switch buffer to the first buffer for a forward search,
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
182 or to the last buffer for a backward search.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
183 Set `multi-isearch-current-buffer' to the current buffer to display
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
184 the isearch suffix message [initial buffer] only when isearch leaves
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
185 the initial buffer."
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
186 (if (or (null multi-isearch-pause)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
187 (and multi-isearch-pause multi-isearch-current-buffer))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
188 (progn
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
189 (switch-to-buffer
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
190 (setq multi-isearch-current-buffer
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
191 (funcall multi-isearch-next-buffer-current-function
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
192 (current-buffer) t)))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
193 (goto-char (if isearch-forward (point-min) (point-max))))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
194 (setq multi-isearch-current-buffer (current-buffer))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
195 (setq isearch-wrapped nil)))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
196
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
197 (defun multi-isearch-push-state ()
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
198 "Save a function restoring the state of multiple buffers search.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
199 Save the current buffer to the additional state parameter in the
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
200 search status stack."
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
201 `(lambda (cmd)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
202 (multi-isearch-pop-state cmd ,(current-buffer))))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
203
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
204 (defun multi-isearch-pop-state (cmd buffer)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
205 "Restore the multiple buffers search state.
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
206 Switch to the buffer restored from the search status stack."
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
207 (unless (equal buffer (current-buffer))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
208 (switch-to-buffer (setq multi-isearch-current-buffer buffer))))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
209
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
210
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
211 ;;; Global multi-buffer search invocations
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
212
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
213 (defvar multi-isearch-buffer-list nil)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
214
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
215 (defun multi-isearch-next-buffer-from-list (&optional buffer wrap)
105599
490704d92623 (multi-isearch-next-buffer-from-list)
Juri Linkov <juri@jurta.org>
parents: 100908
diff changeset
216 "Return the next buffer in the series of buffers.
490704d92623 (multi-isearch-next-buffer-from-list)
Juri Linkov <juri@jurta.org>
parents: 100908
diff changeset
217 This function is used for multiple buffers Isearch. A sequence of
490704d92623 (multi-isearch-next-buffer-from-list)
Juri Linkov <juri@jurta.org>
parents: 100908
diff changeset
218 buffers is defined by the variable `multi-isearch-buffer-list'
490704d92623 (multi-isearch-next-buffer-from-list)
Juri Linkov <juri@jurta.org>
parents: 100908
diff changeset
219 set in `multi-isearch-buffers' or `multi-isearch-buffers-regexp'."
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
220 (let ((buffers (if isearch-forward
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
221 multi-isearch-buffer-list
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
222 (reverse multi-isearch-buffer-list))))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
223 (if wrap
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
224 (car buffers)
106332
a620dcf767e8 (multi-isearch-search-fun): Always provide a non-nil
Juri Linkov <juri@jurta.org>
parents: 106329
diff changeset
225 (cadr (member buffer buffers)))))
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
226
106328
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
227 (defun multi-isearch-read-buffers ()
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
228 "Return a list of buffers specified interactively, one by one."
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
229 ;; Most code from `multi-occur'.
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
230 (let* ((bufs (list (read-buffer "First buffer to search: "
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
231 (current-buffer) t)))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
232 (buf nil)
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
233 (ido-ignore-item-temp-list bufs))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
234 (while (not (string-equal
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
235 (setq buf (read-buffer
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
236 (if (eq read-buffer-function 'ido-read-buffer)
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
237 "Next buffer to search (C-j to end): "
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
238 "Next buffer to search (RET to end): ")
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
239 nil t))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
240 ""))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
241 (add-to-list 'bufs buf)
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
242 (setq ido-ignore-item-temp-list bufs))
106329
1328c6aa3dec (multi-isearch-read-buffers): Move canonicalization
Juri Linkov <juri@jurta.org>
parents: 106328
diff changeset
243 (nreverse bufs)))
106328
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
244
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
245 (defun multi-isearch-read-matching-buffers ()
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
246 "Return a list of buffers whose names match specified regexp."
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
247 ;; Most code from `multi-occur-in-matching-buffers'
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
248 ;; and `kill-matching-buffers'.
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
249 (let ((bufregexp
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
250 (read-regexp "Search in buffers whose names match regexp")))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
251 (when bufregexp
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
252 (delq nil (mapcar (lambda (buf)
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
253 (when (string-match bufregexp (buffer-name buf))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
254 buf))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
255 (buffer-list))))))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
256
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
257 ;;;###autoload
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
258 (defun multi-isearch-buffers (buffers)
106328
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
259 "Start multi-buffer Isearch on a list of BUFFERS.
106329
1328c6aa3dec (multi-isearch-read-buffers): Move canonicalization
Juri Linkov <juri@jurta.org>
parents: 106328
diff changeset
260 This list can contain live buffers or their names.
106328
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
261 Interactively read buffer names to search, one by one, ended with RET.
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
262 With a prefix argument, ask for a regexp, and search in buffers
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
263 whose names match the specified regexp."
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
264 (interactive
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
265 (list (if current-prefix-arg
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
266 (multi-isearch-read-matching-buffers)
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
267 (multi-isearch-read-buffers))))
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
268 (let ((multi-isearch-next-buffer-function
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
269 'multi-isearch-next-buffer-from-list)
106329
1328c6aa3dec (multi-isearch-read-buffers): Move canonicalization
Juri Linkov <juri@jurta.org>
parents: 106328
diff changeset
270 (multi-isearch-buffer-list (mapcar #'get-buffer buffers)))
1328c6aa3dec (multi-isearch-read-buffers): Move canonicalization
Juri Linkov <juri@jurta.org>
parents: 106328
diff changeset
271 (switch-to-buffer (car multi-isearch-buffer-list))
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
272 (goto-char (if isearch-forward (point-min) (point-max)))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
273 (isearch-forward)))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
274
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
275 ;;;###autoload
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
276 (defun multi-isearch-buffers-regexp (buffers)
106328
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
277 "Start multi-buffer regexp Isearch on a list of BUFFERS.
106329
1328c6aa3dec (multi-isearch-read-buffers): Move canonicalization
Juri Linkov <juri@jurta.org>
parents: 106328
diff changeset
278 This list can contain live buffers or their names.
106328
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
279 Interactively read buffer names to search, one by one, ended with RET.
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
280 With a prefix argument, ask for a regexp, and search in buffers
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
281 whose names match the specified regexp."
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
282 (interactive
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
283 (list (if current-prefix-arg
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
284 (multi-isearch-read-matching-buffers)
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
285 (multi-isearch-read-buffers))))
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
286 (let ((multi-isearch-next-buffer-function
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
287 'multi-isearch-next-buffer-from-list)
106329
1328c6aa3dec (multi-isearch-read-buffers): Move canonicalization
Juri Linkov <juri@jurta.org>
parents: 106328
diff changeset
288 (multi-isearch-buffer-list (mapcar #'get-buffer buffers)))
1328c6aa3dec (multi-isearch-read-buffers): Move canonicalization
Juri Linkov <juri@jurta.org>
parents: 106328
diff changeset
289 (switch-to-buffer (car multi-isearch-buffer-list))
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
290 (goto-char (if isearch-forward (point-min) (point-max)))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
291 (isearch-forward-regexp)))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
292
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
293
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
294 ;;; Global multi-file search invocations
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
295
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
296 (defvar multi-isearch-file-list nil)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
297
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
298 (defun multi-isearch-next-file-buffer-from-list (&optional buffer wrap)
105599
490704d92623 (multi-isearch-next-buffer-from-list)
Juri Linkov <juri@jurta.org>
parents: 100908
diff changeset
299 "Return the next buffer in the series of file buffers.
490704d92623 (multi-isearch-next-buffer-from-list)
Juri Linkov <juri@jurta.org>
parents: 100908
diff changeset
300 This function is used for multiple file buffers Isearch. A sequence
490704d92623 (multi-isearch-next-buffer-from-list)
Juri Linkov <juri@jurta.org>
parents: 100908
diff changeset
301 of files is defined by the variable `multi-isearch-file-list' set in
490704d92623 (multi-isearch-next-buffer-from-list)
Juri Linkov <juri@jurta.org>
parents: 100908
diff changeset
302 `multi-isearch-files' or `multi-isearch-files-regexp'.
490704d92623 (multi-isearch-next-buffer-from-list)
Juri Linkov <juri@jurta.org>
parents: 100908
diff changeset
303 Every next/previous file in the defined sequence is visited by
490704d92623 (multi-isearch-next-buffer-from-list)
Juri Linkov <juri@jurta.org>
parents: 100908
diff changeset
304 `find-file-noselect' that returns the corresponding file buffer."
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
305 (let ((files (if isearch-forward
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
306 multi-isearch-file-list
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
307 (reverse multi-isearch-file-list))))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
308 (find-file-noselect
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
309 (if wrap
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
310 (car files)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
311 (cadr (member (buffer-file-name buffer) files))))))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
312
106328
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
313 (defun multi-isearch-read-files ()
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
314 "Return a list of files specified interactively, one by one."
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
315 ;; Most code from `multi-occur'.
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
316 (let* ((files (list (read-file-name "First file to search: "
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
317 default-directory
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
318 buffer-file-name)))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
319 (file nil))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
320 (while (not (string-equal
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
321 (setq file (read-file-name
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
322 "Next file to search (RET to end): "
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
323 default-directory
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
324 default-directory))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
325 default-directory))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
326 (add-to-list 'files file))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
327 (nreverse files)))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
328
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
329 (defun multi-isearch-read-matching-files ()
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
330 "Return a list of files whose names match specified wildcard."
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
331 ;; Most wildcard code from `find-file-noselect'.
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
332 (let ((filename (read-regexp "Search in files whose names match wildcard")))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
333 (when (and filename
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
334 (not (string-match "\\`/:" filename))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
335 (string-match "[[*?]" filename))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
336 (condition-case nil
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
337 (file-expand-wildcards filename t)
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
338 (error (list filename))))))
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
339
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
340 ;;;###autoload
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
341 (defun multi-isearch-files (files)
106328
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
342 "Start multi-buffer Isearch on a list of FILES.
106329
1328c6aa3dec (multi-isearch-read-buffers): Move canonicalization
Juri Linkov <juri@jurta.org>
parents: 106328
diff changeset
343 Relative file names in this list are expanded to absolute
1328c6aa3dec (multi-isearch-read-buffers): Move canonicalization
Juri Linkov <juri@jurta.org>
parents: 106328
diff changeset
344 file names using the current buffer's value of `default-directory'.
106328
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
345 Interactively read file names to search, one by one, ended with RET.
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
346 With a prefix argument, ask for a wildcard, and search in file buffers
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
347 whose file names match the specified wildcard."
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
348 (interactive
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
349 (list (if current-prefix-arg
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
350 (multi-isearch-read-matching-files)
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
351 (multi-isearch-read-files))))
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
352 (let ((multi-isearch-next-buffer-function
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
353 'multi-isearch-next-file-buffer-from-list)
106329
1328c6aa3dec (multi-isearch-read-buffers): Move canonicalization
Juri Linkov <juri@jurta.org>
parents: 106328
diff changeset
354 (multi-isearch-file-list (mapcar #'expand-file-name files)))
1328c6aa3dec (multi-isearch-read-buffers): Move canonicalization
Juri Linkov <juri@jurta.org>
parents: 106328
diff changeset
355 (find-file (car multi-isearch-file-list))
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
356 (goto-char (if isearch-forward (point-min) (point-max)))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
357 (isearch-forward)))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
358
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
359 ;;;###autoload
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
360 (defun multi-isearch-files-regexp (files)
106328
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
361 "Start multi-buffer regexp Isearch on a list of FILES.
106329
1328c6aa3dec (multi-isearch-read-buffers): Move canonicalization
Juri Linkov <juri@jurta.org>
parents: 106328
diff changeset
362 Relative file names in this list are expanded to absolute
1328c6aa3dec (multi-isearch-read-buffers): Move canonicalization
Juri Linkov <juri@jurta.org>
parents: 106328
diff changeset
363 file names using the current buffer's value of `default-directory'.
106328
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
364 Interactively read file names to search, one by one, ended with RET.
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
365 With a prefix argument, ask for a wildcard, and search in file buffers
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
366 whose file names match the specified wildcard."
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
367 (interactive
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
368 (list (if current-prefix-arg
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
369 (multi-isearch-read-matching-files)
5475f1c5e4ed (multi-isearch-read-buffers)
Juri Linkov <juri@jurta.org>
parents: 105599
diff changeset
370 (multi-isearch-read-files))))
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
371 (let ((multi-isearch-next-buffer-function
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
372 'multi-isearch-next-file-buffer-from-list)
106329
1328c6aa3dec (multi-isearch-read-buffers): Move canonicalization
Juri Linkov <juri@jurta.org>
parents: 106328
diff changeset
373 (multi-isearch-file-list (mapcar #'expand-file-name files)))
1328c6aa3dec (multi-isearch-read-buffers): Move canonicalization
Juri Linkov <juri@jurta.org>
parents: 106328
diff changeset
374 (find-file (car multi-isearch-file-list))
96950
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
375 (goto-char (if isearch-forward (point-min) (point-max)))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
376 (isearch-forward-regexp)))
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
377
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
378
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
379 (provide 'multi-isearch)
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
380
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
381 ;; arch-tag: a6d38ffa-4d14-4e39-8ac6-46af9d6a6773
2e007ba78796 Initial revision for a new file with most content from isearch-multi.el.
Juri Linkov <juri@jurta.org>
parents:
diff changeset
382 ;;; misearch.el ends here