|
30 | 30 | "Tabulation width in Python files" |
31 | 31 | :group 'insert-docstring |
32 | 32 | ) |
| 33 | + |
33 | 34 | (defcustom insert-docstring--default-python-indentation |
34 | 35 | (make-string insert-docstring--python-tab-width ? ) |
35 | 36 | "Python indentation string" |
|
41 | 42 | "Regex to find the indentation of a function" |
42 | 43 | :group 'insert-docstring |
43 | 44 | ) |
| 45 | + |
44 | 46 | (defcustom insert-docstring--python-function-name-regex |
45 | 47 | (rx "def" (+ (or blank "\n")) |
46 | 48 | (group (+ (not whitespace))) |
|
54 | 56 | "Regex to find the string of arguments of a function" |
55 | 57 | :group 'insert-docstring |
56 | 58 | ) |
| 59 | + |
57 | 60 | (defcustom insert-docstring--python-function-end-regex |
58 | 61 | (rx ")" (* (not (any ":"))) ":") |
59 | 62 | "Regex to find the end of a function" |
60 | 63 | :group 'insert-docstring |
61 | 64 | ) |
62 | 65 |
|
| 66 | +(defcustom insert-docstring--blank-or-newline-regex |
| 67 | + (rx (+ (or blank "\n"))) |
| 68 | + "Regex to find blanks and newlines (used for trimming)" |
| 69 | + :group 'insert-docstring |
| 70 | + ) |
| 71 | + |
63 | 72 |
|
64 | 73 | (cl-defstruct insert-docstring--argument-data |
65 | 74 | "Data associated to a function argument." |
|
116 | 125 | "Parse the argument names contained in ARGUMENTS-STRING and |
117 | 126 | return them in a list." |
118 | 127 | (if (string-equal "" arguments-string) nil |
119 | | - (cl-remove-if |
| 128 | + (mapcar |
120 | 129 | (lambda (string) |
121 | | - (string-match-p (rx (or "[" "]")) string) |
| 130 | + "Remove default value if any and trim" |
| 131 | + (car (split-string string "=" t insert-docstring--blank-or-newline-regex)) |
122 | 132 | ) |
123 | | - (mapcar (lambda (single-argument-string) |
124 | | - (car (split-string single-argument-string ":" t |
125 | | - (rx (+ (or blank "\n"))))) |
126 | | - ) |
127 | | - (split-string arguments-string ",") |
128 | | - ) |
| 133 | + (cl-remove-if |
| 134 | + (lambda (string) |
| 135 | + "Match type data leftovers" |
| 136 | + (string-match-p (rx (or "[" "]")) string) |
| 137 | + ) |
| 138 | + (mapcar (lambda (single-argument-string) |
| 139 | + "Drop type data" |
| 140 | + (car (split-string single-argument-string ":")) |
| 141 | + ) |
| 142 | + (split-string arguments-string ",") |
| 143 | + ) |
| 144 | + ) |
129 | 145 | ) |
130 | 146 | ) |
131 | 147 | ) |
|
0 commit comments