Skip to content

Commit 3df45ee

Browse files
committed
Set style by php-project-coding-style instead of custom variable.
Try to set it immediately, the local variable has not been set yet. I use hook to delay processing to avoid this problem.
1 parent 9911d8c commit 3df45ee

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

php-mode.el

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787

8888
(require 'cl-lib)
8989
(require 'mode-local)
90+
(require 'php-project)
9091

9192
(eval-when-compile
9293
(require 'regexp-opt)
@@ -1131,6 +1132,13 @@ After setting the stylevars run hooks according to STYLENAME
11311132

11321133
(put 'php-set-style 'interactive-form (interactive-form 'c-set-style))
11331134

1135+
(defun php-mode-set-style-delay ()
1136+
"Set the current `php-mode' buffer to use the style by custom or local variables."
1137+
(let ((coding-style (or (and (boundp 'php-project-coding-style) php-project-coding-style)
1138+
php-mode-coding-style)))
1139+
(prog1 (php-set-style (symbol-name coding-style))
1140+
(remove-hook 'hack-local-variables-hook #'php-mode-set-style-delay))))
1141+
11341142
(defun php-mode-debug ()
11351143
"Display informations useful for debugging PHP Mode."
11361144
(interactive)
@@ -1186,7 +1194,12 @@ After setting the stylevars run hooks according to STYLENAME
11861194
;; PHP vars are case-sensitive
11871195
(setq case-fold-search t)
11881196

1189-
(php-set-style (symbol-name php-mode-coding-style))
1197+
;; When php-mode-enable-project-coding-style is set, it is delayed by hook.
1198+
;; Since it depends on the timing at which the file local variable is set.
1199+
;; File local variables are set after initialization of major mode except `run-hook' is complete.
1200+
(if php-mode-enable-project-coding-style
1201+
(add-hook 'hack-local-variables-hook #'php-mode-set-style-delay t t)
1202+
(php-set-style (symbol-name php-mode-coding-style)))
11901203

11911204
(when (or php-mode-force-pear
11921205
(and (stringp buffer-file-name)

0 commit comments

Comments
 (0)