Skip to content

Commit 38e93aa

Browse files
committed
Handle excess whitespace more robustly
1 parent 307549c commit 38e93aa

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

pyimport.el

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ on line number LINE, remove VAR (e.g. 'baz')."
261261
(pyimport--remove-on-line (format "%s, " var))
262262
(pyimport--remove-on-line var))
263263
;; If we only have "from foo import " left, remove the rest of the line.
264-
(when (or (looking-at (rx "from " (1+ (not (any space))) " import" (1+ space) line-end))
264+
(when (or (looking-at (rx "from" (+ space)
265+
(+ (or (syntax word) (syntax symbol) (syntax punctuation))) (+ space)
266+
"import" (1+ space)
267+
line-end))
265268
(looking-at (rx "from " (1+ (not (any space))) " import " (1+ (not (any space))) " as" (1+ space) line-end))
266269
(looking-at (rx "import " (1+ (not (any space))) " as" (1+ space) line-end)))
267270
(pyimport--delete-current-line)))))))

test/pyimport-test.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
(ert-deftest remove-import-extra-whitespace ()
2828
"Ensure we remove imports correctly even when there's extra whitespace."
2929
(with-temp-buffer
30-
(insert "from foo import bar")
30+
(insert "from foo import bar")
3131
(pyimport--remove-import 1 "bar")
3232
(should
3333
(equal (buffer-string) ""))))

0 commit comments

Comments
 (0)