@@ -144,6 +144,7 @@ variable. Argument DESC is the description of VAR."
144144 (advice-add (key-binding (kbd " RET" )) :after #'docstr--trigger-return )
145145 (cl-case major-mode
146146 (csharp-mode (advice-add (key-binding (kbd " /" )) :after #'docstr--trigger-csharp ))
147+ (go-mode (advice-add (key-binding (kbd " /" )) :after #'docstr--trigger-golang ))
147148 (lua-mode (advice-add (key-binding (kbd " -" )) :after #'docstr--trigger-lua ))
148149 (python-mode (advice-add (key-binding (kbd " \" " )) :after #'docstr--trigger-python )))))
149150
@@ -153,6 +154,7 @@ variable. Argument DESC is the description of VAR."
153154 (advice-remove (key-binding (kbd " RET" )) #'docstr--trigger-return )
154155 (cl-case major-mode
155156 (csharp-mode (advice-remove (key-binding (kbd " /" )) #'docstr--trigger-csharp ))
157+ (go-mode (advice-remove (key-binding (kbd " /" )) #'docstr--trigger-golang ))
156158 (lua-mode (advice-remove (key-binding (kbd " -" )) #'docstr--trigger-lua ))
157159 (python-mode (advice-remove (key-binding (kbd " \" " )) #'docstr--trigger-python )))))
158160
@@ -187,7 +189,8 @@ variable. Argument DESC is the description of VAR."
187189 (if writer
188190 (progn
189191 (run-hook-with-args 'docstr-before-insert-hook search-string)
190- (funcall (cdr writer) search-string))
192+ (save-excursion (funcall (cdr writer) search-string))
193+ (end-of-line ))
191194 (user-error " [WARNING] No document string support for %s" major-mode))))
192195
193196(defun docstr--get-search-string (type sr )
@@ -224,9 +227,13 @@ and SR."
224227See function `docstr--get-search-string' description for argument TYPE."
225228 (docstr--generic-search-string type " {" ))
226229
230+ (defun docstr--doc-valid-p ()
231+ " "
232+ (and docstr-mode (docstr-util-comment-block-p)))
233+
227234(defun docstr--trigger-return ()
228235 " Trigger document string by pressing key return."
229- (when docstr-mode
236+ (when ( docstr--doc-valid-p)
230237 (let ((ln-prev (docstr-util-line-relative -1 t ))
231238 (ln-current (docstr-util-line-relative 0 t ))
232239 (ln-next (docstr-util-line-relative 1 t )))
@@ -236,7 +243,8 @@ See function `docstr--get-search-string' description for argument TYPE."
236243
237244(defun docstr--trigger-csharp ()
238245 " Trigger document string inside C#."
239- (when (and docstr-mode (looking-back " ///" 3 ))
246+ (interactive )
247+ (when (and (docstr--doc-valid-p) (looking-back " ///" 3 ))
240248 (save-excursion
241249 (insert " <summary>\n " )
242250 (insert " /// \n " )
@@ -245,10 +253,15 @@ See function `docstr--get-search-string' description for argument TYPE."
245253 (end-of-line )
246254 (docstr--insert-doc-string (docstr--c-style-search-string 2 ))))
247255
256+ (defun docstr--trigger-golang ()
257+ " Trigger document string inside Golang."
258+ (interactive )
259+ (when (and (docstr--doc-valid-p) (looking-back " //" 2 ))
260+ (docstr--insert-doc-string (docstr--c-style-search-string 1 ))))
261+
248262(defun docstr--trigger-lua ()
249263 " Trigger document string inside Lua."
250- (interactive )
251- (when (and docstr-mode (looking-back " ---" 3 ))
264+ (when (and (docstr--doc-valid-p) (looking-back " ---" 3 ))
252265 (backward-delete-char 3 )
253266 (save-excursion
254267 (insert (format " %s \n " docstr-lua-splitter))
@@ -260,8 +273,7 @@ See function `docstr--get-search-string' description for argument TYPE."
260273
261274(defun docstr--trigger-python ()
262275 " Trigger document string inside Python."
263- (interactive )
264- (when (and docstr-mode (looking-back " \"\"\" " 3 ))
276+ (when (and (docstr--doc-valid-p) (looking-back " \"\"\" " 3 ))
265277 (save-excursion (insert " \"\"\" " ))
266278 (docstr--insert-doc-string (docstr--generic-search-string -1 " :" ))))
267279
0 commit comments