Skip to content

Commit d638cec

Browse files
authored
Merge pull request #591 from emacs-php/feature/php-project-etags-file
Add php-project-etags-file and php-project-apply-local-variables
2 parents d07208c + 9132f21 commit d638cec

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

php-mode.el

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ In that case set to `NIL'."
342342
:tag "PHP Mode Disable C Mode Hook"
343343
:type 'boolean)
344344

345+
(defcustom php-mode-enable-project-local-variable t
346+
"When set to `T', apply project local variable to buffer local variable."
347+
:group 'php-mode
348+
:tag "PHP Mode Enable Project Local Variable"
349+
:type 'boolean)
350+
345351
(defun php-mode-version ()
346352
"Display string describing the version of PHP Mode."
347353
(interactive)
@@ -1116,6 +1122,11 @@ After setting the stylevars run hooks according to STYLENAME
11161122
(php-set-style (symbol-name coding-style)))
11171123
(remove-hook 'hack-local-variables-hook #'php-mode-set-style-delay)))))
11181124

1125+
(defun php-mode-set-local-variable-delay ()
1126+
"Set local variable from php-project."
1127+
(php-project-apply-local-variables)
1128+
(remove-hook 'hack-local-variables-hook #'php-mode-set-local-variable-delay))
1129+
11191130
(defvar php-mode-syntax-table
11201131
(let ((table (make-syntax-table)))
11211132
(c-populate-syntax-table table)
@@ -1169,6 +1180,9 @@ After setting the stylevars run hooks according to STYLENAME
11691180
;; PHP vars are case-sensitive
11701181
(setq case-fold-search t)
11711182

1183+
(when php-mode-enable-project-local-variable
1184+
(add-hook 'hack-local-variables-hook #'php-mode-set-local-variable-delay t t))
1185+
11721186
;; When php-mode-enable-project-coding-style is set, it is delayed by hook.
11731187
;; Since it depends on the timing at which the file local variable is set.
11741188
;; File local variables are set after initialization of major mode except `run-hook' is complete.

php-project.el

Lines changed: 30 additions & 1 deletion
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")
@@ -104,6 +117,12 @@ STRING
104117
(put 'php-project-root 'safe-local-variable
105118
#'(lambda (v) (or (stringp v) (assq v php-project-available-root-files))))
106119

120+
(defvar-local php-project-etags-file nil)
121+
(put 'php-project-etags-file 'safe-local-variable
122+
#'(lambda (v) (or (functionp v)
123+
(eq v t)
124+
(php-project--eval-bootstrap-scripts v))))
125+
107126
(defvar-local php-project-bootstrap-scripts nil
108127
"List of path to bootstrap php script file.
109128
@@ -172,7 +191,6 @@ Typically it is `pear', `drupal', `wordpress', `symfony2' and `psr2'.")
172191
(put 'php-project-server-start 'safe-local-variable
173192
#'(lambda (v) (or (functionp v)
174193
(php-project--eval-bootstrap-scripts v)))))
175-
176194

177195
;; Functions
178196
(defun php-project--validate-php-file-as-template (val)
@@ -229,6 +247,17 @@ Typically it is `pear', `drupal', `wordpress', `symfony2' and `psr2'.")
229247
(t (prog1 nil
230248
(warn "php-project-php-file-as-template is unexpected format")))))
231249

250+
(defun php-project-apply-local-variables ()
251+
"Apply php-project variables to local variables."
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)))))
232261
;;;###autoload
233262
(defun php-project-get-bootstrap-scripts ()
234263
"Return list of bootstrap script."

0 commit comments

Comments
 (0)