From 01205f79d6e8478b377c86b9e997f53f1b3fdc9d Mon Sep 17 00:00:00 2001 From: capitaomorte Date: Wed, 26 Aug 2009 13:06:00 +0000 Subject: [PATCH] Fixed textmate_import.rb slightly and added doc for it --- doc/index.html | 10 +++---- doc/index.rst | 7 ++--- doc/snippet-development.html | 49 +++++++++++++++++++++++++++---- doc/snippet-development.rst | 56 ++++++++++++++++++++++++++++++++++-- extras/textmate_import.rb | 50 ++++++++++++++++---------------- 5 files changed, 130 insertions(+), 42 deletions(-) diff --git a/doc/index.html b/doc/index.html index 6aaa8f4..820a2b0 100644 --- a/doc/index.html +++ b/doc/index.html @@ -3,7 +3,7 @@ - + Yet Another Snippet extension @@ -60,14 +60,14 @@
  • Bugs, Contribution and Support
  • -

    YASnippet is a template system for Emacs. It allows you to type a +

    YASnippet is a template system for Emacs. It allows you to type a abbreviation and automatically expand the abbreviation into function templates.

    Bundled language templates includes: C, C++, C#, Perl, Python, Ruby, SQL, LaTeX, HTML, CSS and more.

    -

    YASnippet system is inspired from TextMate's template system. You can -use a tool -to import any TextMate template you have to YASnippet.

    +

    The snippet syntax is inspired from TextMate's syntax, you can +even import +import most TextMate templates to YASnippet.

    YASnippet is a re-write of the extension smart-snippet. Both are original creations of pluskid.

    diff --git a/doc/index.rst b/doc/index.rst index 94a8cee..a236a61 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -9,16 +9,15 @@ Yet Another Snippet extension .. contents:: -YASnippet is a template system for Emacs. It allows you to type a +**YASnippet** is a template system for Emacs. It allows you to type a abbreviation and automatically expand the abbreviation into function templates. Bundled language templates includes: C, C++, C#, Perl, Python, Ruby, SQL, LaTeX, HTML, CSS and more. -YASnippet system is inspired from TextMate's template system. You can -use `a tool - to +The snippet syntax is inspired from TextMate's syntax, you can +even `import `_ import most TextMate templates to YASnippet. YASnippet is a re-write of the extension `smart-snippet`_. Both are diff --git a/doc/snippet-development.html b/doc/snippet-development.html index 96cf209..9d1b042 100644 --- a/doc/snippet-development.html +++ b/doc/snippet-development.html @@ -3,7 +3,7 @@ - + Writing snippets @@ -60,8 +60,8 @@
  • # name: snippet name
  • # condition: snippet condition
  • # expand-env: expand environment
  • -
  • # binding:: direct keybinding
  • -
  • # contributor:: snippet author
  • +
  • # binding: direct keybinding
  • +
  • # contributor: snippet author
  • Template syntax
  • +
  • Importing TextMate snippets
  • @@ -233,7 +234,7 @@ your hard work. You can then use:

    -

    # binding:: direct keybinding

    +

    # binding: direct keybinding

    You can use this directive to expand a snippet directly from a normal Emacs keybinding. The keybinding will be registered in the Emacs keymap named after the major mode the snippet is active @@ -264,7 +265,7 @@ active and the function yas/kill- undefine all the keybindings.

    -

    # contributor:: snippet author

    +

    # contributor: snippet author

    This is optional and has no effect whatsoever on snippet functionality, but it looks nice.

    @@ -536,10 +537,46 @@ the next field.

    snippet and after exiting the snippet. If you find any strange but functional use for them, that's probably a design flaw in YASnippet, so let us know.

    + + +
    +

    Importing TextMate snippets

    +

    There are a couple of tools that take TextMate's ".tmSnippet" xml +files and create YASnippet definitions:

    +
    + +
    +

    In this section, i'll shortly cover the second option.

    +

    Download the textmate_import.rb tool and the TextMate +bundle you're interested in.

    +
    $ curl -O http://yasnippet.googlecode.com/svn/trunk/extras/textmate_import.rb
    +$ svn export http://svn.textmate.org/trunk/Bundles/HTML.tmbundle/
    +
    +

    Then invoke textmate_import.rb like this:

    +
    $ ./textmate_import.rb -d HTML.tmbundle/Snippets/ -o html-mode -g HTML.tmbundle/info.plist
    +
    +

    You should end up with a html-mode subdir containing snippets +exported from textmate.

    +
    $ tree html-mode # to view dir contents, if you have 'tree' installed
    +
    +

    The -g is optional but helps the tool figure out the grouping. +According to Organizing Snippets, don't forget to touch +.yas-make-groups and .yas-ignore-filename-triggers inside the +html-mode dir.

    +

    Also try textmate_import.rb --help for a list of options.

    +

    Please note that snippet importation is not yet perfect. You'll +probably have some adjustments to some/many snippets. Please +contribute these adjustments to the google group or, better yet, patch +the textmate_import.rb to automatically perform them and submit +that.

    -
    diff --git a/doc/snippet-development.rst b/doc/snippet-development.rst index a8e3b66..554cd94 100644 --- a/doc/snippet-development.rst +++ b/doc/snippet-development.rst @@ -183,7 +183,7 @@ your hard work. You can then use: | | | | +--+-+--+ -``# binding:``: direct keybinding +``# binding:`` direct keybinding --------------------------------- You can use this directive to expand a snippet directly from a normal @@ -225,7 +225,7 @@ modes and it is hard to undefine them. In particular, the variable active and the function ``yas/kill-snippet-keybindings`` will try to undefine all the keybindings. -``# contributor:``: snippet author +``# contributor:`` snippet author --------------------------------------------------- This is optional and has no effect whatsoever on snippet @@ -590,6 +590,58 @@ snippet and after exiting the snippet. If you find any strange but functional use for them, that's probably a design flaw in YASnippet, so let us know. +Importing TextMate snippets +=========================== + +There are a couple of tools that take TextMate's ".tmSnippet" xml +files and create YASnippet definitions: + + * `a python script by Jeff Wheeler + `_ + + * a `ruby tool + `_ + , ``textmate_import.rb`` adapted from `Rob Christie's + `_, + which I have uploaded to the repository. + +In this section, i'll shortly cover the **second** option. + +Download the ``textmate_import.rb`` tool and the TextMate +bundle you're interested in. + +.. sourcecode:: text + + $ curl -O http://yasnippet.googlecode.com/svn/trunk/extras/textmate_import.rb + $ svn export http://svn.textmate.org/trunk/Bundles/HTML.tmbundle/ + + +Then invoke ``textmate_import.rb`` like this: + +.. sourcecode:: text + + $ ./textmate_import.rb -d HTML.tmbundle/Snippets/ -o html-mode -g HTML.tmbundle/info.plist + +You should end up with a ``html-mode`` subdir containing snippets +exported from textmate. + +.. sourcecode:: text + + $ tree html-mode # to view dir contents, if you have 'tree' installed + +The ``-g`` is optional but helps the tool figure out the grouping. +According to `Organizing Snippets`_, don't forget to touch +``.yas-make-groups`` and ``.yas-ignore-filename-triggers`` inside the +``html-mode`` dir. + +Also try ``textmate_import.rb --help`` for a list of options. + +Please note that snippet importation is not yet perfect. You'll +probably have some adjustments to some/many snippets. Please +contribute these adjustments to the google group or, better yet, patch +the ``textmate_import.rb`` to automatically perform them and submit +that. + .. LocalWords: html YASnippet yas sourcecode pluskid init filenames filename .. LocalWords: env varlist keybinding keymap rinari ifndef upcase endif .. LocalWords: nondirectory autorelease aValue inline diff --git a/extras/textmate_import.rb b/extras/textmate_import.rb index 56e181b..aa06979 100755 --- a/extras/textmate_import.rb +++ b/extras/textmate_import.rb @@ -134,19 +134,19 @@ class TmSnippet def to_yasnippet doc = "# -*- mode: snippet -*-\n" - doc << "#key: #{self.tab_trigger}\n" if self.tab_trigger - doc << "#contributor : Translated from TextMate Snippet\n" - doc << "#name : #{self.name}\n" + doc << "# key: #{self.tab_trigger}\n" if self.tab_trigger + doc << "# contributor: Translated from TextMate Snippet\n" + doc << "# name: #{self.name}\n" doc << "#" unless Choice.choices.convert_bindings - doc << "#binding : \"#{self.key_equivalent}\"\n" if self.key_equivalent + doc << "# binding: \"#{self.key_equivalent}\"\n" if self.key_equivalent doc << "# --\n" @@known_substitutions.each_pair { |k, v| self.content.gsub!(k,v) } doc << "#{self.content}" end - def yasnippet_dir(dir) - dir = File.join(dir,File.dirname(@file)) - dir = File.join(dir,group) if group + def yasnippet_file(basedir) + basedir = File.join(basedir,group) if group + File.join(basedir,@file).gsub(/#{File.extname(@file)}$/,".yasnippet") end end @@ -164,27 +164,27 @@ if $0 == __FILE__ puts "Will try to convert #{snippet_files.length} snippets...\n" snippet_files.each do |file| - puts "Processing \"#{File.join(Choice.choices.snippet_dir,file)}\"\n" - snippet = TmSnippet.new(file,info_plist) - if Choice.choices.output_dir - begin - dir_to_create = snippet.yasnippet_dir(File.join(original_dir, Choice.choices.output_dir)) - FileUtils.mkdir_p(dir_to_create) - File.open(File.join(dir_to_create,file_to_create), 'w') do |f| + begin + puts "Processing \"#{File.join(Choice.choices.snippet_dir,file)}\"\n" + snippet = TmSnippet.new(file,info_plist) + if Choice.choices.output_dir + file_to_create = snippet.yasnippet_file(File.join(original_dir, Choice.choices.output_dir)) + FileUtils.mkdir_p(File.dirname(file_to_create)) + File.open(file_to_create, 'w') do |f| f.write(snippet.to_yasnippet) end - rescue RuntimeError => e - $stderr.puts "Oops... #{e.class}:#{e.message}" + else + if Choice.choices.print_pretty + puts "--------------------------------------------" + end + puts snippet.to_yasnippet + if Choice.choices.print_pretty + puts "--------------------------------------------" + end + puts "\n\n" end - else - if Choice.choices.print_pretty - puts "--------------------------------------------" - end - puts snippet.to_yasnippet - if Choice.choices.print_pretty - puts "--------------------------------------------" - end - puts "\n\n" + rescue Exception => e + $stderr.puts "Oops... #{e.class}:#{e.message}" end end end