diff options
Diffstat (limited to '.emacs.d/snippets/python-mode')
| -rw-r--r-- | .emacs.d/snippets/python-mode/.yas-setup.el | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/.emacs.d/snippets/python-mode/.yas-setup.el b/.emacs.d/snippets/python-mode/.yas-setup.el index 7603e4d..76af532 100644 --- a/.emacs.d/snippets/python-mode/.yas-setup.el +++ b/.emacs.d/snippets/python-mode/.yas-setup.el | |||
| @@ -14,12 +14,25 @@ | |||
| 14 | (max-len (if args (apply 'max (mapcar (lambda (x) (length (nth 0 x))) args)) 0)) | 14 | (max-len (if args (apply 'max (mapcar (lambda (x) (length (nth 0 x))) args)) 0)) |
| 15 | (formatted-args (mapconcat | 15 | (formatted-args (mapconcat |
| 16 | (lambda (x) | 16 | (lambda (x) |
| 17 | (concat ":param " (nth 0 x) ":\n:type " (nth 0 x) ":\n" | 17 | (concat (nth 0 x) (make-string (- max-len (length (nth 0 x))) ? ) " -- " |
| 18 | (if (nth 1 x) (concat "\(default " (nth 1 x) "\)")))) | 18 | (if (nth 1 x) (concat "\(default " (nth 1 x) "\)")))) |
| 19 | args | 19 | args |
| 20 | indent))) | 20 | indent))) |
| 21 | (unless (string= formatted-args "") | 21 | (unless (string= formatted-args "") |
| 22 | (mapconcat 'identity (list "Keyword Arguments:" formatted-args) indent)))) | 22 | (mapconcat 'identity (list "Keyword Arguments:" formatted-args) indent)))) |
| 23 | 23 | ||
| 24 | (add-hook 'python-mode-hook | 24 | (defun python-args-to-docstring-numpy () |
| 25 | '(lambda () (set (make-local-variable 'yas-indent-line) 'fixed))) | 25 | "return docstring format for the python arguments in yas-text" |
| 26 | (let* ((args (python-split-args yas-text)) | ||
| 27 | (format-arg (lambda(arg) | ||
| 28 | (concat (nth 0 arg) " : " (if (nth 1 arg) ", optional") "\n"))) | ||
| 29 | (formatted-params (mapconcat format-arg args "\n")) | ||
| 30 | (formatted-ret (mapconcat format-arg (list (list "out")) "\n"))) | ||
| 31 | (unless (string= formatted-params "") | ||
| 32 | (mapconcat 'identity | ||
| 33 | (list "\nParameters\n----------" formatted-params | ||
| 34 | "\nReturns\n-------" formatted-ret) | ||
| 35 | "\n")))) | ||
| 36 | |||
| 37 | |||
| 38 | (add-hook 'python-mode-hook #'yasnippet-snippets--fixed-indent) | ||
