summaryrefslogtreecommitdiff
path: root/python-mode
diff options
context:
space:
mode:
Diffstat (limited to 'python-mode')
-rw-r--r--python-mode/.yas-setup.el17
-rw-r--r--python-mode/all2
-rw-r--r--python-mode/assert (renamed from python-mode/ass)0
-rw-r--r--python-mode/cls2
-rw-r--r--python-mode/function_docstring_numpy11
-rw-r--r--python-mode/pl7
-rw-r--r--python-mode/scls7
7 files changed, 44 insertions, 2 deletions
diff --git a/python-mode/.yas-setup.el b/python-mode/.yas-setup.el
index 6635232..1af8703 100644
--- a/python-mode/.yas-setup.el
+++ b/python-mode/.yas-setup.el
@@ -1,3 +1,6 @@
+(require 'yasnippet)
+(defvar yas-text)
+
(defun python-split-args (arg-string)
"Split a python argument string into ((name, default)..) tuples"
(mapcar (lambda (x)
@@ -18,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/all b/python-mode/all
index 062e31a..b92c4dc 100644
--- a/python-mode/all
+++ b/python-mode/all
@@ -1,6 +1,6 @@
# -*- mode: snippet -*-
# name: all
-# key: a
+# key: all
# --
__all__ = [
$0
diff --git a/python-mode/ass b/python-mode/assert
index ec82efe..ec82efe 100644
--- a/python-mode/ass
+++ b/python-mode/assert
diff --git a/python-mode/cls b/python-mode/cls
index 9f8b27c..f857cdb 100644
--- a/python-mode/cls
+++ b/python-mode/cls
@@ -1,5 +1,5 @@
# -*- mode: snippet -*-
-# name: cls
+# name: class
# key: cls
# group: object oriented
# --
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
diff --git a/python-mode/pl b/python-mode/pl
new file mode 100644
index 0000000..f0fdd05
--- /dev/null
+++ b/python-mode/pl
@@ -0,0 +1,7 @@
+# -*- mode: snippet -*-
+# name: Import pyplot
+# key: plt
+# group : general
+# --
+import matplotlib.pyplot as plt
+$0
diff --git a/python-mode/scls b/python-mode/scls
new file mode 100644
index 0000000..4a10e28
--- /dev/null
+++ b/python-mode/scls
@@ -0,0 +1,7 @@
+# -*- mode: snippet -*-
+# name: subclass
+# key: scls
+# group: object oriented
+# --
+class ${1:class}(${2:super-class}):
+ $0