Skip to content
Browse files

first commit

  • Loading branch information...
0 parents commit dd1ab20028abbcd25ac17d24dd1f06d346a9b34d @hoffmann committed Nov 26, 2010
Showing with 175 additions and 0 deletions.
  1. +21 −0 README.md
  2. +30 −0 export.py
  3. +124 −0 user.xml
21 README.md
@@ -0,0 +1,21 @@
+#About
+
+PyCharm lets you define live templates that expand a word into a snippet of
+code with some input fields. They work similar to textmate snippets and
+snipmate for vim.
+
+You can either add your on snippets via File/Settings/Live Templates or select
+a region and add the text with Tools/Save as Live Template.
+
+Live templates are stored in the following location:
+
+ Windows: <your home directory>\.<productname><versionnumber>\config\templates
+ Linux: ~\.<product name><version number>\config\templates
+ MacOS: ~/Library/Preferences/<product name><version number>/templates
+
+If you have not defined any user templates yet, you can copy the user.xml to
+the templates location, otherwise you have to merge the files or add the
+templates by hand.
+
+See http://peter-hoffmann.com/2010/python-live-templates-for-pycharm.html for
+more information.
30 export.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+"""Export Pycharm templates to html"""
+import sys
+import lxml.etree
+import os.path
+import cgi
+
+def export(filename):
+ tree = lxml.etree.parse(open(filename))
+ print '<dl>'
+ for template in tree.findall('.//template'):
+
+ print '<dt>%s</dt>' %(cgi.escape(template.get('name')))
+ print '<dd>%s\n<pre class="prettyprint">%s\n</pre>\n</dd>\n' %(template.get('description'), template.get('value'))
+ print '</dl>'
+
+
+def main(argv=None):
+ if argv is None:
+ argv = sys.argv
+
+ user_xml_file = os.path.expanduser('~/.PyCharm10/config/templates/user.xml')
+ if len(argv) == 2:
+ user_xml_file = argv[1]
+
+ export(user_xml_file)
+
+if __name__ == '__main__':
+ main()
+
124 user.xml
@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<templateSet group="user">
+ <template name="class" value="class $class$($object$):&#10; &quot;&quot;&quot;$cls_doc$&quot;&quot;&quot;&#10; &#10; def __init__(self, $args$):&#10; &quot;&quot;&quot;Constructor for $class$&quot;&quot;&quot;&#10; $END$&#10; &#10;" description="Python Class Template" toReformat="false" toShortenFQNames="true">
+ <variable name="class" expression="" defaultValue="" alwaysStopAt="true" />
+ <variable name="object" expression="" defaultValue="object" alwaysStopAt="true" />
+ <variable name="cls_doc" expression="" defaultValue="" alwaysStopAt="true" />
+ <variable name="args" expression="" defaultValue="" alwaysStopAt="true" />
+ <context>
+ <option name="HTML_TEXT" value="false" />
+ <option name="HTML" value="false" />
+ <option name="XSL_TEXT" value="false" />
+ <option name="XML" value="false" />
+ <option name="Python" value="true" />
+ <option name="Django" value="false" />
+ <option name="CSS" value="false" />
+ <option name="JAVA_SCRIPT" value="false" />
+ <option name="OTHER" value="false" />
+ </context>
+ </template>
+ <template name="init" value="def __init__(self, $args$):&#10; &quot;&quot;&quot;$doc$&quot;&quot;&quot;&#10; $END$&#10; " description="init function" toReformat="false" toShortenFQNames="true">
+ <variable name="args" expression="" defaultValue="" alwaysStopAt="true" />
+ <variable name="doc" expression="" defaultValue="" alwaysStopAt="true" />
+ <context>
+ <option name="HTML_TEXT" value="false" />
+ <option name="HTML" value="false" />
+ <option name="XSL_TEXT" value="false" />
+ <option name="XML" value="false" />
+ <option name="Python" value="true" />
+ <option name="Django" value="false" />
+ <option name="CSS" value="false" />
+ <option name="JAVA_SCRIPT" value="false" />
+ <option name="OTHER" value="false" />
+ </context>
+ </template>
+ <template name="def" value="def $fnname$($args$):&#10; &quot;&quot;&quot;$docstring$&#10; &#10; Args:&#10; $args$&#10; &#10; Returns:&#10; $return_value$&#10; &quot;&quot;&quot;&#10; $END$" description="function definition" toReformat="false" toShortenFQNames="true">
+ <variable name="fnname" expression="" defaultValue="" alwaysStopAt="true" />
+ <variable name="args" expression="" defaultValue="" alwaysStopAt="true" />
+ <variable name="docstring" expression="" defaultValue="" alwaysStopAt="true" />
+ <variable name="return_value" expression="" defaultValue="" alwaysStopAt="true" />
+ <context>
+ <option name="HTML_TEXT" value="false" />
+ <option name="HTML" value="false" />
+ <option name="XSL_TEXT" value="false" />
+ <option name="XML" value="false" />
+ <option name="Python" value="true" />
+ <option name="Django" value="false" />
+ <option name="CSS" value="false" />
+ <option name="JAVA_SCRIPT" value="false" />
+ <option name="OTHER" value="false" />
+ </context>
+ </template>
+ <template name="se" value="self.$var$ = $var$&#10;$END$" description="set instance variable" toReformat="false" toShortenFQNames="true">
+ <variable name="var" expression="" defaultValue="" alwaysStopAt="true" />
+ <context>
+ <option name="HTML_TEXT" value="false" />
+ <option name="HTML" value="false" />
+ <option name="XSL_TEXT" value="false" />
+ <option name="XML" value="false" />
+ <option name="Python" value="true" />
+ <option name="Django" value="false" />
+ <option name="CSS" value="false" />
+ <option name="JAVA_SCRIPT" value="false" />
+ <option name="OTHER" value="false" />
+ </context>
+ </template>
+ <template name="from" value="from $module$ import $name$&#10;$END$" description="from module import name" toReformat="false" toShortenFQNames="true">
+ <variable name="module" expression="" defaultValue="" alwaysStopAt="true" />
+ <variable name="name" expression="" defaultValue="" alwaysStopAt="true" />
+ <context>
+ <option name="HTML_TEXT" value="false" />
+ <option name="HTML" value="false" />
+ <option name="XSL_TEXT" value="false" />
+ <option name="XML" value="false" />
+ <option name="Python" value="true" />
+ <option name="Django" value="false" />
+ <option name="CSS" value="false" />
+ <option name="JAVA_SCRIPT" value="false" />
+ <option name="OTHER" value="false" />
+ </context>
+ </template>
+ <template name="pf" value="print &quot;$string$&quot;.format($args$)&#10;$END$" description="print formatted string" toReformat="false" toShortenFQNames="true">
+ <variable name="string" expression="" defaultValue="" alwaysStopAt="true" />
+ <variable name="args" expression="" defaultValue="" alwaysStopAt="true" />
+ <context>
+ <option name="HTML_TEXT" value="false" />
+ <option name="HTML" value="false" />
+ <option name="XSL_TEXT" value="false" />
+ <option name="XML" value="false" />
+ <option name="Python" value="true" />
+ <option name="Django" value="false" />
+ <option name="CSS" value="false" />
+ <option name="JAVA_SCRIPT" value="false" />
+ <option name="OTHER" value="false" />
+ </context>
+ </template>
+ <template name="prop" value="$property$ = property(get_$property$, set_$property$)&#10;$END$" description="property" toReformat="false" toShortenFQNames="true">
+ <variable name="property" expression="" defaultValue="" alwaysStopAt="true" />
+ <context>
+ <option name="HTML_TEXT" value="false" />
+ <option name="HTML" value="false" />
+ <option name="XSL_TEXT" value="false" />
+ <option name="XML" value="false" />
+ <option name="Python" value="true" />
+ <option name="Django" value="false" />
+ <option name="CSS" value="false" />
+ <option name="JAVA_SCRIPT" value="false" />
+ <option name="OTHER" value="false" />
+ </context>
+ </template>
+ <template name="main" value="def main(argv):&#10; if argv is None:&#10; argv = sys.argv&#10; $END$&#10;&#10;if __name__ == &quot;__main__&quot;:&#10; main()" description="if __name__ = &quot;__main__&quot;:" toReformat="false" toShortenFQNames="true">
+ <context>
+ <option name="HTML_TEXT" value="false" />
+ <option name="HTML" value="false" />
+ <option name="XSL_TEXT" value="false" />
+ <option name="XML" value="false" />
+ <option name="Python" value="true" />
+ <option name="Django" value="false" />
+ <option name="CSS" value="false" />
+ <option name="JAVA_SCRIPT" value="false" />
+ <option name="OTHER" value="false" />
+ </context>
+ </template>
+</templateSet>
+

0 comments on commit dd1ab20

Please sign in to comment.
Something went wrong with that request. Please try again.