File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -129,11 +129,18 @@ To terminate the loop early, throw 'break."
129
129
; ; Find the first non-comment non-blank line.
130
130
(dotimes (_ 30 )
131
131
(forward-line 1 )
132
- (when (and (not (looking-at " \n " ))
133
- (not (looking-at " #" ))
134
- (not (looking-at " \" " )))
135
- (setq insert-pos (point ))
136
- (throw 'found nil ))))
132
+ (let* ((ppss (syntax-ppss ))
133
+ ; ; Since point is at the start of the line, we
134
+ ; ; are outside single line comments or
135
+ ; ; strings. However, we might be in a multiline
136
+ ; ; comment.
137
+ (string-comment-p (nth 8 ppss)))
138
+ (when (and (not (looking-at " \n " ))
139
+ (not (looking-at " #" ))
140
+ (not (looking-at " \" " ))
141
+ (or (not string-comment-p) t ))
142
+ (setq insert-pos (point ))
143
+ (throw 'found nil )))))
137
144
(insert line " \n " ))))))
138
145
139
146
(defun pyimport--get-alias (import-as symbol )
Original file line number Diff line number Diff line change 160
160
(equal (buffer-string )
161
161
" from foo import x\n " ))))
162
162
163
+ (ert-deftest pyimport-insert-import-module-docstring ()
164
+ " Test inserting an import when the module starts with a docstring."
165
+ (with-temp-buffer
166
+ (insert " \"\"\" hello world.\n\n\"\"\"\n\n from bar import y" )
167
+ (pyimport--insert-import " from foo import x" )
168
+ (should
169
+ (equal (buffer-string )
170
+ " \"\"\" hello world.\n\n\"\"\"\n\n from foo import x\n from bar import y" ))))
171
+
163
172
(ert-deftest pyimport-extract-simple-import ()
164
173
(should
165
174
(equal
You can’t perform that action at this time.
0 commit comments