Skip to content

Commit c52c625

Browse files
committed
Separate php-syntax-propertize-function and add # line comment
1 parent c61db49 commit c52c625

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

php-mode.el

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -982,18 +982,43 @@ this ^ lineup"
982982
(string-match "\\_<.+?\\_>" heredoc-start)
983983
(concat "^\\s-*\\(" (match-string 0 heredoc-start) "\\)\\W"))
984984

985+
(defvar php-syntax-propertize-functions
986+
'(php-syntax-propertize-heredoc
987+
php-syntax-propertize-quotes-in-comment
988+
php-syntax-propertize-hash-line-comment)
989+
"Syntax propertize functions for PHP script.")
990+
985991
(defun php-syntax-propertize-function (start end)
986992
"Apply propertize rules from START to END."
987-
(goto-char start)
993+
(dolist (propertizer php-syntax-propertize-functions)
994+
(goto-char start)
995+
(funcall propertizer start end)))
996+
997+
(defun php-syntax-propertize-heredoc (_start end)
998+
"Apply propertize Heredoc and Nowdoc from START to END."
988999
(while (and (< (point) end)
9891000
(re-search-forward php-heredoc-start-re end t))
990-
(php-heredoc-syntax))
991-
(goto-char start)
1001+
(php-heredoc-syntax)))
1002+
1003+
(defun php-syntax-propertize-quotes-in-comment (_start end)
1004+
"Apply propertize quotes (' and \") from START to END."
9921005
(while (re-search-forward "['\"]" end t)
9931006
(when (php-in-comment-p)
9941007
(c-put-char-property (match-beginning 0)
9951008
'syntax-table (string-to-syntax "_")))))
9961009

1010+
(defun php-syntax-propertize-hash-line-comment (_start end)
1011+
"Apply propertize # comment (without PHP8 Attributes) from START to END."
1012+
(unless php-mode-use-php7-syntax-table
1013+
(while (< (point) (min end (point-max)))
1014+
(let ((line-end (line-end-position)))
1015+
(when (and (search-forward "#" line-end t)
1016+
(not (php-in-string-or-comment-p))
1017+
(not (looking-at "[[]")))
1018+
(c-put-char-property (1- (point)) 'syntax-table (string-to-syntax "<"))
1019+
(c-put-char-property line-end 'syntax-table (string-to-syntax ">")))
1020+
(move-beginning-of-line 2)))))
1021+
9971022
(defun php-heredoc-syntax ()
9981023
"Mark the boundaries of searched heredoc."
9991024
(goto-char (match-beginning 0))

0 commit comments

Comments
 (0)