|
29 | 29 |
|
30 | 30 | ;;; Code:
|
31 | 31 | (require 'flymake)
|
| 32 | +(require 'php-project) |
32 | 33 |
|
33 | 34 | ;;;###autoload
|
34 | 35 | (defgroup php nil
|
@@ -248,15 +249,32 @@ Look at the `php-executable' variable instead of the constant \"php\" command."
|
248 | 249 | (goto-char (point-min))
|
249 | 250 | (re-search-forward php-re-detect-html-tag nil t))))
|
250 | 251 |
|
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))))) |
255 | 266 | (when (and mode (not (fboundp mode)))
|
256 | 267 | (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") |
258 | 270 | (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))) |
260 | 278 |
|
261 | 279 | ;;;###autoload
|
262 | 280 | (defun php-current-class ()
|
|
0 commit comments