Added numpy function docstring template

This commit is contained in:
Egor Panfilov 2016-08-14 17:14:20 +03:00
parent c6304aa86e
commit 10db44b841
2 changed files with 25 additions and 0 deletions

View file

@ -21,5 +21,19 @@
(unless (string= formatted-args "")
(mapconcat 'identity (list "Keyword Arguments:" formatted-args) indent))))
(defun python-args-to-docstring-numpy ()
"return docstring format for the python arguments in yas-text"
(let* ((args (python-split-args yas-text))
(format-arg (lambda(arg)
(concat (nth 0 arg) " : " (if (nth 1 arg) ", optional") "\n")))
(formatted-params (mapconcat format-arg args "\n"))
(formatted-ret (mapconcat format-arg (list (list "out")) "\n")))
(unless (string= formatted-params "")
(mapconcat 'identity
(list "\nParameters\n----------" formatted-params
"\nReturns\n-------" formatted-ret)
"\n"))))
(add-hook 'python-mode-hook
'(lambda () (set (make-local-variable 'yas-indent-line) 'fixed)))

View file

@ -0,0 +1,11 @@
# -*- mode: snippet -*-
# contributor: Egor Panfilov <egor.v.panfilov[at]gmail[dot]com>
# name: function_docstring_numpy
# key: fdn
# group: definitions
# --
def ${1:name}($2):
\"\"\"$3
${2:$(python-args-to-docstring-numpy)}
\"\"\"
$0