Skip to content

Commit 96e1f30

Browse files
committedApr 12, 2018
Make php-project-root accept a string
This change helps users to identify project-specific directories. There is usually no risk of conflict between the file name of the marker and the directory name. In the future, it is possible to control the behavior when the directory name was not the parent directory of the buffer file.
1 parent 6de2923 commit 96e1f30

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed
 

‎php-project.el

+18-11
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,15 @@
9595
Try to search file in order of `php-project-available-root-files'.
9696
9797
SYMBOL
98-
Key of `php-project-available-root-files'.")
98+
Key of `php-project-available-root-files'.
99+
100+
STRING
101+
A file/directory name of top level marker.
102+
If the string is an actual directory path, it is set as the absolute path
103+
of the root directory, not the marker.")
99104
(make-variable-buffer-local 'php-project-root)
100105
(put 'php-project-root 'safe-local-variable
101-
#'(lambda (v) (assq v php-project-available-root-files))))
106+
#'(lambda (v) (or (stringp v) (assq v php-project-available-root-files)))))
102107

103108
;;;###autoload
104109
(progn
@@ -177,15 +182,17 @@ Typically it is `pear', `drupal', `wordpress', `symfony2' and `psr2'.")
177182
;;;###autoload
178183
(defun php-project-get-root-dir ()
179184
"Return path to current PHP project."
180-
(let ((detect-method
181-
(cond
182-
((stringp php-project-root) (list php-project-root))
183-
((eq php-project-root 'auto)
184-
(cl-loop for m in php-project-available-root-files
185-
append (cdr m)))
186-
(t (cdr-safe (assq php-project-root php-project-available-root-files))))))
187-
(cl-loop for m in detect-method
188-
thereis (locate-dominating-file default-directory m))))
185+
(if (and (stringp php-project-root) (file-directory-p php-project-root))
186+
php-project-root
187+
(let ((detect-method
188+
(cond
189+
((stringp php-project-root) (list php-project-root))
190+
((eq php-project-root 'auto)
191+
(cl-loop for m in php-project-available-root-files
192+
append (cdr m)))
193+
(t (cdr-safe (assq php-project-root php-project-available-root-files))))))
194+
(cl-loop for m in detect-method
195+
thereis (locate-dominating-file default-directory m)))))
189196

190197
(provide 'php-project)
191198
;;; php-project.el ends here

0 commit comments

Comments
 (0)
Please sign in to comment.