Skip to content

Commit 6631cae

Browse files
committed
Add php-mode-maybe
1 parent 6a269f5 commit 6631cae

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

php.el

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ You can replace \"en\" with your ISO language code."
7878
"Suffix for inserted namespace."
7979
:group 'php
8080
:type 'string)
81+
82+
(defcustom php-template-mode-alist
83+
'(("\\.blade" . web-mode)
84+
("\\.phpt\\'" . phpt-mode)
85+
("\\.phtml\\'" . web-mode))
86+
"Automatically use another MAJOR-MODE when open template file."
87+
:group 'php
88+
:tag "PHP Template Mode Alist"
89+
:type '(alist :key-type regexp :value-type function)
90+
:link '(url-link :tag "web-mode" "http://web-mode.org/")
91+
:link '(url-link :tag "phpt-mode" "https://github.com/emacs-php/phpt-mode"))
8192

8293
;;; PHP Keywords
8394
(defconst php-magical-constants
@@ -187,6 +198,19 @@ Look at the `php-executable' variable instead of the constant \"php\" command."
187198
'flymake-php-init)))))
188199
(list php-executable (cdr init))))
189200

201+
(eval-when-compile
202+
(declare-function php-mode "php-mode"))
203+
204+
;;;###autoload
205+
(defun php-mode-maybe ()
206+
"Select PHP mode or other major mode."
207+
(let ((mode (assoc-default buffer-file-name php-template-mode-alist #'string-match-p)))
208+
(when (and mode (not (fboundp mode)))
209+
(if (string-match-p "\\.blade\\." buffer-file-name)
210+
(warn "php-mode is NOT support blade template")
211+
(setq mode #'php-mode)))
212+
(funcall (or mode #'php-mode))))
213+
190214
;;;###autoload
191215
(defun php-current-class ()
192216
"Insert current class name if cursor in class context."

0 commit comments

Comments
 (0)