|
38 | 38 | ;;;###autoload |
39 | 39 | (defun add-node-modules-path () |
40 | 40 | "Search the current buffer's parent directories for `node_modules/.bin`. |
41 | | -If it's found, then add it to the `exec-path'." |
| 41 | +Traverse the directory structure up, until reaching the user's home directory. |
| 42 | +Any path found is added to the `exec-path'." |
42 | 43 | (interactive) |
43 | | - (let* ((root (locate-dominating-file |
44 | | - (or (buffer-file-name) default-directory) |
45 | | - "node_modules")) |
46 | | - (path (and root |
47 | | - (expand-file-name "node_modules/.bin/" root)))) |
48 | | - (if root |
| 44 | + (let* ((file (or (buffer-file-name) default-directory)) |
| 45 | + (home (expand-file-name "~")) |
| 46 | + (root (expand-file-name (locate-dominating-file file "node_modules"))) |
| 47 | + (roots '())) |
| 48 | + (while (and root (not (string= root home))) |
| 49 | + (let ((bindir (expand-file-name "node_modules/.bin/" root))) |
| 50 | + (when (file-directory-p bindir) |
| 51 | + (add-to-list 'roots bindir))) |
| 52 | + (setq root (directory-file-name (file-name-directory root)))) |
| 53 | + (if roots |
49 | 54 | (progn |
50 | 55 | (make-local-variable 'exec-path) |
51 | | - (add-to-list 'exec-path path) |
52 | | - (when add-node-modules-path-debug |
53 | | - (message (concat "added " path " to exec-path")))) |
| 56 | + (while roots |
| 57 | + (add-to-list 'exec-path (car roots)) |
| 58 | + (when add-node-modules-path-debug |
| 59 | + (message (concat "added " (car roots) " to exec-path"))) |
| 60 | + (setq roots (cdr roots)))) |
54 | 61 | (when add-node-modules-path-debug |
55 | | - (message (concat "node_modules not found in " root)))))) |
| 62 | + (message (concat "node_modules/.bin not found for " file)))))) |
56 | 63 |
|
57 | 64 | (provide 'add-node-modules-path) |
58 | 65 |
|
|
0 commit comments