diff --git a/lisp/php-mode.el b/lisp/php-mode.el index c3859614..cbd4c6a7 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -245,13 +245,12 @@ Turning this on will force PEAR rules on all PHP files." :tag "PHP Mode Force Pear" :type 'boolean) -(defcustom php-mode-warn-if-mumamo-off t - "Warn once per buffer if you try to indent a buffer without -mumamo-mode turned on. Detects if there are any HTML tags in the -buffer before warning, but this is is not very smart; e.g. if you -have any tags inside a PHP string, it will be fooled." - :tag "PHP Mode Warn If MuMaMo Off" +(defcustom php-mode-warn-if-html-template t + "When indenting HTML tags, warn and prompt to switch major mode for HTML template." + :tag "PHP Mode Warn If HTML Template" + :safe #'booleanp :type '(choice (const :tag "Warn" t) (const "Don't warn" nil))) +(make-obsolete-variable 'php-mode-warn-if-mumamo-off 'php-mode-warn-if-html-template "2.0.0") (defcustom php-mode-coding-style 'pear "Select default coding style to use with `php-mode'. @@ -811,93 +810,41 @@ See `php-beginning-of-defun'." (defvar php-warned-bad-indent nil) -;; Do it but tell it is not good if html tags in buffer. (defun php-check-html-for-indentation () - (let ((html-tag-re "^\\s-*") - (here (point))) - (goto-char (line-beginning-position)) - (if (or (when (boundp 'mumamo-multi-major-mode) mumamo-multi-major-mode) - ;; Fix-me: no idea how to check for mmm or multi-mode - (save-match-data - (not (or (re-search-forward html-tag-re (line-end-position) t) - (re-search-backward html-tag-re (line-beginning-position) t))))) - (prog1 t - (goto-char here)) - (goto-char here) - (setq php-warned-bad-indent t) - (let* ((known-multi-libs '(("mumamo" mumamo (lambda () (nxhtml-mumamo))) - ("mmm-mode" mmm-mode (lambda () (mmm-mode 1))) - ("multi-mode" multi-mode (lambda () (multi-mode 1))) - ("web-mode" web-mode (lambda () (web-mode))))) - (known-names (mapcar (lambda (lib) (car lib)) known-multi-libs)) - (available-multi-libs (delq nil - (mapcar - (lambda (lib) - (when (locate-library (car lib)) lib)) - known-multi-libs))) - (available-names (mapcar (lambda (lib) (car lib)) available-multi-libs)) - (base-msg - (concat - "Indentation fails badly with mixed HTML/PHP in the HTML part in -plain `php-mode'. To get indentation to work you must use an -Emacs library that supports 'multiple major modes' in a buffer. -Parts of the buffer will then be in `php-mode' and parts in for -example `html-mode'. Known such libraries are:\n\t" - (mapconcat #'identity known-names ", ") - "\n" - (if available-multi-libs - (concat - "You have these available in your `load-path':\n\t" - (mapconcat #'identity available-names ", ") - "\n\n" - "Do you want to turn any of those on? ") - "You do not have any of those in your `load-path'."))) - (is-using-multi - (catch 'is-using - (dolist (lib available-multi-libs) - (when (and (boundp (cadr lib)) - (symbol-value (cadr lib))) - (throw 'is-using t)))))) - (unless is-using-multi - (if available-multi-libs - (if (not (y-or-n-p base-msg)) - (message "Did not do indentation, but you can try again now if you want") - (let* ((name - (if (= 1 (length available-multi-libs)) - (car available-names) - ;; Minibuffer window is more than one line, fix that first: - (message "") - (completing-read "Choose multiple major mode support library: " - available-names nil t - (car available-names) - '(available-names . 1) - ))) - (mode (when name - (cl-caddr (assoc name available-multi-libs))))) - (when mode - ;; Minibuffer window is more than one line, fix that first: - (message "") - (load name) - (funcall mode)))) - (lwarn 'php-indent :warning base-msg))) - nil)))) + "Do it but tell it is not good if html tags in buffer." + (cond + ((php-in-poly-php-html-mode) nil) + ((not (php-buffer-has-html-tag)) t) + (php-warned-bad-indent nil) + ((fboundp php-html-template-major-mode) + (if (y-or-n-p (format "This file seems to contains HTML tag. Switch to %s? " + php-html-template-major-mode)) + (funcall php-html-template-major-mode) + (prog1 nil + (setq-local php-warned-bad-indent t)))) + (t ;; Suppress warnings in Emacs session + (setq php-warned-bad-indent t) + (lwarn 'php-mode + :warning "Indentation fails badly with mixed HTML/PHP in the HTML part in plain `php-mode'. +It is highly recommended to install a major mode that supports PHP and HTML templates, such as Web Mode. + +Set `php-html-template-major-mode' variable to use a mode other than `web-mode'. +Set `php-mode-warn-if-html-template' variable to nil to suppress the warning. +") + nil))) (defun php-cautious-indent-region (start end &optional quiet) "Carefully indent region START to END in contexts other than HTML templates. If the optional argument QUIET is non-nil then no syntactic errors are reported, even if `c-report-syntactic-errors' is non-nil." - (if (or (not php-mode-warn-if-mumamo-off) - (not (php-in-poly-php-html-mode)) - php-warned-bad-indent + (if (or (not php-mode-warn-if-html-template) (php-check-html-for-indentation)) (funcall 'c-indent-region start end quiet))) (defun php-cautious-indent-line () "Carefully indent lines in contexts other than HTML templates." - (if (or (not php-mode-warn-if-mumamo-off) - (not (php-in-poly-php-html-mode)) - php-warned-bad-indent + (if (or (not php-mode-warn-if-html-template) (php-check-html-for-indentation)) (let ((here (point)) doit)