|
87 | 87 |
|
88 | 88 | (require 'cl-lib) |
89 | 89 | (require 'mode-local) |
| 90 | +(require 'php-project) |
90 | 91 |
|
91 | 92 | (eval-when-compile |
92 | 93 | (require 'regexp-opt) |
@@ -374,14 +375,15 @@ This variable can take one of the following symbol values: |
374 | 375 | (const :tag "WordPress" wordpress) |
375 | 376 | (const :tag "Symfony2" symfony2) |
376 | 377 | (const :tag "PSR-2" psr2)) |
377 | | - :set 'php-mode-custom-coding-style-set |
378 | 378 | :initialize 'custom-initialize-default) |
379 | 379 |
|
380 | | -(defun php-mode-custom-coding-style-set (sym value) |
381 | | - (when (eq major-mode 'php-mode) |
382 | | - (set sym value) |
383 | | - (set-default sym value) |
384 | | - (php-set-style (symbol-name value)))) |
| 380 | + |
| 381 | +(defcustom php-mode-enable-project-coding-style t |
| 382 | + "When set to true override php-mode-coding-style by php-project-coding-style. |
| 383 | +
|
| 384 | +If you want to suppress styles from being overwritten by directory / file |
| 385 | +local variables, set NIL." |
| 386 | + :type 'boolean) |
385 | 387 |
|
386 | 388 | (defun php-mode-version () |
387 | 389 | "Display string describing the version of PHP Mode." |
@@ -1124,6 +1126,13 @@ After setting the stylevars run hooks according to STYLENAME |
1124 | 1126 |
|
1125 | 1127 | (put 'php-set-style 'interactive-form (interactive-form 'c-set-style)) |
1126 | 1128 |
|
| 1129 | +(defun php-mode-set-style-delay () |
| 1130 | + "Set the current `php-mode' buffer to use the style by custom or local variables." |
| 1131 | + (let ((coding-style (or (and (boundp 'php-project-coding-style) php-project-coding-style) |
| 1132 | + php-mode-coding-style))) |
| 1133 | + (prog1 (php-set-style (symbol-name coding-style)) |
| 1134 | + (remove-hook 'hack-local-variables-hook #'php-mode-set-style-delay)))) |
| 1135 | + |
1127 | 1136 | (defun php-mode-debug () |
1128 | 1137 | "Display informations useful for debugging PHP Mode." |
1129 | 1138 | (interactive) |
@@ -1179,7 +1188,12 @@ After setting the stylevars run hooks according to STYLENAME |
1179 | 1188 | ;; PHP vars are case-sensitive |
1180 | 1189 | (setq case-fold-search t) |
1181 | 1190 |
|
1182 | | - (php-set-style (symbol-name php-mode-coding-style)) |
| 1191 | + ;; When php-mode-enable-project-coding-style is set, it is delayed by hook. |
| 1192 | + ;; Since it depends on the timing at which the file local variable is set. |
| 1193 | + ;; File local variables are set after initialization of major mode except `run-hook' is complete. |
| 1194 | + (if php-mode-enable-project-coding-style |
| 1195 | + (add-hook 'hack-local-variables-hook #'php-mode-set-style-delay t t) |
| 1196 | + (php-set-style (symbol-name php-mode-coding-style))) |
1183 | 1197 |
|
1184 | 1198 | (when (or php-mode-force-pear |
1185 | 1199 | (and (stringp buffer-file-name) |
|
0 commit comments