From 1db622ca9b156e52fb90d6fb05747a2ca0b8b0d9 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sun, 26 May 2019 23:40:20 +0900 Subject: [PATCH] Impl php-derivation-major-mode --- php.el | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/php.el b/php.el index 79d6d095..9f621535 100644 --- a/php.el +++ b/php.el @@ -29,6 +29,7 @@ ;;; Code: (require 'flymake) +(require 'php-project) ;;;###autoload (defgroup php nil @@ -248,15 +249,32 @@ Look at the `php-executable' variable instead of the constant \"php\" command." (goto-char (point-min)) (re-search-forward php-re-detect-html-tag nil t)))) -;;;###autoload -(defun php-mode-maybe () - "Select PHP mode or other major mode." - (let ((mode (assoc-default buffer-file-name php-template-mode-alist #'string-match-p))) +(defun php-derivation-major-mode () + "Return major mode for PHP file by file-name and its content." + (let ((mode (assoc-default buffer-file-name + php-template-mode-alist + #'string-match-p)) + type) + (when (and (null mode) buffer-file-name + php-project-php-file-as-template) + (setq type (php-project-get-file-html-template-type buffer-file-name)) + (cond + ((eq t type) (setq mode php-html-template-major-mode)) + ((eq 'auto type) + (when (php-buffer-has-html-tag) + (setq mode php-html-template-major-mode))))) (when (and mode (not (fboundp mode))) (if (string-match-p "\\.blade\\." buffer-file-name) - (warn "php-mode is NOT support blade template") + (warn "php-mode is NOT support blade template. %s" + "Please install `web-mode' package") (setq mode nil))) - (funcall (or mode php-default-major-mode)))) + (or mode php-default-major-mode))) + +;;;###autoload +(defun php-mode-maybe () + "Select PHP mode or other major mode." + (interactive) + (funcall (php-derivation-major-mode))) ;;;###autoload (defun php-current-class ()