summaryrefslogtreecommitdiff
path: root/.emacs.d/snippets/python-mode
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d/snippets/python-mode')
-rw-r--r--.emacs.d/snippets/python-mode/.yas-parents1
-rw-r--r--.emacs.d/snippets/python-mode/.yas-setup.el22
-rw-r--r--.emacs.d/snippets/python-mode/__getitem__7
-rw-r--r--.emacs.d/snippets/python-mode/__setitem__7
-rw-r--r--.emacs.d/snippets/python-mode/arg7
-rw-r--r--.emacs.d/snippets/python-mode/classmethod10
-rw-r--r--.emacs.d/snippets/python-mode/cls7
-rw-r--r--.emacs.d/snippets/python-mode/dec14
-rw-r--r--.emacs.d/snippets/python-mode/deftest7
-rw-r--r--.emacs.d/snippets/python-mode/doc6
-rw-r--r--.emacs.d/snippets/python-mode/eq7
-rw-r--r--.emacs.d/snippets/python-mode/for6
-rw-r--r--.emacs.d/snippets/python-mode/from6
-rw-r--r--.emacs.d/snippets/python-mode/function7
-rw-r--r--.emacs.d/snippets/python-mode/function_docstring10
-rw-r--r--.emacs.d/snippets/python-mode/ife9
-rw-r--r--.emacs.d/snippets/python-mode/ifmain6
-rw-r--r--.emacs.d/snippets/python-mode/import7
-rw-r--r--.emacs.d/snippets/python-mode/init_docstring10
-rw-r--r--.emacs.d/snippets/python-mode/lambda5
-rw-r--r--.emacs.d/snippets/python-mode/list7
-rw-r--r--.emacs.d/snippets/python-mode/method7
-rw-r--r--.emacs.d/snippets/python-mode/method_docstring10
-rw-r--r--.emacs.d/snippets/python-mode/not_impl5
-rw-r--r--.emacs.d/snippets/python-mode/parse_args9
-rw-r--r--.emacs.d/snippets/python-mode/parser7
-rw-r--r--.emacs.d/snippets/python-mode/print5
-rw-r--r--.emacs.d/snippets/python-mode/reg7
-rw-r--r--.emacs.d/snippets/python-mode/repr7
-rw-r--r--.emacs.d/snippets/python-mode/return5
-rw-r--r--.emacs.d/snippets/python-mode/script13
-rw-r--r--.emacs.d/snippets/python-mode/self6
-rw-r--r--.emacs.d/snippets/python-mode/self_without_dot6
-rw-r--r--.emacs.d/snippets/python-mode/selfassign6
-rw-r--r--.emacs.d/snippets/python-mode/static6
-rw-r--r--.emacs.d/snippets/python-mode/str7
-rw-r--r--.emacs.d/snippets/python-mode/try8
-rw-r--r--.emacs.d/snippets/python-mode/unicode7
-rw-r--r--.emacs.d/snippets/python-mode/utf85
-rw-r--r--.emacs.d/snippets/python-mode/while7
-rw-r--r--.emacs.d/snippets/python-mode/with7
41 files changed, 308 insertions, 0 deletions
diff --git a/.emacs.d/snippets/python-mode/.yas-parents b/.emacs.d/snippets/python-mode/.yas-parents
new file mode 100644
index 0000000..75d003f
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/.yas-parents
@@ -0,0 +1 @@
prog-mode
diff --git a/.emacs.d/snippets/python-mode/.yas-setup.el b/.emacs.d/snippets/python-mode/.yas-setup.el
new file mode 100644
index 0000000..6635232
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/.yas-setup.el
@@ -0,0 +1,22 @@
1(defun python-split-args (arg-string)
2 "Split a python argument string into ((name, default)..) tuples"
3 (mapcar (lambda (x)
4 (split-string x "[[:blank:]]*=[[:blank:]]*" t))
5 (split-string arg-string "[[:blank:]]*,[[:blank:]]*" t)))
6
7(defun python-args-to-docstring ()
8 "return docstring format for the python arguments in yas-text"
9 (let* ((indent (concat "\n" (make-string (current-column) 32)))
10 (args (python-split-args yas-text))
11 (max-len (if args (apply 'max (mapcar (lambda (x) (length (nth 0 x))) args)) 0))
12 (formatted-args (mapconcat
13 (lambda (x)
14 (concat (nth 0 x) (make-string (- max-len (length (nth 0 x))) ? ) " -- "
15 (if (nth 1 x) (concat "\(default " (nth 1 x) "\)"))))
16 args
17 indent)))
18 (unless (string= formatted-args "")
19 (mapconcat 'identity (list "Keyword Arguments:" formatted-args) indent))))
20
21(add-hook 'python-mode-hook
22 '(lambda () (set (make-local-variable 'yas-indent-line) 'fixed)))
diff --git a/.emacs.d/snippets/python-mode/__getitem__ b/.emacs.d/snippets/python-mode/__getitem__
new file mode 100644
index 0000000..939bd1a
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/__getitem__
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: __getitem__
3# key: getit
4# group: dunder methods
5# --
6def __getitem__(self, ${1:key}):
7 $0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/__setitem__ b/.emacs.d/snippets/python-mode/__setitem__
new file mode 100644
index 0000000..c7db5b1
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/__setitem__
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: __setitem__
3# key: setit
4# group: dunder methods
5# --
6def __setitem__(self, ${1:key}, ${2:val}):
7 $0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/arg b/.emacs.d/snippets/python-mode/arg
new file mode 100644
index 0000000..f5145ec
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/arg
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: arg
3# key: arg
4# group: argparser
5# --
6parser.add_argument('-$1', '--$2',
7 $0)
diff --git a/.emacs.d/snippets/python-mode/classmethod b/.emacs.d/snippets/python-mode/classmethod
new file mode 100644
index 0000000..aa78440
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/classmethod
@@ -0,0 +1,10 @@
1# -*- mode: snippet -*-
2# name: classmethod
3# key: cm
4# group: object oriented
5# --
6@classmethod
7def ${1:meth}(cls, $2):
8 """
9 """
10 $3 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/cls b/.emacs.d/snippets/python-mode/cls
new file mode 100644
index 0000000..9f8b27c
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/cls
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: cls
3# key: cls
4# group: object oriented
5# --
6class ${1:class}:
7 $0
diff --git a/.emacs.d/snippets/python-mode/dec b/.emacs.d/snippets/python-mode/dec
new file mode 100644
index 0000000..b22c9e9
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/dec
@@ -0,0 +1,14 @@
1# -*- mode: snippet -*-
2# name: dec
3# key: dec
4# group : definitions
5# --
6def ${1:decorator}(func):
7 $2
8 def _$1(*args, **kwargs):
9 $3
10 ret = func(*args, **kwargs)
11 $4
12 return ret
13
14 return _$1 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/deftest b/.emacs.d/snippets/python-mode/deftest
new file mode 100644
index 0000000..394553a
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/deftest
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: deftest
3# key: dt
4# group: testing
5# --
6def test_${1:long_name}(self):
7 $0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/doc b/.emacs.d/snippets/python-mode/doc
new file mode 100644
index 0000000..2929e78
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/doc
@@ -0,0 +1,6 @@
1# -*- mode: snippet -*-
2# name: doc
3# key: d
4# --
5"""$0
6""" \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/eq b/.emacs.d/snippets/python-mode/eq
new file mode 100644
index 0000000..e19c328
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/eq
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: __eq__
3# key: eq
4# group: dunder methods
5# --
6def __eq__(self, other):
7 return self.$1 == other.$1 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/for b/.emacs.d/snippets/python-mode/for
new file mode 100644
index 0000000..0033c87
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/for
@@ -0,0 +1,6 @@
1# name: for ... in ... : ...
2# key: for
3# group : control structure
4# --
5for ${var} in ${collection}:
6 $0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/from b/.emacs.d/snippets/python-mode/from
new file mode 100644
index 0000000..3a4acfc
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/from
@@ -0,0 +1,6 @@
1# -*- mode: snippet -*-
2# name: from
3# key: from
4# group : general
5# --
6from ${1:lib} import ${2:funs} \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/function b/.emacs.d/snippets/python-mode/function
new file mode 100644
index 0000000..d7e8f12
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/function
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: function
3# key: f
4# group: definitions
5# --
6def ${1:fun}(${2:args}):
7 $0
diff --git a/.emacs.d/snippets/python-mode/function_docstring b/.emacs.d/snippets/python-mode/function_docstring
new file mode 100644
index 0000000..1f7f35b
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/function_docstring
@@ -0,0 +1,10 @@
1# -*- mode: snippet -*-
2# name: function_docstring
3# key: fd
4# group: definitions
5# --
6def ${1:name}($2):
7 \"\"\"$3
8 ${2:$(python-args-to-docstring)}
9 \"\"\"
10 $0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/ife b/.emacs.d/snippets/python-mode/ife
new file mode 100644
index 0000000..4b8f613
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/ife
@@ -0,0 +1,9 @@
1# -*- mode: snippet -*-
2# name: ife
3# key: ife
4# group : control structure
5# --
6if $1:
7 $2
8else:
9 $0
diff --git a/.emacs.d/snippets/python-mode/ifmain b/.emacs.d/snippets/python-mode/ifmain
new file mode 100644
index 0000000..9575798
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/ifmain
@@ -0,0 +1,6 @@
1# -*- mode: snippet -*-
2# name: ifmain
3# key: ifm
4# --
5if __name__ == '__main__':
6 ${1:main()} \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/import b/.emacs.d/snippets/python-mode/import
new file mode 100644
index 0000000..f34bc39
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/import
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: import
3# key: imp
4# group : general
5# --
6import ${1:lib}${2: as ${3:alias}}
7$0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/init_docstring b/.emacs.d/snippets/python-mode/init_docstring
new file mode 100644
index 0000000..51af8db
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/init_docstring
@@ -0,0 +1,10 @@
1# -*- mode: snippet -*-
2# name: init_docstring
3# key: id
4# group : definitions
5# --
6def __init__(self$1):
7 \"\"\"$2
8 ${1:$(python-args-to-docstring)}
9 \"\"\"
10 $0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/lambda b/.emacs.d/snippets/python-mode/lambda
new file mode 100644
index 0000000..08b268b
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/lambda
@@ -0,0 +1,5 @@
1# -*- mode: snippet -*-
2# name: lambda
3# key: lam
4# --
5lambda ${1:x}: $0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/list b/.emacs.d/snippets/python-mode/list
new file mode 100644
index 0000000..63cef24
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/list
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: list
3# key: li
4# group : definitions
5# --
6[${1:el} for $1 in ${2:list}]
7$0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/method b/.emacs.d/snippets/python-mode/method
new file mode 100644
index 0000000..985ef0c
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/method
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: method
3# key: m
4# group: object oriented
5# --
6def ${1:method}(self${2:, $3}):
7 $0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/method_docstring b/.emacs.d/snippets/python-mode/method_docstring
new file mode 100644
index 0000000..8f5e78d
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/method_docstring
@@ -0,0 +1,10 @@
1# -*- mode: snippet -*-
2# name: method_docstring
3# key: md
4# group: object oriented
5# --
6def ${1:name}(self$2):
7 \"\"\"$3
8 ${2:$(python-args-to-docstring)}
9 \"\"\"
10 $0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/not_impl b/.emacs.d/snippets/python-mode/not_impl
new file mode 100644
index 0000000..515e353
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/not_impl
@@ -0,0 +1,5 @@
1# -*- mode: snippet -*-
2# name: not_impl
3# key: not_impl
4# --
5raise NotImplementedError \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/parse_args b/.emacs.d/snippets/python-mode/parse_args
new file mode 100644
index 0000000..aa61070
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/parse_args
@@ -0,0 +1,9 @@
1# -*- mode: snippet -*-
2# name: parse_args
3# key: pargs
4# group: argparser
5# --
6def parse_arguments():
7 parser = argparse.ArgumentParser(description='$1')
8 $0
9 return parser.parse_args() \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/parser b/.emacs.d/snippets/python-mode/parser
new file mode 100644
index 0000000..29a04ea
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/parser
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: parser
3# key: pars
4# group: argparser
5# --
6parser = argparse.ArgumentParser(description='$1')
7$0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/print b/.emacs.d/snippets/python-mode/print
new file mode 100644
index 0000000..cc1c797
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/print
@@ -0,0 +1,5 @@
1# -*- mode: snippet -*-
2# name: print
3# key: p
4# --
5print($0) \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/reg b/.emacs.d/snippets/python-mode/reg
new file mode 100644
index 0000000..c4ebeac
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/reg
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: reg
3# key: reg
4# group : general
5# --
6${1:regexp} = re.compile(r"${2:expr}")
7$0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/repr b/.emacs.d/snippets/python-mode/repr
new file mode 100644
index 0000000..a1f6783
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/repr
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: __repr__
3# key: repr
4# group: dunder methods
5# --
6def __repr__(self):
7 $0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/return b/.emacs.d/snippets/python-mode/return
new file mode 100644
index 0000000..641a308
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/return
@@ -0,0 +1,5 @@
1# -*- mode: snippet -*-
2# name: return
3# key: r
4# --
5return $0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/script b/.emacs.d/snippets/python-mode/script
new file mode 100644
index 0000000..e7f8a42
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/script
@@ -0,0 +1,13 @@
1# -*- mode: snippet -*-
2# name: script
3# key: script
4# --
5#!/usr/bin/env python
6# -*- coding: utf-8 -*-
7
8
9def main():
10 pass
11
12if __name__ == '__main__':
13 main()
diff --git a/.emacs.d/snippets/python-mode/self b/.emacs.d/snippets/python-mode/self
new file mode 100644
index 0000000..4461022
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/self
@@ -0,0 +1,6 @@
1# -*- mode: snippet -*-
2# name: self
3# key: .
4# group: object oriented
5# --
6self.$0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/self_without_dot b/.emacs.d/snippets/python-mode/self_without_dot
new file mode 100644
index 0000000..a1a0526
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/self_without_dot
@@ -0,0 +1,6 @@
1# -*- mode: snippet -*-
2# name: self_without_dot
3# key: s
4# group: object oriented
5# --
6self \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/selfassign b/.emacs.d/snippets/python-mode/selfassign
new file mode 100644
index 0000000..95d7b2b
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/selfassign
@@ -0,0 +1,6 @@
1# -*- mode: snippet -*-
2# name: selfassign
3# key: sn
4# group: object oriented
5# --
6self.$1 = $1 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/static b/.emacs.d/snippets/python-mode/static
new file mode 100644
index 0000000..19c3df9
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/static
@@ -0,0 +1,6 @@
1# -*- mode: snippet -*-
2# name: static
3# key: sm
4# --
5@staticmethod
6def ${1:func}($0):
diff --git a/.emacs.d/snippets/python-mode/str b/.emacs.d/snippets/python-mode/str
new file mode 100644
index 0000000..b0572e3
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/str
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: __str__
3# key: str
4# group: dunder methods
5# --
6def __str__(self):
7 $0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/try b/.emacs.d/snippets/python-mode/try
new file mode 100644
index 0000000..8836de6
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/try
@@ -0,0 +1,8 @@
1# -*- mode: snippet -*-
2# name: try
3# key: try
4# --
5try:
6 $1
7except ${2:Exception}:
8 $0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/unicode b/.emacs.d/snippets/python-mode/unicode
new file mode 100644
index 0000000..52d6b8d
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/unicode
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: __unicode__
3# key: un
4# group: dunder methods
5# --
6def __unicode__(self):
7 $0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/utf8 b/.emacs.d/snippets/python-mode/utf8
new file mode 100644
index 0000000..2ebd82e
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/utf8
@@ -0,0 +1,5 @@
1# -*- mode: snippet -*-
2# name: utf-8 encoding
3# key: utf8
4# --
5# -*- coding: utf-8 -*-
diff --git a/.emacs.d/snippets/python-mode/while b/.emacs.d/snippets/python-mode/while
new file mode 100644
index 0000000..7b3539c
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/while
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: while
3# key: wh
4# group: control structure
5# --
6while ${1:True}:
7 $0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/with b/.emacs.d/snippets/python-mode/with
new file mode 100644
index 0000000..7fcbd38
--- /dev/null
+++ b/.emacs.d/snippets/python-mode/with
@@ -0,0 +1,7 @@
1# -*- mode: snippet -*-
2# name: with
3# key: with
4# group : control structure
5# --
6with ${1:expr}${2: as ${3:alias}}:
7 $0 \ No newline at end of file