From 18e94f443951def6d8a9fd461073292740cf2620 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Fri, 10 Mar 2017 00:43:52 +0900 Subject: [PATCH 1/3] Add php-mode-maybe for auto-mode-alist The new function `php-mode-maybe` is wrapper for auto-mode-alist that invokes another function that is not php-mode under certain conditions. One of them is the Bladetemplate. This file generally has .blade.php extension, but it can not be edited in php-mode. Fortunately web-mode supports Blade templates. When web-mode is not installed in Emacs, simply announce warn and notify the user that php-mode is not suitable for editing the blade file. --- php-mode.el | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/php-mode.el b/php-mode.el index e1b2597b..d5c29a54 100644 --- a/php-mode.el +++ b/php-mode.el @@ -161,6 +161,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))) @@ -1229,6 +1236,18 @@ After setting the stylevars run hooks according to STYLENAME (php-mode-debug--message "Thank you!") (pop-to-buffer (php-mode-debug--buffer 'top))) +;;;###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" "Major mode for editing PHP code. From 72b46c326cb418b82aae760893e5a2f2acde9550 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sun, 2 Jul 2017 21:41:38 +0900 Subject: [PATCH 2/3] Modify auto-mode-alist Use 'php-mode-maybe instead of 'php-mode. Invoke php-mode or the appropriate major mode when open the file. --- php-mode.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/php-mode.el b/php-mode.el index d5c29a54..d5d9165d 100644 --- a/php-mode.el +++ b/php-mode.el @@ -1874,8 +1874,7 @@ The output will appear in the buffer *PHP*." ".php_cs" ".php_cs.dist"))) string-end)) - 'php-mode) - t) + 'php-mode-maybe)) (provide 'php-mode) From 22e15d86f9a860f6426ad6bfbf4b5c8e85fd74db Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sun, 25 Mar 2018 20:54:04 +0900 Subject: [PATCH 3/3] Use php-template-mode-alist instead of php-template-integrate-blade --- php-mode.el | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/php-mode.el b/php-mode.el index d5d9165d..c171ebfa 100644 --- a/php-mode.el +++ b/php-mode.el @@ -161,11 +161,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")) +(defcustom php-template-mode-alist + '(("\\.blade\\." . web-mode) + ;; ("\\.phtml\\'" . web-mode) + ;; ("\\.tpl\\." . web-mode) + ) + "Automatically use another MAJOR-MODE when open template file." + :type 'alist :link '(url-link :tag "web-mode" "http://web-mode.org/")) (defsubst php-in-string-p () @@ -1239,14 +1241,12 @@ After setting the stylevars run hooks according to STYLENAME ;;;###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)))) + (let ((mode (assoc-default buffer-file-name php-template-mode-alist #'string-match-p))) + (when (and mode (not (fboundp mode))) + (cond + ((string-match-p "\\.blade\\." buffer-file-name) + (warn "php-mode is NOT support blade template")))) + (funcall (or mode #'php-mode)))) ;;;###autoload (define-derived-mode php-mode c-mode "PHP"