summaryrefslogtreecommitdiff
path: root/.emacs.d/snippets/python-mode.statnett/.yas-setup.el
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d/snippets/python-mode.statnett/.yas-setup.el')
-rw-r--r--.emacs.d/snippets/python-mode.statnett/.yas-setup.el25
1 files changed, 25 insertions, 0 deletions
diff --git a/.emacs.d/snippets/python-mode.statnett/.yas-setup.el b/.emacs.d/snippets/python-mode.statnett/.yas-setup.el
new file mode 100644
index 0000000..7603e4d
--- /dev/null
+++ b/.emacs.d/snippets/python-mode.statnett/.yas-setup.el
@@ -0,0 +1,25 @@
1(require 'yasnippet)
2(defvar yas-text)
3
4(defun python-split-args (arg-string)
5 "Split a python argument string into ((name, default)..) tuples"
6 (mapcar (lambda (x)
7 (split-string x "[[:blank:]]*=[[:blank:]]*" t))
8 (split-string arg-string "[[:blank:]]*,[[:blank:]]*" t)))
9
10(defun python-args-to-docstring ()
11 "return docstring format for the python arguments in yas-text"
12 (let* ((indent (concat "\n" (make-string (current-column) 32)))
13 (args (python-split-args yas-text))
14 (max-len (if args (apply 'max (mapcar (lambda (x) (length (nth 0 x))) args)) 0))
15 (formatted-args (mapconcat
16 (lambda (x)
17 (concat ":param " (nth 0 x) ":\n:type " (nth 0 x) ":\n"
18 (if (nth 1 x) (concat "\(default " (nth 1 x) "\)"))))
19 args
20 indent)))
21 (unless (string= formatted-args "")
22 (mapconcat 'identity (list "Keyword Arguments:" formatted-args) indent))))
23
24(add-hook 'python-mode-hook
25 '(lambda () (set (make-local-variable 'yas-indent-line) 'fixed)))