Skip to content

Commit f40e5eb

Browse files
committed
Org src once.
1 parent a0d7119 commit f40e5eb

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

isearch-project.el

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
;; Description: Incremental search through the whole project.
88
;; Keyword: convenience, search
99
;; Version: 0.2.3
10-
;; Package-Requires: ((emacs "26.1") (cl-lib "0.6") (f "0.20.0"))
10+
;; Package-Requires: ((emacs "26.1") (f "0.20.0"))
1111
;; URL: https://github.com/jcs090218/isearch-project
1212

1313
;; This file is NOT part of GNU Emacs.
@@ -71,6 +71,7 @@
7171
(defvar isearch-project--thing-at-point ""
7272
"Record down the symbol while executing `isearch-project-forward-symbol-at-point' command.")
7373

74+
;;; Util
7475

7576
(defun isearch-project--flatten-list (l)
7677
"Flatten the multiple dimensional array, L to one dimensonal array.
@@ -81,36 +82,29 @@ For instance,
8182
(t (loop for a in l appending (isearch-project--flatten-list a)))))
8283

8384
(defun isearch-project--is-contain-list-string (in-list in-str)
84-
"Check if a string contain in any string in the string list.
85-
IN-LIST : list of string use to check if IN-STR in contain one of
86-
the string.
87-
IN-STR : string using to check if is contain one of the IN-LIST."
85+
"Check if IN-STR contain in any string in the IN-LIST."
8886
(cl-some #'(lambda (lb-sub-str) (string-match-p (regexp-quote lb-sub-str) in-str)) in-list))
8987

90-
(defun isearch-project--remove-nth-element (n lst)
91-
"Remove nth element from the list.
92-
N : nth element you want to remove from the list.
93-
LST : List you want to modified."
94-
(if (zerop n)
88+
(defun isearch-project--remove-nth-element (nth lst)
89+
"Remove NTH element from the LST and return the list."
90+
(if (zerop nth)
9591
(cdr lst)
96-
(let ((last (nthcdr (1- n) lst)))
92+
(let ((last (nthcdr (1- nth) lst)))
9793
(setcdr last (cddr last))
9894
lst)))
9995

10096
(defun isearch-project--contain-string (in-sub-str in-str)
101-
"Check if a string is a substring of another string.
102-
Return true if contain, else return false.
103-
IN-SUB-STR : substring to see if contain in the IN-STR.
104-
IN-STR : string to check by the IN-SUB-STR."
97+
"Check if the IN-SUB-STR is a string in IN-STR."
10598
(string-match-p in-sub-str in-str))
10699

107-
(defun isearch-project--get-string-from-file (filePath)
108-
"Return filePath's file content.
109-
FILEPATH : file path."
100+
(defun isearch-project--get-string-from-file (path)
101+
"Return PATH file content."
110102
(with-temp-buffer
111-
(insert-file-contents filePath)
103+
(insert-file-contents path)
112104
(buffer-string)))
113105

106+
;;; Core
107+
114108
(defun isearch-project--f-directories-ignore-directories (path &optional rec)
115109
"Find all directories in PATH by ignored common directories with FN and REC."
116110
(let ((dirs (f-directories path))
@@ -139,7 +133,7 @@ FILEPATH : file path."
139133
(push (f-files dir fn) files))
140134
(isearch-project--flatten-list (reverse files))))
141135

142-
(defun isearch-project-prepare ()
136+
(defun isearch-project--prepare ()
143137
"Incremental search preparation."
144138
(let ((prepare-success nil))
145139
(setq isearch-project--project-dir (cdr (project-current)))
@@ -167,7 +161,7 @@ FILEPATH : file path."
167161
(defun isearch-project-forward ()
168162
"Incremental search forward in the project."
169163
(interactive)
170-
(if (isearch-project-prepare)
164+
(if (isearch-project--prepare)
171165
(progn
172166
(isearch-project--add-advices)
173167
(isearch-forward)
@@ -176,13 +170,13 @@ FILEPATH : file path."
176170

177171
(defun isearch-project--add-advices ()
178172
"Add all needed advices."
179-
(advice-add 'isearch-repeat :after #'isearch-project-advice-isearch-repeat-after))
173+
(advice-add 'isearch-repeat :after #'isearch-project--advice-isearch-repeat-after))
180174

181175
(defun isearch-project--remove-advices ()
182176
"Remove all needed advices."
183-
(advice-remove 'isearch-repeat #'isearch-project-advice-isearch-repeat-after))
177+
(advice-remove 'isearch-repeat #'isearch-project--advice-isearch-repeat-after))
184178

185-
(defun isearch-project-find-file-search (fn dt)
179+
(defun isearch-project--find-file-search (fn dt)
186180
"Open a file and isearch.
187181
If found, leave it. If not found, try find the next file.
188182
FN : file to search.
@@ -197,8 +191,7 @@ DT : search direction."
197191
('forward (isearch-repeat-forward))
198192
('backward (isearch-repeat-backward)))))
199193

200-
201-
(defun isearch-project-advice-isearch-repeat-after (dt &optional cnt)
194+
(defun isearch-project--advice-isearch-repeat-after (dt &optional cnt)
202195
"Advice for `isearch-repeat-backward' and `isearch-repeat-forward' command.
203196
DT : search direction.
204197
CNT : search count."
@@ -246,7 +239,7 @@ CNT : search count."
246239
(when (<= search-cnt 0) (setq break-it t)))))
247240

248241
;; Open the file.
249-
(isearch-project-find-file-search next-fn dt)
242+
(isearch-project--find-file-search next-fn dt)
250243

251244
;; Update current file index.
252245
(setq isearch-project--files-current-index next-file-index))))
@@ -269,6 +262,7 @@ SEARCH-STR : Search string."
269262
(forward-char 1))
270263
(forward-symbol -1)
271264
(isearch-project--isearch-yank-string isearch-project--thing-at-point)))))
265+
272266
(add-hook 'isearch-mode-hook #'isearch-project--isearch-mode-hook)
273267

274268
(provide 'isearch-project)

0 commit comments

Comments
 (0)