37
37
(require 'grep )
38
38
(require 'isearch )
39
39
40
-
41
40
(defgroup isearch-project nil
42
41
" Incremental search through the whole project."
43
42
:prefix " isearch-project-"
44
43
:group 'isearch
45
44
:link '(url-link :tag " Repository" " https://github.com/jcs090218/isearch-project" ))
46
45
47
-
48
46
(defcustom isearch-project-ignore-paths '(" .vs/"
49
47
" .vscode/"
50
48
" node_modules/" )
51
49
" List of path you want to ignore by Incremental searching in the project."
52
50
:type 'list
53
51
:group 'isearch-project )
54
52
55
-
56
53
(defvar isearch-project--search-path " "
57
54
" Record the current search path, so when next time it searhs would not need to research from the start." )
58
55
@@ -92,6 +89,20 @@ LST : List you want to modified."
92
89
(setcdr last (cddr last ))
93
90
lst)))
94
91
92
+ (defun isearch-project--contain-string (in-sub-str in-str )
93
+ " Check if a string is a substring of another string.
94
+ Return true if contain, else return false.
95
+ IN-SUB-STR : substring to see if contain in the IN-STR.
96
+ IN-STR : string to check by the IN-SUB-STR."
97
+ (string-match-p in-sub-str in-str))
98
+
99
+ (defun isearch-project--get-string-from-file (filePath )
100
+ " Return filePath's file content.
101
+ FILEPATH : file path."
102
+ (with-temp-buffer
103
+ (insert-file-contents filePath)
104
+ (buffer-string )))
105
+
95
106
(defun isearch-project--f-directories-ignore-directories (path &optional rec )
96
107
" Find all directories in PATH by ignored common directories with FN and REC."
97
108
(let ((dirs (f-directories path))
@@ -134,7 +145,6 @@ LST : List you want to modified."
134
145
(setq prepare-success t ))
135
146
prepare-success))
136
147
137
-
138
148
;;;### autoload
139
149
(defun isearch-project-forward-symbol-at-point ()
140
150
" Incremental search forward at current point in the project."
@@ -151,36 +161,19 @@ LST : List you want to modified."
151
161
(interactive )
152
162
(if (isearch-project-prepare)
153
163
(progn
154
- (isearch-project-add-advices)
164
+ (isearch-project-- add-advices)
155
165
(isearch-forward )
156
- (isearch-project-remove-advices))
166
+ (isearch-project-- remove-advices))
157
167
(error " Cannot isearch project without project directory defined " )))
158
168
159
-
160
- (defun isearch-project-add-advices ()
169
+ (defun isearch-project--add-advices ()
161
170
" Add all needed advices."
162
171
(advice-add 'isearch-repeat :after #'isearch-project-advice-isearch-repeat-after ))
163
172
164
- (defun isearch-project-remove-advices ()
173
+ (defun isearch-project-- remove-advices ()
165
174
" Remove all needed advices."
166
175
(advice-remove 'isearch-repeat #'isearch-project-advice-isearch-repeat-after ))
167
176
168
-
169
- (defun isearch-project-contain-string (in-sub-str in-str )
170
- " Check if a string is a substring of another string.
171
- Return true if contain, else return false.
172
- IN-SUB-STR : substring to see if contain in the IN-STR.
173
- IN-STR : string to check by the IN-SUB-STR."
174
- (string-match-p in-sub-str in-str))
175
-
176
- (defun isearch-project-get-string-from-file (filePath )
177
- " Return filePath's file content.
178
- FILEPATH : file path."
179
- (with-temp-buffer
180
- (insert-file-contents filePath)
181
- (buffer-string )))
182
-
183
-
184
177
(defun isearch-project-find-file-search (fn dt )
185
178
" Open a file and isearch.
186
179
If found, leave it. If not found, try find the next file.
@@ -190,18 +183,15 @@ DT : search direction."
190
183
(cl-case dt
191
184
('forward (goto-char (point-min )))
192
185
('backward (goto-char (point-max ))))
193
-
194
186
(isearch-search-string isearch-string nil t )
195
-
196
187
(let ((isearch-project--run-advice nil ))
197
188
(cl-case dt
198
189
('forward (isearch-repeat-forward ))
199
190
('backward (isearch-repeat-backward )))))
200
191
201
192
202
193
(defun isearch-project-advice-isearch-repeat-after (dt &optional cnt )
203
- " Advice when do either `isearch-repeat-backward' or `isearch-repeat-forward' \
204
- command.
194
+ " Advice for `isearch-repeat-backward' and `isearch-repeat-forward' command.
205
195
DT : search direction.
206
196
CNT : search count."
207
197
(when (and (not isearch-success) isearch-project--run-advice)
@@ -237,11 +227,11 @@ CNT : search count."
237
227
(setq next-fn (nth next-file-index isearch-project--files))
238
228
239
229
; ; Update buffer content.
240
- (setq buf-content (isearch-project-get-string-from-file next-fn))
230
+ (setq buf-content (isearch-project-- get-string-from-file next-fn))
241
231
242
232
(when (or
243
233
; ; Found match.
244
- (isearch-project-contain-string isearch-string buf-content)
234
+ (isearch-project-- contain-string isearch-string buf-content)
245
235
; ; Is the same as the starting file, this prevents infinite loop.
246
236
(= isearch-project--files-starting-index next-file-index))
247
237
(setq search-cnt (- search-cnt 1 ))
@@ -253,13 +243,12 @@ CNT : search count."
253
243
; ; Update current file index.
254
244
(setq isearch-project--files-current-index next-file-index))))
255
245
256
-
257
246
(defun isearch-project--isearch-yank-string (search-str )
258
247
" Isearch project allow error because we need to search through next file.
259
248
SEARCH-STR : Search string."
260
249
(ignore-errors (isearch-yank-string search-str)))
261
250
262
- (defun isearch-project-isearch-mode-hook ()
251
+ (defun isearch-project-- isearch-mode-hook ()
263
252
" Paste the current symbol when `isearch' enabled."
264
253
(cond ((and (use-region-p )
265
254
(memq this-command '(isearch-project-forward isearch-project-forward-symbol-at-point)))
@@ -272,9 +261,7 @@ SEARCH-STR : Search string."
272
261
(forward-char 1 ))
273
262
(forward-symbol -1 )
274
263
(isearch-project--isearch-yank-string isearch-project--thing-at-point)))))
275
-
276
- (add-hook 'isearch-mode-hook #'isearch-project-isearch-mode-hook )
277
-
264
+ (add-hook 'isearch-mode-hook #'isearch-project--isearch-mode-hook )
278
265
279
266
(provide 'isearch-project )
280
267
; ;; isearch-project.el ends here
0 commit comments