Skip to content

Commit

Permalink
Merge pull request #632 from emacs-php/feature/match-expr
Browse files Browse the repository at this point in the history
Support PHP 8 match expression
  • Loading branch information
zonuexe authored Jul 25, 2020
2 parents 04f2113 + 899fc4c commit 4369c21
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ PHP does not have an \"enum\"-like keyword."
(c-lang-defconst c-lambda-kwds
php '("function" "use"))

(c-lang-defconst c-inexpr-block-kwds
php '("match"))

(c-lang-defconst c-other-block-decl-kwds
php '("namespace"))

Expand Down Expand Up @@ -643,6 +646,23 @@ but only if the setting is enabled"
(beginning-of-line)
(if (looking-at-p "\\s-*->") '+ nil))))

(defun php-c-looking-at-or-maybe-in-bracelist (&optional containing-sexp lim)
"Replace `c-looking-at-or-maybe-in-bracelist'.
CONTAINING-SEXP is the position of the brace/paren/bracket enclosing
POINT, or nil if there is no such position, or we do not know it. LIM is
a backward search limit."
(cond
((looking-at-p "{")
(save-excursion
(c-backward-token-2 2 t lim)
;; PHP 8.0 match expression
;; echo match ($var) |{
;; ↑ matches ↑ initial position
(when (looking-at-p (eval-when-compile (rx symbol-start "match" symbol-end)))
(cons (point) t))))
(t nil)))

(c-add-style
"php"
`((c-basic-offset . 4)
Expand Down Expand Up @@ -1186,6 +1206,10 @@ After setting the stylevars run hooks according to STYLENAME
(setq-local add-log-current-defun-function nil)
(setq-local add-log-current-defun-header-regexp php-beginning-of-defun-regexp)

(when (fboundp #'c-looking-at-or-maybe-in-bracelist)
(advice-add #'c-looking-at-or-maybe-in-bracelist
:override 'php-c-looking-at-or-maybe-in-bracelist))

(when (>= emacs-major-version 25)
(with-silent-modifications
(save-excursion
Expand Down

0 comments on commit 4369c21

Please sign in to comment.