Skip to content

Commit 67954d1

Browse files
committed
Add php-mode-maybe
1 parent 5b0fe1b commit 67954d1

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
@@ -85,6 +85,17 @@ You can replace \"en\" with your ISO language code."
8585
"Suffix for inserted namespace."
8686
:group 'php
8787
:type 'string)
88+
89+
(defcustom php-template-mode-alist
90+
'(("\\.blade" . web-mode)
91+
("\\.phpt\\'" . phpt-mode)
92+
("\\.phtml\\'" . web-mode))
93+
"Automatically use another MAJOR-MODE when open template file."
94+
:group 'php
95+
:tag "PHP Template Mode Alist"
96+
:type '(alist :key-type regexp :value-type function)
97+
:link '(url-link :tag "web-mode" "http://web-mode.org/")
98+
:link '(url-link :tag "phpt-mode" "https://github.com/emacs-php/phpt-mode"))
8899

89100
;;; PHP Keywords
90101
(defconst php-magical-constants
@@ -199,6 +210,19 @@ Look at the `php-executable' variable instead of the constant \"php\" command."
199210
'flymake-php-init)))))
200211
(list php-executable (cdr init))))
201212

213+
(eval-when-compile
214+
(declare-function php-mode "php-mode"))
215+
216+
;;;###autoload
217+
(defun php-mode-maybe ()
218+
"Select PHP mode or other major mode."
219+
(let ((mode (assoc-default buffer-file-name php-template-mode-alist #'string-match-p)))
220+
(when (and mode (not (fboundp mode)))
221+
(if (string-match-p "\\.blade\\." buffer-file-name)
222+
(warn "php-mode is NOT support blade template")
223+
(setq mode #'php-mode)))
224+
(funcall (or mode #'php-mode))))
225+
202226
;;;###autoload
203227
(defun php-current-class ()
204228
"Insert current class name if cursor in class context."

0 commit comments

Comments
 (0)