2424
2525; ;; Code:
2626
27+ (require 'cl-lib )
2728(require 's )
2829
2930(require 'docstr-util )
@@ -224,31 +225,39 @@ the last word only."
224225; ; (@* "Writers" )
225226; ;
226227
227- (defun docstr-writers--insert-param (param-types param-vars prefix )
228+ (defun docstr-writers--valid-return-type-p (return-type-str ignore-lst )
229+ " Return non-nil if RETURN-TYPE-STR is valid compare to IGNORE-LST."
230+ (and (stringp return-type-str)
231+ (not (docstr-util-is-contain-list-string ignore-lst return-type-str))))
232+
233+ (defun docstr-writers--insert-param (param-types param-vars prefix &optional postfix )
228234 " Insert parameter section.
229235
230236Argument PARAM-TYPES is a list of string contain type name data.
231237Argument PARAM-VARS is a list of string contain variable name data.
232- Argument PREFIX is string infront of each document string."
238+ Argument PREFIX is string infront of each document string.
239+ Argument POSTFIX is string behind of each document string."
233240 (let ((param-var-len (length param-vars)) (param-index 0 ))
234241 (while (< param-index param-var-len)
235242 (let ((type (nth param-index param-types))
236243 (var (nth param-index param-vars)))
237244 (insert prefix)
238245 (insert (docstr-form-param type var docstr-desc-param))
246+ (when postfix (insert postfix))
239247 (indent-for-tab-command ))
240248 (setq param-index (1+ param-index)))))
241249
242- (defun docstr-writers--insert-return (return-type-str ignore-lst prefix )
250+ (defun docstr-writers--insert-return (return-type-str ignore-lst prefix &optional postfix )
243251 " Insert return section.
244252
245253Argument RETURN-TYPE-STR is a string contain return type name. Argument
246254IGNORE-LST is a list of string contain return type that we want to skip.
247- Argument PREFIX is string infront of each document string."
248- ( when ( and ( stringp return-type-str)
249- ( not (docstr-util-is-contain-list-string ignore-lst return-type-str)) )
255+ Argument PREFIX is string infront of return document string.
256+ Argument POSTFIX is string behind of return document string. "
257+ ( when (docstr-writers--valid-return-type-p return-type-str ignore-lst )
250258 (insert prefix)
251- (insert (docstr-form-return return-type-str " " docstr-desc-return))))
259+ (insert (docstr-form-return return-type-str " " docstr-desc-return))
260+ (when postfix (insert postfix))))
252261
253262(defun docstr-writers-after (start )
254263 " Do stuff after document string insertion.
@@ -285,6 +294,56 @@ Argument START is the starting point ot the insertion."
285294 (docstr-writers--insert-return return-type-str nil prefix)
286295 (docstr-writers-after start)))
287296
297+ (defun docstr-writers-csharp (search-string )
298+ " Insert document string for C# using SEARCH-STRING."
299+ (let* ((start (point )) (prefix " \n /// " )
300+ (paren-param-list (docstr-writers--paren-param-list search-string))
301+ (param-types (nth 0 paren-param-list))
302+ (param-vars (nth 1 paren-param-list))
303+ ; ; Get the return data type.
304+ (return-type-str (docstr-writers--return-type search-string))
305+ docstring-type)
306+ ; ; Determine the docstring type.
307+ (save-excursion
308+ (backward-char 1 )
309+ (if (docstr-util-current-char-equal-p " *" )
310+ (setq docstring-type 'javadoc ) (setq docstring-type 'vsdoc )))
311+
312+ (cl-case docstring-type
313+ (javadoc (docstr-writers-java search-string))
314+ (vsdoc
315+ (forward-line 1 ) (end-of-line )
316+ (let ((docstr-format-var " %s" )
317+ (docstr-format-param " <param name=\" #V\" ></param>" )
318+ (docstr-format-return " <returns></returns>" ))
319+ (docstr-writers--insert-param param-types param-vars prefix)
320+ (docstr-writers--insert-return return-type-str '(" void" ) prefix))
321+ (docstr-writers-after start)))))
322+
323+ (defun docstr-writers-golang (search-string )
324+ " Insert document string for Golang using SEARCH-STRING."
325+ (let* ((start (point )) (prefix " \n // " )
326+ (paren-param-list (docstr-writers--paren-param-list-behind search-string))
327+ (param-types (nth 0 paren-param-list))
328+ (param-vars (nth 1 paren-param-list))
329+ ; ; Get the return data type.
330+ (return-type-str (docstr-writers--return-type-behind search-string))
331+ docstring-type)
332+
333+ ; ; Determine the docstring type.
334+ (save-excursion
335+ (backward-char 1 )
336+ (if (docstr-util-current-char-equal-p " *" )
337+ (setq docstring-type 'javadoc ) (setq docstring-type 'godoc )))
338+
339+ (cl-case docstring-type
340+ (javadoc (docstr-writers-c++ search-string))
341+ (godoc
342+ (end-of-line ) (insert " " )
343+ (docstr-writers--insert-param param-types param-vars prefix)
344+ (docstr-writers--insert-return return-type-str nil prefix)
345+ (docstr-writers-after start)))))
346+
288347(defun docstr-writers-java (search-string )
289348 " Insert document string for Java using SEARCH-STRING."
290349 (let* ((start (point )) (prefix " \n * " )
@@ -306,7 +365,7 @@ Argument START is the starting point ot the insertion."
306365 (param-var-len (length param-vars))
307366 (return-type-str " void" )) ; Get the return data type.
308367 (unless (= param-var-len 0 )
309- (insert (format " \n %s --- " docstr-lua-splitter)))
368+ (insert (format " \n %s " docstr-lua-splitter)))
310369 (docstr-writers--insert-param param-types param-vars prefix)
311370 (docstr-writers--insert-return return-type-str '(" void" ) prefix)
312371 (docstr-writers-after start)))
@@ -343,7 +402,7 @@ Argument START is the starting point ot the insertion."
343402 (c-mode . docstr-writers-c)
344403 (c++-mode . docstr-writers-c++)
345404 (csharp-mode . docstr-writers-csharp)
346- (go-mode . docstr-writers-go )
405+ (go-mode . docstr-writers-golang )
347406 (groovy-mode . docstr-writers-groovy)
348407 (java-mode . docstr-writers-java)
349408 (javascript-mode . docstr-writers-javascript)
0 commit comments