From 897eee81de8b3f6adf0165f50e95600a7b89c20c Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Wed, 4 Feb 2015 21:41:42 +0100 Subject: Standalone lisp and snippet repo --- .emacs.d/snippets/python-mode/.yas-setup.el | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .emacs.d/snippets/python-mode/.yas-setup.el (limited to '.emacs.d/snippets/python-mode/.yas-setup.el') 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 @@ +(defun python-split-args (arg-string) + "Split a python argument string into ((name, default)..) tuples" + (mapcar (lambda (x) + (split-string x "[[:blank:]]*=[[:blank:]]*" t)) + (split-string arg-string "[[:blank:]]*,[[:blank:]]*" t))) + +(defun python-args-to-docstring () + "return docstring format for the python arguments in yas-text" + (let* ((indent (concat "\n" (make-string (current-column) 32))) + (args (python-split-args yas-text)) + (max-len (if args (apply 'max (mapcar (lambda (x) (length (nth 0 x))) args)) 0)) + (formatted-args (mapconcat + (lambda (x) + (concat (nth 0 x) (make-string (- max-len (length (nth 0 x))) ? ) " -- " + (if (nth 1 x) (concat "\(default " (nth 1 x) "\)")))) + args + indent))) + (unless (string= formatted-args "") + (mapconcat 'identity (list "Keyword Arguments:" formatted-args) indent)))) + +(add-hook 'python-mode-hook + '(lambda () (set (make-local-variable 'yas-indent-line) 'fixed))) -- cgit v1.3