Skip to content

Commit 1db622c

Browse files
committed
Impl php-derivation-major-mode
1 parent 9369cab commit 1db622c

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

php.el

+24-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
;;; Code:
3131
(require 'flymake)
32+
(require 'php-project)
3233

3334
;;;###autoload
3435
(defgroup php nil
@@ -248,15 +249,32 @@ Look at the `php-executable' variable instead of the constant \"php\" command."
248249
(goto-char (point-min))
249250
(re-search-forward php-re-detect-html-tag nil t))))
250251

251-
;;;###autoload
252-
(defun php-mode-maybe ()
253-
"Select PHP mode or other major mode."
254-
(let ((mode (assoc-default buffer-file-name php-template-mode-alist #'string-match-p)))
252+
(defun php-derivation-major-mode ()
253+
"Return major mode for PHP file by file-name and its content."
254+
(let ((mode (assoc-default buffer-file-name
255+
php-template-mode-alist
256+
#'string-match-p))
257+
type)
258+
(when (and (null mode) buffer-file-name
259+
php-project-php-file-as-template)
260+
(setq type (php-project-get-file-html-template-type buffer-file-name))
261+
(cond
262+
((eq t type) (setq mode php-html-template-major-mode))
263+
((eq 'auto type)
264+
(when (php-buffer-has-html-tag)
265+
(setq mode php-html-template-major-mode)))))
255266
(when (and mode (not (fboundp mode)))
256267
(if (string-match-p "\\.blade\\." buffer-file-name)
257-
(warn "php-mode is NOT support blade template")
268+
(warn "php-mode is NOT support blade template. %s"
269+
"Please install `web-mode' package")
258270
(setq mode nil)))
259-
(funcall (or mode php-default-major-mode))))
271+
(or mode php-default-major-mode)))
272+
273+
;;;###autoload
274+
(defun php-mode-maybe ()
275+
"Select PHP mode or other major mode."
276+
(interactive)
277+
(funcall (php-derivation-major-mode)))
260278

261279
;;;###autoload
262280
(defun php-current-class ()

0 commit comments

Comments
 (0)