├── README.md ├── export.py └── user.xml /README.md: -------------------------------------------------------------------------------- 1 | #About 2 | 3 | PyCharm lets you define live templates that expand a word into a snippet of 4 | code with some input fields. They work similar to textmate snippets and 5 | snipmate for vim. 6 | 7 | You can either add your on snippets via File/Settings/Live Templates or select 8 | a region and add the text with Tools/Save as Live Template. 9 | 10 | Live templates are stored in the following location: 11 | 12 | Windows: \.\config\templates 13 | Linux: ~\.\config\templates 14 | MacOS: ~/Library/Preferences//templates 15 | 16 | ## Example 17 | 18 | MacOS, PyCharm 3 19 | 20 | ``` 21 | git clone git@github.com:hoffmann/PyCharm-Python-Templates.git 22 | cp PyCharm-Python-Templates/user.xml ~/Library/Preferences/PyCharm30/templates/ 23 | ``` 24 | 25 | You could also copy/paste the template XML to the `Python.xml` file but that's more work. 26 | 27 | If you have not defined any user templates yet, you can copy the user.xml to 28 | the templates location, otherwise you have to merge the files or add the 29 | templates by hand. 30 | 31 | See http://peter-hoffmann.com/2010/python-live-templates-for-pycharm.html for 32 | more information. 33 | 34 | 35 | ## How to use 36 | 37 | Now you should be able to type "fnpdoc``", meaning you type the letters "fnpdoc" and then press the button `` and it will fill the live template, in this case with the numpy docstring template for a function. Visually, 38 | 39 | fnpdoc 40 | 41 | will become: 42 | 43 | Parameters 44 | ---------- 45 | 46 | 47 | Returns 48 | ------- 49 | 50 | 51 | Raises 52 | ------ 53 | -------------------------------------------------------------------------------- /export.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Export Pycharm templates to html""" 3 | import sys 4 | import lxml.etree 5 | import os.path 6 | import cgi 7 | 8 | 9 | def export(filename): 10 | tree = lxml.etree.parse(open(filename)) 11 | print '
' 12 | for template in tree.findall('.//template'): 13 | print '
%s
' % (cgi.escape(template.get('name'))) 14 | print '
%s\n
%s\n
\n
\n' % 15 | (template.get('description'), template.get('value')) 16 | print '
' 17 | 18 | 19 | def main(argv=None): 20 | if argv is None: 21 | argv = sys.argv 22 | 23 | user_xml_file = os.path.expanduser( 24 | '~/.PyCharm30/config/templates/user.xml' 25 | ) 26 | if len(argv) == 2: 27 | user_xml_file = argv[1] 28 | 29 | export(user_xml_file) 30 | 31 | if __name__ == '__main__': 32 | main() 33 | -------------------------------------------------------------------------------- /user.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 39 | 56 | 75 | 91 | 108 | 125 | 141 | 156 | 172 | 188 | 202 | 224 | 239 | 258 | 274 | 290 | 307 | 324 | 341 | 356 | 371 | 388 | 405 | 420 | 435 | 450 | 468 | 469 | --------------------------------------------------------------------------------