Skip to content

Commit

Permalink
Impl php-derivation-major-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
zonuexe committed May 26, 2019
1 parent 9369cab commit 1db622c
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions php.el
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

;;; Code:
(require 'flymake)
(require 'php-project)

;;;###autoload
(defgroup php nil
Expand Down Expand Up @@ -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 ()
Expand Down

0 comments on commit 1db622c

Please sign in to comment.