Auto-add docstrings by entering the newline when it's needed.
- Package Control
- AutoDocstring
-
Select
Sublime Text
->Preferences
->Key Bindings
-
Add the following json chunk:
{ "keys": ["enter"], "command": "auto_docstring", "context": [ { "key": "preceding_text", "operator": "regex_match", "operand": "^ *(def .*\\).*:|class .*:|[^\\(\\n]*\\).*:)", "match_all": true }, { "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true }, { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }, { "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true }, { "key": "selector", "operator": "equal", "operand": "source.python" }, ] },
- The regexp pattern is inspired from the comment from
@Damodar Bashyal
in the [Stack Overflow] Regular expression to match a line that doesn't contain a word. - If you don't want to add docstrings in some cases, you can simply insert a newline with the built-in command
⌘ + enter
.