Skip to content

Commit ca4dd48

Browse files
committed
Don't insert imports before the shebang
1 parent 2482c8e commit ca4dd48

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
wrong buffer where it found the import.
55
* `pyimport-remove-unused` now works on all buffers, even if they're
66
unsaved or not visiting a file.
7+
* `pyimport-insert-missing` now steps over shebangs when choosing
8+
where to insert new imports.
79

810
## v1.0
911

pyimport.el

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,17 @@ To terminate the loop early, throw 'break."
115115
;; LINE as-is.
116116
(save-excursion
117117
(goto-char (point-min))
118-
(insert line "\n")))))
118+
(let ((insert-pos (point)))
119+
(catch 'found
120+
;; Find the first non-comment non-blank line.
121+
(dotimes (_ 30)
122+
(forward-line 1)
123+
(when (and (not (looking-at "\n"))
124+
(not (looking-at "#"))
125+
(not (looking-at "\"")))
126+
(setq insert-pos (point))
127+
(throw 'found nil))))
128+
(insert line "\n"))))))
119129

120130
(defun pyimport--get-alias (import-as symbol)
121131
"Return the original symbol name, the aliased name, or nil, if

0 commit comments

Comments
 (0)