Mercurial > emacs
annotate lisp/isearch-multi.el @ 85762:29e75576e47f
* calc/calc.el (calc-emacs-type-lucid): Remove.
(calc-digit-map, calcDigit-start, calc-read-key)
(calc-clear-unread-commands):
* calc/calc-ext.el (calc-user-key-map): Replace uses of
calc-emacs-type-lucid with (featurep 'xemacs)
* emulation/tpu-mapper.el: Replace tpu-lucid-emacs19-p with
(featurep 'xemacs).
(tpu-lucid-emacs19-p): Remove.
(tpu-map-key): Make it a function instead of using fset. Inline
tpu-emacs-map-key and tpu-lucid-map-key. Use featurep 'xemacs.
(tpu-emacs-map-key, tpu-lucid-map-key): Remove.
* ielm.el: Use featurep 'xemacs.
* progmodes/cperl-mode.el (cperl-xemacs-p): Remove.
(condition-case, cperl-can-font-lock, cperl-singly-quote-face)
(cperl-define-key, cperl-mode-map, cperl-mode, cperl-init-faces)
(cperl-write-tags, cperl-tags-hier-init, cperl-perldoc): Replace
cperl-xemacs-p with (featurep 'xemacs).
(font-lock-cache-position): Pacify byte compiler.
author | Dan Nicolaescu <dann@ics.uci.edu> |
---|---|
date | Mon, 29 Oct 2007 15:33:04 +0000 |
parents | 4516d805659c |
children | f4816ef45bcb |
rev | line source |
---|---|
85568 | 1 ;;; isearch-multi.el --- isearch extensions for multi-buffer search |
2 | |
3 ;; Copyright (C) 2007 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Juri Linkov <juri@jurta.org> | |
6 ;; Keywords: matching | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 3, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
23 ;; Boston, MA 02110-1301, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; This file adds more dimensions to the search space. It implements | |
28 ;; various features that extend isearch. One of them is an ability to | |
29 ;; search through multiple buffers. | |
30 | |
31 ;;; Code: | |
32 | |
33 ;;; Search multiple buffers | |
34 | |
35 (defgroup isearch-buffers nil | |
36 "Using isearch to search through multiple buffers." | |
37 :version "23.1" | |
38 :group 'isearch) | |
39 | |
85667
4516d805659c
(isearch-buffers-multi): New option.
Richard M. Stallman <rms@gnu.org>
parents:
85604
diff
changeset
|
40 (defcustom isearch-buffers-multi t |
4516d805659c
(isearch-buffers-multi): New option.
Richard M. Stallman <rms@gnu.org>
parents:
85604
diff
changeset
|
41 "Non-nil enables searching multiple related buffers, in certain modes." |
4516d805659c
(isearch-buffers-multi): New option.
Richard M. Stallman <rms@gnu.org>
parents:
85604
diff
changeset
|
42 :type 'boolean |
4516d805659c
(isearch-buffers-multi): New option.
Richard M. Stallman <rms@gnu.org>
parents:
85604
diff
changeset
|
43 :version "23.1" |
4516d805659c
(isearch-buffers-multi): New option.
Richard M. Stallman <rms@gnu.org>
parents:
85604
diff
changeset
|
44 :group 'isearch-buffers) |
4516d805659c
(isearch-buffers-multi): New option.
Richard M. Stallman <rms@gnu.org>
parents:
85604
diff
changeset
|
45 |
85568 | 46 (defcustom isearch-buffers-pause t |
47 "A choice defining where to pause the search. | |
48 If the value is nil, don't pause before going to the next buffer. | |
49 If the value is `initial', pause only after a failing search in the | |
50 initial buffer. | |
51 If t, pause in all buffers that contain the search string." | |
52 :type '(choice | |
53 (const :tag "Don't pause" nil) | |
54 (const :tag "Only in initial buffer" initial) | |
55 (const :tag "All buffers" t)) | |
56 :version "23.1" | |
57 :group 'isearch-buffers) | |
58 | |
59 ;;;###autoload | |
60 (defvar isearch-buffers-current-buffer nil | |
61 "The buffer where the search is currently searching. | |
62 The value is nil when the search still is in the initial buffer.") | |
63 | |
64 ;;;###autoload | |
65 (defvar isearch-buffers-next-buffer-function nil | |
66 "Function to call to get the next buffer to search. | |
67 | |
68 When this variable is set to a function that returns a buffer, then | |
69 after typing another C-s or C-r at a failing search, the search goes | |
70 to the next buffer in the series and continues searching for the | |
71 next occurrence. | |
72 | |
73 The first argument of this function is the current buffer where the | |
74 search is currently searching. It defines the base buffer relative to | |
75 which this function should find the next buffer. When the isearch | |
76 direction is backward (when isearch-forward is nil), this function | |
77 should return the previous buffer to search. If the second argument of | |
78 this function WRAP is non-nil, then it should return the first buffer | |
79 in the series; and for the backward search, it should return the last | |
80 buffer in the series.") | |
81 | |
82 ;;;###autoload | |
83 (define-minor-mode isearch-buffers-minor-mode | |
84 "Minor mode for using isearch to search through multiple buffers. | |
85 With arg, turn isearch-buffers minor mode on if arg is positive, off otherwise." | |
86 :group 'isearch-buffers ;; :lighter " X" | |
87 (if isearch-buffers-minor-mode | |
88 (progn | |
89 (add-hook 'isearch-mode-hook 'isearch-buffers-init nil t) | |
90 (set (make-local-variable 'isearch-search-fun-function) | |
91 'isearch-buffers-search-fun) | |
92 (set (make-local-variable 'isearch-wrap-function) | |
93 'isearch-buffers-wrap) | |
94 (set (make-local-variable 'isearch-push-state-function) | |
95 'isearch-buffers-push-state)) | |
96 (remove-hook 'isearch-mode-hook 'isearch-buffers-init t) | |
97 (kill-local-variable 'isearch-search-fun-function) | |
98 (kill-local-variable 'isearch-wrap-function) | |
99 (kill-local-variable 'isearch-push-state-function))) | |
100 | |
101 (defun isearch-buffers-init () | |
102 "Set up isearch to search multiple buffers. | |
103 Intended to be added to `isearch-mode-hook'." | |
104 (setq isearch-buffers-current-buffer nil)) | |
105 | |
106 (defun isearch-buffers-search-fun () | |
107 "Return the proper search function, for isearch in multiple buffers." | |
108 (lambda (string bound noerror) | |
109 (let ((search-fun | |
110 ;; Use standard functions to search within one buffer | |
111 (cond | |
112 (isearch-word | |
113 (if isearch-forward 'word-search-forward 'word-search-backward)) | |
114 (isearch-regexp | |
115 (if isearch-forward 're-search-forward 're-search-backward)) | |
116 (t | |
117 (if isearch-forward 'search-forward 'search-backward)))) | |
118 found buffer) | |
119 (or | |
120 ;; 1. First try searching in the initial buffer | |
121 (let ((res (funcall search-fun string bound noerror))) | |
122 ;; Reset wrapping for all-buffers pause after successful search | |
123 (if (and res (eq isearch-buffers-pause t)) | |
124 (setq isearch-buffers-current-buffer nil)) | |
125 res) | |
126 ;; 2. If the above search fails, start visiting next/prev buffers | |
127 ;; successively, and search the string in them. Do this only | |
128 ;; when bound is nil (i.e. not while lazy-highlighting search | |
129 ;; strings in the current buffer). | |
85667
4516d805659c
(isearch-buffers-multi): New option.
Richard M. Stallman <rms@gnu.org>
parents:
85604
diff
changeset
|
130 (when (and (not bound) isearch-buffers-multi) |
85568 | 131 ;; If no-pause or there was one attempt to leave the current buffer |
132 (if (or (null isearch-buffers-pause) | |
133 (and isearch-buffers-pause isearch-buffers-current-buffer)) | |
134 (condition-case nil | |
135 (progn | |
136 (while (not found) | |
137 ;; Find the next buffer to search | |
138 (setq buffer (funcall isearch-buffers-next-buffer-function | |
139 buffer)) | |
140 (with-current-buffer buffer | |
141 (goto-char (if isearch-forward (point-min) (point-max))) | |
142 (setq isearch-barrier (point) isearch-opoint (point)) | |
143 ;; After visiting the next/prev buffer search the | |
144 ;; string in it again, until the function in | |
145 ;; isearch-buffers-next-buffer-function raises an error | |
146 ;; at the beginning/end of the buffer sequence. | |
147 (setq found (funcall search-fun string bound noerror)))) | |
148 ;; Set buffer for isearch-search-string to switch | |
149 (if buffer (setq isearch-buffers-current-buffer buffer)) | |
150 ;; Return point of the new search result | |
151 found) | |
152 ;; Return nil when isearch-buffers-next-buffer-function fails | |
153 (error nil)) | |
154 (signal 'search-failed (list string "Repeat for next buffer")))))))) | |
155 | |
156 (defun isearch-buffers-wrap () | |
157 "Wrap the multiple buffers search when search is failed. | |
158 Switch buffer to the first buffer for a forward search, | |
159 or to the last buffer for a backward search. | |
160 Set `isearch-buffers-current-buffer' to the current buffer to display | |
161 the isearch suffix message [initial buffer] only when isearch leaves | |
162 the initial buffer." | |
163 (if (or (null isearch-buffers-pause) | |
164 (and isearch-buffers-pause isearch-buffers-current-buffer)) | |
165 (progn | |
166 (switch-to-buffer | |
167 (setq isearch-buffers-current-buffer | |
168 (funcall isearch-buffers-next-buffer-function | |
169 (current-buffer) t))) | |
170 (goto-char (if isearch-forward (point-min) (point-max)))) | |
171 (setq isearch-buffers-current-buffer (current-buffer)) | |
172 (setq isearch-wrapped nil))) | |
173 | |
174 (defun isearch-buffers-push-state () | |
175 "Save a function restoring the state of multiple buffers search. | |
176 Save the current buffer to the additional state parameter in the | |
177 search status stack." | |
178 `(lambda (cmd) | |
179 (isearch-buffers-pop-state cmd ,(current-buffer)))) | |
180 | |
181 (defun isearch-buffers-pop-state (cmd buffer) | |
182 "Restore the multiple buffers search state. | |
183 Switch to the buffer restored from the search status stack." | |
184 (unless (equal buffer (current-buffer)) | |
185 (switch-to-buffer (setq isearch-buffers-current-buffer buffer)))) | |
186 | |
187 (provide 'isearch-multi) | |
85604 | 188 |
189 ;; arch-tag: a6d38ffa-4d14-4e39-8ac6-46af9d6a6773 | |
85568 | 190 ;;; isearch-multi.el ends here |