Skip to content

Commit acadfa8

Browse files
authored
Merge pull request #673 from emacs-php/optimize/font-lock-string-interpolation
Optimize php-mode--string-interpolated-variable-font-lock-find
2 parents 0a94905 + a3bf6dc commit acadfa8

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

.github/workflows/test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
- "26.2"
2020
- "26.3"
2121
- "27.1"
22+
- "27.2"
2223
- snapshot
2324
include:
2425
- emacs_version: snapshot

lisp/php-mode.el

+9-14
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,9 @@ for \\[find-tag] (which see)."
14421442

14431443
;; Logical operators (and, or, &&, ...)
14441444
;; Not operator (!) is defined in "before cc-mode" section above.
1445-
("\\(&&\\|||\\)" 1 'php-logical-op)))
1445+
("\\(&&\\|||\\)" 1 'php-logical-op)
1446+
;; string interpolation ("$var, ${var}, {$var}")
1447+
(php-mode--string-interpolated-variable-font-lock-find 0 nil)))
14461448
"Detailed highlighting for PHP Mode.")
14471449

14481450
(defvar php-font-lock-keywords php-font-lock-keywords-3
@@ -1474,22 +1476,15 @@ The output will appear in the buffer *PHP*."
14741476
(defconst php-string-interpolated-variable-regexp
14751477
"{\\$[^}\n\\\\]*\\(?:\\\\.[^}\n\\\\]*\\)*}\\|\\${\\sw+}\\|\\$\\sw+")
14761478

1477-
(defun php-string-intepolated-variable-font-lock-find (limit)
1478-
(while (re-search-forward php-string-interpolated-variable-regexp limit t)
1479-
(let ((quoted-stuff (nth 3 (syntax-ppss))))
1479+
(defun php-mode--string-interpolated-variable-font-lock-find (limit)
1480+
"Apply text-property to LIMIT for string interpolation by font-lock."
1481+
(let (quoted-stuff)
1482+
(while (re-search-forward php-string-interpolated-variable-regexp limit t)
1483+
(setq quoted-stuff (php-in-string-p))
14801484
(when (or (eq ?\" quoted-stuff) (eq ?` quoted-stuff))
1481-
(put-text-property (match-beginning 0) (match-end 0)
1482-
'face 'php-variable-name))))
1485+
(put-text-property (match-beginning 0) (match-end 0) 'face 'php-variable-name))))
14831486
nil)
1484-
1485-
(eval-after-load 'php-mode
1486-
'(progn
1487-
(font-lock-add-keywords
1488-
'php-mode
1489-
`((php-string-intepolated-variable-font-lock-find))
1490-
'append)))
14911487

1492-
14931488
;;; Correct the behavior of `delete-indentation' by modifying the
14941489
;;; logic of `fixup-whitespace'.
14951490
(defun php-mode--fixup-whitespace-after ()

0 commit comments

Comments
 (0)