Skip to content

Commit 4a38276

Browse files
committed
Org public/private macros.
1 parent 00de318 commit 4a38276

File tree

1 file changed

+23
-36
lines changed

1 file changed

+23
-36
lines changed

isearch-project.el

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,19 @@
3737
(require 'grep)
3838
(require 'isearch)
3939

40-
4140
(defgroup isearch-project nil
4241
"Incremental search through the whole project."
4342
:prefix "isearch-project-"
4443
:group 'isearch
4544
:link '(url-link :tag "Repository" "https://github.com/jcs090218/isearch-project"))
4645

47-
4846
(defcustom isearch-project-ignore-paths '(".vs/"
4947
".vscode/"
5048
"node_modules/")
5149
"List of path you want to ignore by Incremental searching in the project."
5250
:type 'list
5351
:group 'isearch-project)
5452

55-
5653
(defvar isearch-project--search-path ""
5754
"Record the current search path, so when next time it searhs would not need to research from the start.")
5855

@@ -92,6 +89,20 @@ LST : List you want to modified."
9289
(setcdr last (cddr last))
9390
lst)))
9491

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+
95106
(defun isearch-project--f-directories-ignore-directories (path &optional rec)
96107
"Find all directories in PATH by ignored common directories with FN and REC."
97108
(let ((dirs (f-directories path))
@@ -134,7 +145,6 @@ LST : List you want to modified."
134145
(setq prepare-success t))
135146
prepare-success))
136147

137-
138148
;;;###autoload
139149
(defun isearch-project-forward-symbol-at-point ()
140150
"Incremental search forward at current point in the project."
@@ -151,36 +161,19 @@ LST : List you want to modified."
151161
(interactive)
152162
(if (isearch-project-prepare)
153163
(progn
154-
(isearch-project-add-advices)
164+
(isearch-project--add-advices)
155165
(isearch-forward)
156-
(isearch-project-remove-advices))
166+
(isearch-project--remove-advices))
157167
(error "Cannot isearch project without project directory defined")))
158168

159-
160-
(defun isearch-project-add-advices ()
169+
(defun isearch-project--add-advices ()
161170
"Add all needed advices."
162171
(advice-add 'isearch-repeat :after #'isearch-project-advice-isearch-repeat-after))
163172

164-
(defun isearch-project-remove-advices ()
173+
(defun isearch-project--remove-advices ()
165174
"Remove all needed advices."
166175
(advice-remove 'isearch-repeat #'isearch-project-advice-isearch-repeat-after))
167176

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-
184177
(defun isearch-project-find-file-search (fn dt)
185178
"Open a file and isearch.
186179
If found, leave it. If not found, try find the next file.
@@ -190,18 +183,15 @@ DT : search direction."
190183
(cl-case dt
191184
('forward (goto-char (point-min)))
192185
('backward (goto-char (point-max))))
193-
194186
(isearch-search-string isearch-string nil t)
195-
196187
(let ((isearch-project--run-advice nil))
197188
(cl-case dt
198189
('forward (isearch-repeat-forward))
199190
('backward (isearch-repeat-backward)))))
200191

201192

202193
(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.
205195
DT : search direction.
206196
CNT : search count."
207197
(when (and (not isearch-success) isearch-project--run-advice)
@@ -237,11 +227,11 @@ CNT : search count."
237227
(setq next-fn (nth next-file-index isearch-project--files))
238228

239229
;; 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))
241231

242232
(when (or
243233
;; Found match.
244-
(isearch-project-contain-string isearch-string buf-content)
234+
(isearch-project--contain-string isearch-string buf-content)
245235
;; Is the same as the starting file, this prevents infinite loop.
246236
(= isearch-project--files-starting-index next-file-index))
247237
(setq search-cnt (- search-cnt 1))
@@ -253,13 +243,12 @@ CNT : search count."
253243
;; Update current file index.
254244
(setq isearch-project--files-current-index next-file-index))))
255245

256-
257246
(defun isearch-project--isearch-yank-string (search-str)
258247
"Isearch project allow error because we need to search through next file.
259248
SEARCH-STR : Search string."
260249
(ignore-errors (isearch-yank-string search-str)))
261250

262-
(defun isearch-project-isearch-mode-hook ()
251+
(defun isearch-project--isearch-mode-hook ()
263252
"Paste the current symbol when `isearch' enabled."
264253
(cond ((and (use-region-p)
265254
(memq this-command '(isearch-project-forward isearch-project-forward-symbol-at-point)))
@@ -272,9 +261,7 @@ SEARCH-STR : Search string."
272261
(forward-char 1))
273262
(forward-symbol -1)
274263
(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)
278265

279266
(provide 'isearch-project)
280267
;;; isearch-project.el ends here

0 commit comments

Comments
 (0)