Skip to content

Commit ed4fd79

Browse files
committed
Merge pull request #258 from elixir-lang/fix-emacs-freez
Emacs hangs if `elixir-smie-forward-token` returns an empty string
2 parents b8363e9 + 4580b13 commit ed4fd79

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

elixir-smie.el

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,10 @@
260260
((looking-at elixir-smie--operator-regexp)
261261
(goto-char (match-end 0))
262262
"OP")
263-
(t (smie-default-forward-token))))
263+
(t
264+
(let ((token (smie-default-forward-token)))
265+
(unless (elixir-smie-empty-string-p token)
266+
token)))))
264267

265268
(defun elixir-smie-backward-token ()
266269
(let ((pos (point)))
@@ -635,6 +638,12 @@ Rules:
635638
(goto-char indent)
636639
(goto-char (elixir-smie--previous-line-indentation)))))))
637640

641+
(defun elixir-smie-empty-string-p (string)
642+
"Return non-nil if STRING is null, blank or whitespace only."
643+
(or (null string)
644+
(string= string "")
645+
(if (string-match-p "^\s+$" string) t)))
646+
638647
(add-to-list 'smie-indent-functions 'elixir-smie--indent-inside-heredoc)
639648

640649
(provide 'elixir-smie)

test/elixir-mode-helper-test.el

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,18 @@ end")
173173
(goto-line 4)
174174
(elixir-smie-current-line-contains-built-in-keyword-p)))))
175175

176+
(ert-deftest test-if-string-is-empty ()
177+
(should (equal (elixir-smie-empty-string-p nil)
178+
t))
179+
(should (equal (elixir-smie-empty-string-p "")
180+
t))
181+
(should (equal (elixir-smie-empty-string-p " ")
182+
t))
183+
(should (equal (elixir-smie-empty-string-p "story")
184+
nil))
185+
(should (equal (elixir-smie-empty-string-p " ")
186+
t)))
187+
176188
(provide 'elixir-mode-helper-test)
177189

178190
;;; elixir-mode-helper-test.el ends here

0 commit comments

Comments
 (0)