Skip to content

Commit fb53fbc

Browse files
committed
Merge pull request #6 from jferguson-gnubio/python_arg_docstring
Automatic arguments to Python def docstrings
2 parents cf314d6 + a3bdc86 commit fb53fbc

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

python-mode/.yas-setup.el

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 (mapconcat
11+
'(lambda (x)
12+
(concat (nth 0 x) " -- "
13+
(if (nth 1 x) (concat "\(default " (nth 1 x) "\)"))))
14+
(python-split-args yas-text)
15+
indent)))
16+
(unless (string= args "")
17+
(mapconcat 'identity (list "Keyword Arguments:" args) indent))))

python-mode/function_docstring

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- mode: snippet -*-
2+
# name: function_docstring
3+
# key: fd
4+
# group: definitions
5+
# --
6+
def ${1:name}($2):
7+
\"\"\"$3
8+
${2:$(python-args-to-docstring)}
9+
\"\"\"
10+
$0

python-mode/init_docstring

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- mode: snippet -*-
2+
# name: init_docstring
3+
# key: id
4+
# group : definitions
5+
# --
6+
def __init__(self$1):
7+
\"\"\"$2
8+
${1:$(python-args-to-docstring)}
9+
\"\"\"
10+
$0

python-mode/method_docstring

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- mode: snippet -*-
2+
# name: method_docstring
3+
# key: md
4+
# group: object oriented
5+
# --
6+
def ${1:name}(self$2):
7+
\"\"\"$3
8+
${2:$(python-args-to-docstring)}
9+
\"\"\"
10+
$0

0 commit comments

Comments
 (0)