Skip to content

Commit 2e8657e

Browse files
committed
Clean up imports even if they have redundant whitespace
1 parent 8e1792b commit 2e8657e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pyimport.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ on line number LINE, remove VAR (e.g. 'baz')."
198198
(pyimport--remove-on-line (format "%s, " var))
199199
(pyimport--remove-on-line var))
200200
;; If we only have "from foo import " left, remove the rest of the line.
201-
(when (or (looking-at (rx "from " (1+ (not (any space))) " import " line-end))
202-
(looking-at (rx "import " (1+ (not (any space))) " as " line-end)))
201+
(when (or (looking-at (rx "from " (1+ (not (any space))) " import" (1+ space) line-end))
202+
(looking-at (rx "import " (1+ (not (any space))) " as" (1+ space) line-end)))
203203
(pyimport--delete-current-line)))))))
204204

205205
;; TODO: defcustom

test/pyimport-test.el

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
(should
2525
(equal (buffer-string) ""))))
2626

27+
(ert-deftest remove-import-extra-whitespace ()
28+
"Ensure we remove imports correctly even when there's extra whitespace."
29+
(with-temp-buffer
30+
(insert "from foo import bar")
31+
(pyimport--remove-import 1 "bar")
32+
(should
33+
(equal (buffer-string) ""))))
34+
2735
(ert-deftest remove-on-line-first ()
2836
"We should remove the first occurrence, if present."
2937
(with-temp-buffer

0 commit comments

Comments
 (0)