Skip to content

Add php-mode-maybe for auto-mode-alist #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ Turning this on will open it whenever `php-mode' is loaded."
"Should detect presence of html tags."
:type 'boolean)

(defcustom php-template-integrate-blade #'web-mode
"Automatically use another MAJOR-MODE when open Laravel Blade template file."
:type '(choice (function-item "web-mode is popular major mode" #'web-mode)
(function :tag "Major mode for editing blade template")
(const :tag "Do not use other major mode"))
:link '(url-link :tag "web-mode" "http://web-mode.org/"))

(defsubst php-in-string-p ()
(nth 3 (syntax-ppss)))

Expand Down Expand Up @@ -1097,6 +1104,17 @@ PHP heredoc."

(define-obsolete-face-alias 'php-annotations-annotation-face 'php-doc-annotation-tag "1.19.0")

;;;###autoload
(defun php-mode-maybe ()
"Select PHP mode or other major mode."
(cond
((and php-template-integrate-blade
buffer-file-name (string-match-p "\\.blade\\.php\\'" buffer-file-name))
(if (fboundp php-template-integrate-blade)
(prog1 t
(funcall php-template-integrate-blade))
(warn "php-mode is NOT support blade template")))
(:else (php-mode))))

;;;###autoload
(define-derived-mode php-mode c-mode "PHP"
Expand Down Expand Up @@ -1732,7 +1750,7 @@ The output will appear in the buffer *PHP*."

;;;###autoload
(dolist (pattern '("\\.php[s345t]?\\'" "/\\.php_cs\\(\\.dist\\)?\\'" "\\.phtml\\'" "/Amkfile\\'" "\\.amk\\'"))
(add-to-list 'auto-mode-alist `(,pattern . php-mode) t))
(add-to-list 'auto-mode-alist `(,pattern . php-mode-maybe) t))

(provide 'php-mode)

Expand Down