Skip to content

Commit b1b815f

Browse files
committed
feat: add variable to customize max search depth
1 parent 6f76b46 commit b1b815f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

add-node-modules-path.el

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,25 @@
3636
"Enable verbose output when non nil."
3737
:type 'boolean)
3838

39+
;;;###autoload
40+
(defcustom add-node-modules-max-depth 20
41+
"Max depth to look for node_modules."
42+
:type 'integer)
43+
3944
;;;###autoload
4045
(defun add-node-modules-path ()
4146
"Search the current buffer's parent directories for `node_modules/.bin`.
42-
Traverse the directory structure up, until reaching the user's home directory.
47+
Traverse the directory structure up, until reaching the user's home directory,
48+
or hitting add-node-modules-max-depth.
4349
Any path found is added to the `exec-path'."
4450
(interactive)
4551
(let* ((file (or (buffer-file-name) default-directory))
46-
(path (locate-dominating-file file "node_modules"))
4752
(home (expand-file-name "~"))
48-
(root (and path (expand-file-name path)))
53+
(iterations add-node-modules-max-depth)
54+
(root (directory-file-name (or (file-name-directory (buffer-file-name)) default-directory)))
4955
(roots '()))
50-
(while root
56+
(while (and root (> iterations 0))
57+
(setq iterations (1- iterations))
5158
(let ((bindir (expand-file-name "node_modules/.bin/" root)))
5259
(when (file-directory-p bindir)
5360
(add-to-list 'roots bindir)))

0 commit comments

Comments
 (0)