Skip to content

Commit 211b5a8

Browse files
committed
Fix infinite loop on XHP in comments
`syntax-ppss` moves point to the position given, so ensure that we wrap calls with `save-excursion` when the position is specified. Fixes #31
1 parent 54f5482 commit 211b5a8

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

hack-mode.el

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
(defun hack--propertize-xhp ()
8080
"Put syntax properties on XHP blocks."
8181
(let* ((start-pos (match-beginning 1))
82-
(ppss (syntax-ppss start-pos))
82+
(ppss (save-excursion (syntax-ppss start-pos)))
8383
(in-comment (nth 4 ppss)))
8484
(unless in-comment
8585
(hack--forward-parse-xhp start-pos nil)
@@ -198,11 +198,14 @@ If we find one, move point to its end, and set match data."
198198
(save-excursion
199199
(while (and (not end-pos)
200200
(re-search-forward hack-xhp-start-regex limit t))
201-
;; Ignore XHP in comments.
202-
(unless (nth 4 (syntax-ppss (match-beginning 1)))
203-
(setq start-pos (match-beginning 1))
204-
(hack--forward-parse-xhp start-pos limit t)
205-
(setq end-pos (point)))))
201+
(let* ((ppss-start
202+
(save-excursion (syntax-ppss (match-beginning 1))))
203+
(in-comment (nth 4 ppss-start)))
204+
;; Ignore XHP in comments.
205+
(unless in-comment
206+
(setq start-pos (match-beginning 1))
207+
(hack--forward-parse-xhp start-pos limit t)
208+
(setq end-pos (point))))))
206209
(when end-pos
207210
(set-match-data (list start-pos end-pos))
208211
(goto-char end-pos))))

test/hack-unit-test.el

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,3 +862,9 @@ baz()"
862862
<
863863
"))
864864

865+
(ert-deftest hack-hang-on-xhp-in-comment ()
866+
"Regression test for font-lock hanging on XHP inside comments."
867+
(with-hack-buffer "/*
868+
<foo></foo>
869+
*/"))
870+

0 commit comments

Comments
 (0)