Skip to content

Commit 9132f21

Browse files
committed
Impl project variable auto detection mechanism
1 parent 795466c commit 9132f21

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

php-project.el

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@
7272
;; Constants
7373
(defconst php-project-composer-autoloader "vendor/autoload.php")
7474

75+
;; Custom variables
76+
(defgroup php-project nil
77+
"Major mode for editing PHP code."
78+
:tag "PHP Project"
79+
:prefix "php-project-"
80+
:group 'php)
81+
82+
(defcustom php-project-auto-detect-etags-file nil
83+
"If `T', automatically detect etags file when file is opened."
84+
:tag "PHP Project Auto Detect Etags File"
85+
:group 'php-project
86+
:type 'boolean)
87+
7588
;; Variables
7689
(defvar php-project-available-root-files
7790
'((projectile ".projectile")
@@ -107,6 +120,7 @@ STRING
107120
(defvar-local php-project-etags-file nil)
108121
(put 'php-project-etags-file 'safe-local-variable
109122
#'(lambda (v) (or (functionp v)
123+
(eq v t)
110124
(php-project--eval-bootstrap-scripts v))))
111125

112126
(defvar-local php-project-bootstrap-scripts nil
@@ -235,9 +249,15 @@ Typically it is `pear', `drupal', `wordpress', `symfony2' and `psr2'.")
235249

236250
(defun php-project-apply-local-variables ()
237251
"Apply php-project variables to local variables."
238-
(when (and php-project-etags-file (null tags-file-name))
239-
(setq-local tags-file-name (php-project--eval-bootstrap-scripts php-project-etags-file))))
240-
252+
(when (null tags-file-name)
253+
(when (or (and php-project-auto-detect-etags-file
254+
(null php-project-etags-file))
255+
(eq php-project-etags-file t))
256+
(let ((tags-file (expand-file-name "TAGS" (php-project-get-root-dir))))
257+
(when (file-exists-p tags-file)
258+
(setq-local php-project-etags-file tags-file))))
259+
(when php-project-etags-file
260+
(setq-local tags-file-name (php-project--eval-bootstrap-scripts php-project-etags-file)))))
241261
;;;###autoload
242262
(defun php-project-get-bootstrap-scripts ()
243263
"Return list of bootstrap script."

0 commit comments

Comments
 (0)