summaryrefslogtreecommitdiff
path: root/.emacs.d/snippets/python-mode/.yas-setup.el
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d/snippets/python-mode/.yas-setup.el')
-rw-r--r--.emacs.d/snippets/python-mode/.yas-setup.el22
1 files changed, 22 insertions, 0 deletions
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)))