summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEgor Panfilov <multicolor.mood@gmail.com>2016-08-14 17:14:20 +0300
committerEgor Panfilov <multicolor.mood@gmail.com>2016-08-14 17:14:20 +0300
commit10db44b841f6e572ae0f69ac9aceda1852b0d44f (patch)
tree0d937f261a766645b9e9a986efb724f8d97c1958
parentc6304aa86e6a9c409d0e78672ef247d1abcf8f55 (diff)
Added numpy function docstring template
-rw-r--r--python-mode/.yas-setup.el14
-rw-r--r--python-mode/function_docstring_numpy11
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