Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP8 Attributes as new statement without semicolon using vsemi mechanism #626

Merged
merged 3 commits into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -879,38 +879,34 @@ reported, even if `c-report-syntactic-errors' is non-nil."
(funcall 'c-indent-line)))))

(defun php-c-at-vsemi-p (&optional pos)
"Return t on html lines (including php region border), otherwise nil.
"Return T on HTML lines (including php tag) or PHP8 Attribute, otherwise NIL.
POS is a position on the line in question.

This is was done due to the problem reported here:

URL `https://answers.launchpad.net/nxhtml/+question/43320'"
(if (not php-template-compatibility)
nil
(setq pos (or pos (point)))
(let ((here (point))
ret)
(save-match-data
;; If this function could call c-beginning-of-statement-1, change php-c-vsemi-status-unknown-p.
(save-excursion
(if pos
(goto-char pos)
(beginning-of-line)
(setq ret (looking-at
(rx
(or (seq
bol
(0+ space)
"<"
(in "a-z\\?"))
(seq
(0+ not-newline)
(in "a-z\\?")
">"
(0+ space)
eol))))))
(goto-char here)
ret)))
(setq pos (point)))
(unless (php-in-string-or-comment-p)
(or
;; Detect PHP8 attribute: <<Attribute()>>
(when (and (< 2 pos) (< 2 (- pos (c-point 'bol))))
(backward-char 2)
(looking-at-p ">>\\s-*\\(?:<<\\|$\\)"))
;; Detect HTML/XML tag and PHP tag (<?php, <?=, ?>)
(when php-mode-template-compatibility
(beginning-of-line)
(looking-at-p
(eval-when-compile
(rx (or (: bol (0+ space) "<" (in "a-z\\?"))
(: (0+ not-newline) (in "a-z\\?") ">" (0+ space) eol))))))))))

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

(defun php-lineup-string-cont (langelem)
Expand Down
12 changes: 12 additions & 0 deletions tests/8.0/attribute/function.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

<<ExampleAttribute>>
function f1() { }

<<WithoutArgument>>
<<SingleArgument(0)>>
<<FewArguments('Hello', 'World')>>
function foo() {}

<<WithoutArgument>><<SingleArgument(0)>><<FewArguments('Hello', 'World')>>
function bar() {}