Skip to content

Commit 1747964

Browse files
committed
Separate php-syntax-propertize-function and add # line comment
1 parent 0a52b7e commit 1747964

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
@@ -985,18 +985,43 @@ this ^ lineup"
985985
(string-match "\\_<.+?\\_>" heredoc-start)
986986
(concat "^\\s-*\\(" (match-string 0 heredoc-start) "\\)\\W"))
987987

988+
(defvar php-syntax-propertize-functions
989+
'(php-syntax-propertize-heredoc
990+
php-syntax-propertize-quotes-in-comment
991+
php-syntax-propertize-hash-line-comment)
992+
"Syntax propertize functions for PHP script.")
993+
988994
(defun php-syntax-propertize-function (start end)
989995
"Apply propertize rules from START to END."
990-
(goto-char start)
996+
(dolist (propertizer php-syntax-propertize-functions)
997+
(goto-char start)
998+
(funcall propertizer start end)))
999+
1000+
(defun php-syntax-propertize-heredoc (_start end)
1001+
"Apply propertize Heredoc and Nowdoc from START to END."
9911002
(while (and (< (point) end)
9921003
(re-search-forward php-heredoc-start-re end t))
993-
(php-heredoc-syntax))
994-
(goto-char start)
1004+
(php-heredoc-syntax)))
1005+
1006+
(defun php-syntax-propertize-quotes-in-comment (_start end)
1007+
"Apply propertize quotes (' and \") from START to END."
9951008
(while (re-search-forward "['\"]" end t)
9961009
(when (php-in-comment-p)
9971010
(c-put-char-property (match-beginning 0)
9981011
'syntax-table (string-to-syntax "_")))))
9991012

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

0 commit comments

Comments
 (0)