diff options
author | Andrea Crotti <andrea.crotti.0@gmail.com> | 2016-09-17 10:49:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-17 10:49:19 +0100 |
commit | cf589efb27fef753482af82476675fae8d5761d3 (patch) | |
tree | 0d937f261a766645b9e9a986efb724f8d97c1958 | |
parent | c6304aa86e6a9c409d0e78672ef247d1abcf8f55 (diff) | |
parent | 10db44b841f6e572ae0f69ac9aceda1852b0d44f (diff) |
Merge pull request #158 from soupault/master
Add snippet for `function+docstring in Numpy convention` to python-mode
-rw-r--r-- | python-mode/.yas-setup.el | 14 | ||||
-rw-r--r-- | python-mode/function_docstring_numpy | 11 |
2 files changed, 25 insertions, 0 deletions
diff --git a/python-mode/.yas-setup.el b/python-mode/.yas-setup.el index cd46717..1af8703 100644 --- a/python-mode/.yas-setup.el +++ b/python-mode/.yas-setup.el @@ -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))) diff --git a/python-mode/function_docstring_numpy b/python-mode/function_docstring_numpy new file mode 100644 index 0000000..00ea351 --- /dev/null +++ b/python-mode/function_docstring_numpy @@ -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
\ No newline at end of file |