Skip to content

Commit df00855

Browse files
authored
Merge pull request #626 from emacs-php/feature/php8-attr-indentation
PHP8 Attributes as new statement without semicolon using vsemi mechanism
2 parents 39f4306 + e7ae81f commit df00855

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

php-mode.el

+20-24
Original file line numberDiff line numberDiff line change
@@ -879,38 +879,34 @@ reported, even if `c-report-syntactic-errors' is non-nil."
879879
(funcall 'c-indent-line)))))
880880

881881
(defun php-c-at-vsemi-p (&optional pos)
882-
"Return t on html lines (including php region border), otherwise nil.
882+
"Return T on HTML lines (including php tag) or PHP8 Attribute, otherwise NIL.
883883
POS is a position on the line in question.
884884
885885
This is was done due to the problem reported here:
886886
887887
URL `https://answers.launchpad.net/nxhtml/+question/43320'"
888-
(if (not php-template-compatibility)
889-
nil
890-
(setq pos (or pos (point)))
891-
(let ((here (point))
892-
ret)
893-
(save-match-data
888+
;; If this function could call c-beginning-of-statement-1, change php-c-vsemi-status-unknown-p.
889+
(save-excursion
890+
(if pos
894891
(goto-char pos)
895-
(beginning-of-line)
896-
(setq ret (looking-at
897-
(rx
898-
(or (seq
899-
bol
900-
(0+ space)
901-
"<"
902-
(in "a-z\\?"))
903-
(seq
904-
(0+ not-newline)
905-
(in "a-z\\?")
906-
">"
907-
(0+ space)
908-
eol))))))
909-
(goto-char here)
910-
ret)))
892+
(setq pos (point)))
893+
(unless (php-in-string-or-comment-p)
894+
(or
895+
;; Detect PHP8 attribute: <<Attribute()>>
896+
(when (and (< 2 pos) (< 2 (- pos (c-point 'bol))))
897+
(backward-char 2)
898+
(looking-at-p ">>\\s-*\\(?:<<\\|$\\)"))
899+
;; Detect HTML/XML tag and PHP tag (<?php, <?=, ?>)
900+
(when php-mode-template-compatibility
901+
(beginning-of-line)
902+
(looking-at-p
903+
(eval-when-compile
904+
(rx (or (: bol (0+ space) "<" (in "a-z\\?"))
905+
(: (0+ not-newline) (in "a-z\\?") ">" (0+ space) eol))))))))))
911906

912907
(defun php-c-vsemi-status-unknown-p ()
913-
"Always return NIL. See `php-c-at-vsemi-p'."
908+
"Always return NIL. See `c-vsemi-status-unknown-p'."
909+
;; Current implementation of php-c-at-vsemi-p never calls c-beginning-of-statement-1
914910
nil)
915911

916912
(defun php-lineup-string-cont (langelem)

tests/8.0/attribute/function.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
<<ExampleAttribute>>
4+
function f1() { }
5+
6+
<<WithoutArgument>>
7+
<<SingleArgument(0)>>
8+
<<FewArguments('Hello', 'World')>>
9+
function foo() {}
10+
11+
<<WithoutArgument>><<SingleArgument(0)>><<FewArguments('Hello', 'World')>>
12+
function bar() {}

0 commit comments

Comments
 (0)