Skip to content

Commit f6c36a2

Browse files
committed
Don't assume that XHP tags have names
First steps towards resolving #31.
1 parent c8be2fe commit f6c36a2

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

hack-mode.el

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,11 @@ If PROPERTIZE-TAGS is non-nil, apply `hack-xhp-tag' to tag names."
476476
(when close-p
477477
(forward-char 1))
478478
;; Get the name of the current tag.
479-
(re-search-forward
480-
(rx (+ (or (syntax word) (syntax symbol) ":" "-"))))
479+
(unless
480+
(re-search-forward
481+
(rx (+ (or (syntax word) (syntax symbol) ":" "-"))) nil t)
482+
;; Incomplete XHP tag, e.g. the user has just written "<".
483+
(throw 'done t))
481484
(setq tag-name (match-string 0))
482485
(setq tag-name-start (match-beginning 0))
483486
(setq tag-name-end (match-end 0))

test/hack-unit-test.el

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,3 +886,10 @@ baz()"
886886
(with-hack-buffer "// <foo>"
887887
(search-forward "f")
888888
(should (eq (face-at-point) 'font-lock-comment-face))))
889+
890+
(ert-deftest hack-xhp-unfinished ()
891+
"Don't crash if the user hasn't finished writing their XHP tag."
892+
(with-hack-buffer "
893+
<
894+
"))
895+

0 commit comments

Comments
 (0)