Mercurial > hg > dotemacs
annotate elpa/elpy-1.26.0/snippets/python-mode/.yas-setup.el @ 183:3de719fb264a
elpy: version 1.26
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Wed, 21 Nov 2018 14:39:16 -0500 |
parents | elpa/elpy-1.25.0/snippets/python-mode/.yas-setup.el@c3bd84985977 |
children |
rev | line source |
---|---|
98 | 1 (defun elpy-snippet-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 elpy-snippet-current-method-and-args () | |
8 "Return information on the current definition." | |
9 (let ((current-defun (python-info-current-defun)) | |
10 (current-arglist | |
11 (save-excursion | |
12 (python-nav-beginning-of-defun) | |
13 (when (re-search-forward "(" nil t) | |
14 (let* ((start (point)) | |
15 (end (progn | |
16 (forward-char -1) | |
17 (forward-sexp) | |
18 (- (point) 1)))) | |
19 (elpy-snippet-split-args | |
20 (buffer-substring-no-properties start end)))))) | |
21 class method args) | |
22 (when (not current-arglist) | |
23 (setq current-arglist '(("self")))) | |
24 (if (and current-defun | |
25 (string-match "^\\(.*\\)\\.\\(.*\\)$" current-defun)) | |
26 (setq class (match-string 1 current-defun) | |
27 method (match-string 2 current-defun)) | |
28 (setq class "Class" | |
29 method "method")) | |
30 (setq args (mapcar #'car current-arglist)) | |
31 (list class method args))) | |
32 | |
33 (defun elpy-snippet-init-assignments (arg-string) | |
34 "Return the typical __init__ assignments for arguments." | |
35 (let ((indentation (make-string (save-excursion | |
36 (goto-char start-point) | |
37 (current-indentation)) | |
38 ?\s))) | |
39 (mapconcat (lambda (arg) | |
40 (if (string-match "^\\*" (car arg)) | |
41 "" | |
42 (format "self.%s = %s\n%s" | |
43 (car arg) | |
44 (car arg) | |
45 indentation))) | |
46 (elpy-snippet-split-args arg-string) | |
47 ""))) | |
48 | |
49 (defun elpy-snippet-super-form () | |
152
55ceabc58fcc
elpy: upgrade to 1.12
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
126
diff
changeset
|
50 "Return (Class, first-arg).method if Py2. |
55ceabc58fcc
elpy: upgrade to 1.12
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
126
diff
changeset
|
51 Else return ().method for Py3." |
98 | 52 (let* ((defun-info (elpy-snippet-current-method-and-args)) |
53 (class (nth 0 defun-info)) | |
54 (method (nth 1 defun-info)) | |
55 (args (nth 2 defun-info)) | |
152
55ceabc58fcc
elpy: upgrade to 1.12
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
126
diff
changeset
|
56 (first-arg (nth 0 args)) |
55ceabc58fcc
elpy: upgrade to 1.12
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
126
diff
changeset
|
57 (py-version-command " -c 'import sys ; print(sys.version_info.major)'") |
55ceabc58fcc
elpy: upgrade to 1.12
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
126
diff
changeset
|
58 ;; Get the python version. Either 2 or 3 |
55ceabc58fcc
elpy: upgrade to 1.12
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
126
diff
changeset
|
59 (py-version-num (substring (shell-command-to-string (concat elpy-rpc-python-command py-version-command))0 1))) |
55ceabc58fcc
elpy: upgrade to 1.12
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
126
diff
changeset
|
60 (if (string-match py-version-num "2") |
55ceabc58fcc
elpy: upgrade to 1.12
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
126
diff
changeset
|
61 (format "(%s, %s).%s" class first-arg method) |
55ceabc58fcc
elpy: upgrade to 1.12
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
126
diff
changeset
|
62 (format "().%s" method)))) |
98 | 63 |
64 (defun elpy-snippet-super-arguments () | |
65 "Return the argument list for the current method." | |
66 (mapconcat (lambda (x) x) | |
67 (cdr (nth 2 (elpy-snippet-current-method-and-args))) | |
68 ", ")) |