Skip to content

Commit 1d06c6e

Browse files
committed
Move php-project-get-root-dir and some variables into php-project.el
By dividing these functions into separate files rather than a single file, it improves interoperability with other modes and functions. In the future this file will be independent as a separate package.
1 parent 9ed89c8 commit 1d06c6e

File tree

2 files changed

+44
-38
lines changed

2 files changed

+44
-38
lines changed

php-mode.el

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
(require 'etags)
8484
(require 'speedbar)
8585
(require 'imenu)
86+
(require 'php-project nil t)
8687

8788
(require 'cl-lib)
8889
(require 'mode-local)
@@ -388,30 +389,8 @@ This variable can take one of the following symbol values:
388389
(message "PHP Mode %s of %s"
389390
php-mode-version-number php-mode-modified))
390391

391-
(defvar php-available-project-root-files
392-
'((projectile ".projectile")
393-
(composer "composer.json" "composer.lock")
394-
(git ".git")
395-
(mercurial ".hg")
396-
(subversion ".svn")
397-
;; NOTICE: This method does not detect the top level of .editorconfig
398-
;; However, we can integrate it by adding the editorconfig.el's API.
399-
;;(editorconfig . ".editorconfig")
400-
))
401-
402392
;;;###autoload
403-
(progn
404-
(defvar php-project-root 'auto
405-
"Method of searching for the top level directory.
406-
407-
`auto' (default)
408-
Try to search file in order of `php-available-project-root-files'.
409-
410-
SYMBOL
411-
Key of `php-available-project-root-files'.")
412-
(make-variable-buffer-local 'php-project-root)
413-
(put 'php-project-root 'safe-local-variable
414-
#'(lambda (v) (assq v php-available-project-root-files))))
393+
(define-obsolete-variable-alias 'php-available-project-root-files 'php-project-available-root-files "1.19.0")
415394

416395
(defvar php-mode-map
417396
(let ((map (make-sparse-keymap)))
@@ -1743,18 +1722,6 @@ The output will appear in the buffer *PHP*."
17431722
(when (re-search-backward re-pattern nil t)
17441723
(match-string-no-properties 1))))
17451724

1746-
;;;###autoload
1747-
(defun php-project-get-root-dir ()
1748-
"Return path to current PHP project."
1749-
(let ((detect-method (if (stringp php-project-root)
1750-
(list php-project-root)
1751-
(if (eq php-project-root 'auto)
1752-
(cl-loop for m in php-available-project-root-files
1753-
append (cdr m))
1754-
(cdr-safe (assq php-project-root php-available-project-root-files))))))
1755-
(cl-loop for m in detect-method
1756-
thereis (locate-dominating-file default-directory m))))
1757-
17581725
;;;###autoload
17591726
(defun php-current-class ()
17601727
"Insert current class name if cursor in class context."

php-project.el

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,58 @@
2525
;;; Commentary:
2626

2727
;; Define project specific functions and variables for PHP application.
28+
;;
29+
;; ## API
30+
;;
31+
;; ### `php-project-get-root-dir()'
32+
;;
33+
;; Return root directory of current buffer file. The root directory is
34+
;; determined by several marker file or directory.
35+
;;
2836

2937
;;; Code:
30-
3138

3239
;; Variables
33-
34-
40+
(defvar php-project-available-root-files
41+
'((projectile ".projectile")
42+
(composer "composer.json" "composer.lock")
43+
(git ".git")
44+
(mercurial ".hg")
45+
(subversion ".svn")
46+
;; NOTICE: This method does not detect the top level of .editorconfig
47+
;; However, we can integrate it by adding the editorconfig.el's API.
48+
;;(editorconfig . ".editorconfig")
49+
))
3550

3651
;; Buffer local variables
3752

53+
;;;###autoload
54+
(progn
55+
(defvar php-project-root 'auto
56+
"Method of searching for the top level directory.
57+
58+
`auto' (default)
59+
Try to search file in order of `php-project-available-root-files'.
60+
61+
SYMBOL
62+
Key of `php-project-available-root-files'.")
63+
(make-variable-buffer-local 'php-project-root)
64+
(put 'php-project-root 'safe-local-variable
65+
#'(lambda (v) (assq v php-project-available-root-files))))
3866

3967
;; Functions
4068

69+
;;;###autoload
70+
(defun php-project-get-root-dir ()
71+
"Return path to current PHP project."
72+
(let ((detect-method (if (stringp php-project-root)
73+
(list php-project-root)
74+
(if (eq php-project-root 'auto)
75+
(cl-loop for m in php-project-available-root-files
76+
append (cdr m))
77+
(cdr-safe (assq php-project-root php-project-available-root-files))))))
78+
(cl-loop for m in detect-method
79+
thereis (locate-dominating-file default-directory m))))
4180

4281
(provide 'php-project)
4382
;;; php-project.el ends here

0 commit comments

Comments
 (0)