diff options
| author | Simeon Simeonov | 2021-01-12 20:05:37 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2021-01-12 20:05:37 +0100 |
| commit | 4996a6403108a226d4ff1d73b880207cc80284bd (patch) | |
| tree | 4ed642a366a34775d3401228db1f7bb10752b1b4 /.emacs.d/snippets/python-mode.statnett/.yas-setup.el | |
| parent | 4fbfa5db6d2819f528698b78d15634affdf9b9a9 (diff) | |
Add snippets/python-mode.statnett
Diffstat (limited to '.emacs.d/snippets/python-mode.statnett/.yas-setup.el')
| -rw-r--r-- | .emacs.d/snippets/python-mode.statnett/.yas-setup.el | 25 |
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))) | ||
