@@ -245,13 +245,12 @@ Turning this on will force PEAR rules on all PHP files."
245245 :tag " PHP Mode Force Pear"
246246 :type 'boolean )
247247
248- (defcustom php-mode-warn-if-mumamo-off t
249- " Warn once per buffer if you try to indent a buffer without
250- mumamo-mode turned on. Detects if there are any HTML tags in the
251- buffer before warning, but this is is not very smart; e.g. if you
252- have any tags inside a PHP string, it will be fooled."
253- :tag " PHP Mode Warn If MuMaMo Off"
248+ (defcustom php-mode-warn-if-html-template t
249+ " When indenting HTML tags, warn and prompt to switch major mode for HTML template."
250+ :tag " PHP Mode Warn If HTML Template"
251+ :safe #'booleanp
254252 :type '(choice (const :tag " Warn" t ) (const " Don't warn" nil )))
253+ (make-obsolete-variable 'php-mode-warn-if-mumamo-off 'php-mode-warn-if-html-template " 2.0.0" )
255254
256255(defcustom php-mode-coding-style 'pear
257256 " Select default coding style to use with `php-mode' .
@@ -811,93 +810,41 @@ See `php-beginning-of-defun'."
811810
812811(defvar php-warned-bad-indent nil )
813812
814- ; ; Do it but tell it is not good if html tags in buffer.
815813(defun php-check-html-for-indentation ()
816- (let ((html-tag-re " ^\\ s-*</?\\ sw+.*?>" )
817- (here (point )))
818- (goto-char (line-beginning-position ))
819- (if (or (when (boundp 'mumamo-multi-major-mode ) mumamo-multi-major-mode)
820- ; ; Fix-me: no idea how to check for mmm or multi-mode
821- (save-match-data
822- (not (or (re-search-forward html-tag-re (line-end-position ) t )
823- (re-search-backward html-tag-re (line-beginning-position ) t )))))
824- (prog1 t
825- (goto-char here))
826- (goto-char here)
827- (setq php-warned-bad-indent t )
828- (let* ((known-multi-libs '((" mumamo" mumamo (lambda () (nxhtml-mumamo)))
829- (" mmm-mode" mmm-mode (lambda () (mmm-mode 1 )))
830- (" multi-mode" multi-mode (lambda () (multi-mode 1 )))
831- (" web-mode" web-mode (lambda () (web-mode)))))
832- (known-names (mapcar (lambda (lib ) (car lib)) known-multi-libs))
833- (available-multi-libs (delq nil
834- (mapcar
835- (lambda (lib )
836- (when (locate-library (car lib)) lib))
837- known-multi-libs)))
838- (available-names (mapcar (lambda (lib ) (car lib)) available-multi-libs))
839- (base-msg
840- (concat
841- " Indentation fails badly with mixed HTML/PHP in the HTML part in
842- plain `php-mode' . To get indentation to work you must use an
843- Emacs library that supports 'multiple major modes' in a buffer.
844- Parts of the buffer will then be in `php-mode' and parts in for
845- example `html-mode' . Known such libraries are:\n\t "
846- (mapconcat #'identity known-names " , " )
847- " \n "
848- (if available-multi-libs
849- (concat
850- " You have these available in your `load-path' :\n\t "
851- (mapconcat #'identity available-names " , " )
852- " \n\n "
853- " Do you want to turn any of those on? " )
854- " You do not have any of those in your `load-path' ." )))
855- (is-using-multi
856- (catch 'is-using
857- (dolist (lib available-multi-libs)
858- (when (and (boundp (cadr lib))
859- (symbol-value (cadr lib)))
860- (throw 'is-using t ))))))
861- (unless is-using-multi
862- (if available-multi-libs
863- (if (not (y-or-n-p base-msg))
864- (message " Did not do indentation, but you can try again now if you want " )
865- (let* ((name
866- (if (= 1 (length available-multi-libs))
867- (car available-names)
868- ; ; Minibuffer window is more than one line, fix that first:
869- (message " " )
870- (completing-read " Choose multiple major mode support library: "
871- available-names nil t
872- (car available-names)
873- '(available-names . 1 )
874- )))
875- (mode (when name
876- (cl-caddr (assoc name available-multi-libs)))))
877- (when mode
878- ; ; Minibuffer window is more than one line, fix that first:
879- (message " " )
880- (load name)
881- (funcall mode))))
882- (lwarn 'php-indent :warning base-msg)))
883- nil ))))
814+ " Do it but tell it is not good if html tags in buffer."
815+ (cond
816+ ((php-in-poly-php-html-mode) nil )
817+ ((not (php-buffer-has-html-tag)) t )
818+ (php-warned-bad-indent nil )
819+ ((fboundp php-html-template-major-mode)
820+ (if (y-or-n-p (format " This file seems to contains HTML tag. Switch to %s ? "
821+ php-html-template-major-mode))
822+ (funcall php-html-template-major-mode)
823+ (prog1 nil
824+ (setq-local php-warned-bad-indent t ))))
825+ (t ; ; Suppress warnings in Emacs session
826+ (setq php-warned-bad-indent t )
827+ (lwarn 'php-mode
828+ :warning " Indentation fails badly with mixed HTML/PHP in the HTML part in plain `php-mode' .
829+ It is highly recommended to install a major mode that supports PHP and HTML templates, such as Web Mode.
830+
831+ Set `php-html-template-major-mode' variable to use a mode other than `web-mode' .
832+ Set `php-mode-warn-if-html-template' variable to nil to suppress the warning.
833+ " )
834+ nil )))
884835
885836(defun php-cautious-indent-region (start end &optional quiet )
886837 " Carefully indent region START to END in contexts other than HTML templates.
887838
888839If the optional argument QUIET is non-nil then no syntactic errors are
889840reported, even if `c-report-syntactic-errors' is non-nil."
890- (if (or (not php-mode-warn-if-mumamo-off)
891- (not (php-in-poly-php-html-mode))
892- php-warned-bad-indent
841+ (if (or (not php-mode-warn-if-html-template)
893842 (php-check-html-for-indentation))
894843 (funcall 'c-indent-region start end quiet)))
895844
896845(defun php-cautious-indent-line ()
897846 " Carefully indent lines in contexts other than HTML templates."
898- (if (or (not php-mode-warn-if-mumamo-off)
899- (not (php-in-poly-php-html-mode))
900- php-warned-bad-indent
847+ (if (or (not php-mode-warn-if-html-template)
901848 (php-check-html-for-indentation))
902849 (let ((here (point ))
903850 doit)
0 commit comments