@@ -245,13 +245,12 @@ Turning this on will force PEAR rules on all PHP files."
245
245
:tag " PHP Mode Force Pear"
246
246
:type 'boolean )
247
247
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
254
252
: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" )
255
254
256
255
(defcustom php-mode-coding-style 'pear
257
256
" Select default coding style to use with `php-mode' .
@@ -811,105 +810,46 @@ See `php-beginning-of-defun'."
811
810
812
811
(defvar php-warned-bad-indent nil )
813
812
814
- ; ; Do it but tell it is not good if html tags in buffer.
815
813
(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
+ ((not php-mode-warn-if-html-template) t )
817
+ ((php-in-poly-php-html-mode) nil )
818
+ ((not (php-buffer-has-html-tag)) t )
819
+ (php-warned-bad-indent nil )
820
+ ((fboundp php-html-template-major-mode)
821
+ (if (y-or-n-p (format " This file seems to contains HTML tag. Switch to %s ? "
822
+ php-html-template-major-mode))
823
+ (funcall php-html-template-major-mode)
824
+ (prog1 nil
825
+ (setq-local php-warned-bad-indent t ))))
826
+ (t ; ; Suppress warnings in Emacs session
827
+ (setq php-warned-bad-indent t )
828
+ (lwarn 'php-mode
829
+ :warning " Indentation fails badly with mixed HTML/PHP in the HTML part in plain `php-mode' .
830
+ It is highly recommended to install a major mode that supports PHP and HTML templates, such as Web Mode.
831
+
832
+ Set `php-html-template-major-mode' variable to use a mode other than `web-mode' .
833
+ Set `php-mode-warn-if-html-template' variable to nil to suppress the warning.
834
+ " )
835
+ nil )))
884
836
885
837
(defun php-cautious-indent-region (start end &optional quiet )
886
838
" Carefully indent region START to END in contexts other than HTML templates.
887
839
888
840
If the optional argument QUIET is non-nil then no syntactic errors are
889
841
reported, 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
893
- (php-check-html-for-indentation))
894
- (funcall 'c-indent-region start end quiet)))
842
+ (when (php-check-html-for-indentation)
843
+ (c-indent-region start end quiet)))
895
844
896
845
(defun php-cautious-indent-line ()
897
846
" 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
901
- (php-check-html-for-indentation))
902
- (let ((here (point ))
903
- doit)
904
- (move-beginning-of-line nil )
905
- ; ; Don't indent heredoc end mark
906
- (save-match-data
907
- (unless (and (looking-at " [a-zA-Z0-9_]+;\n " )
908
- (php-in-string-p))
909
- (setq doit t )))
910
- (goto-char here)
911
- (when doit
912
- (funcall 'c-indent-line )))))
847
+ (when (and (php-check-html-for-indentation)
848
+ (save-excursion
849
+ (beginning-of-line )
850
+ ; ; Don't indent heredoc end mark
851
+ (not (and (looking-at-p " [a-zA-Z0-9_]+;\n " ) (php-in-string-p)))))
852
+ (c-indent-line )))
913
853
914
854
(defun php-c-at-vsemi-p (&optional pos )
915
855
" Return T on HTML lines (including php tag) or PHP8 Attribute, otherwise NIL.
0 commit comments