mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
Fixed textmate_import.rb slightly and added doc for it
This commit is contained in:
parent
81857aea6d
commit
01205f79d6
@ -3,7 +3,7 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
|
||||
<meta name="generator" content="Docutils 0.6: http://docutils.sourceforge.net/" />
|
||||
<title>Yet Another Snippet extension</title>
|
||||
<link rel="stylesheet" href="styles.css" type="text/css" />
|
||||
</head>
|
||||
@ -60,14 +60,14 @@
|
||||
<li><a class="reference internal" href="#bugs-contribution-and-support" id="id6">Bugs, Contribution and Support</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<p>YASnippet is a template system for Emacs. It allows you to type a
|
||||
<p><strong>YASnippet</strong> is a template system for Emacs. It allows you to type a
|
||||
abbreviation and automatically expand the abbreviation into function
|
||||
templates.</p>
|
||||
<p>Bundled language templates includes: C, C++, C#, Perl, Python, Ruby,
|
||||
SQL, LaTeX, HTML, CSS and more.</p>
|
||||
<p>YASnippet system is inspired from TextMate's template system. You can
|
||||
use <a class="reference external" href="https://groups.google.com/group/smart-snippet/browse_thread/thread/691fbdd33412d86e?pli=1">a tool</a>
|
||||
to import any TextMate template you have to YASnippet.</p>
|
||||
<p>The snippet syntax is inspired from TextMate's syntax, you can
|
||||
even <a class="reference external" href="snippet-development.html#importing-textmate-snippets">import</a>
|
||||
import most TextMate templates to YASnippet.</p>
|
||||
<p>YASnippet is a re-write of the extension <a class="reference external" href="http://code.google.com/p/smart-snippet/">smart-snippet</a>. Both are
|
||||
original creations of <a class="reference external" href="http://pluskid.lifegoo.org">pluskid</a>.</p>
|
||||
<div class="section" id="video-demo">
|
||||
|
@ -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
|
||||
<http://yasnippet.googlecode.com/svn/trunk/textmate-import.rb> to
|
||||
The snippet syntax is inspired from TextMate's syntax, you can
|
||||
even `import <snippet-development.html#importing-textmate-snippets>`_
|
||||
import most TextMate templates to YASnippet.
|
||||
|
||||
YASnippet is a re-write of the extension `smart-snippet`_. Both are
|
||||
|
@ -3,7 +3,7 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
|
||||
<meta name="generator" content="Docutils 0.6: http://docutils.sourceforge.net/" />
|
||||
<title>Writing snippets</title>
|
||||
<link rel="stylesheet" href="styles.css" type="text/css" />
|
||||
</head>
|
||||
@ -60,8 +60,8 @@
|
||||
<li><a class="reference internal" href="#name-snippet-name" id="id8"><tt class="docutils literal"><span class="pre">#</span> <span class="pre">name:</span></tt> snippet name</a></li>
|
||||
<li><a class="reference internal" href="#condition-snippet-condition" id="id9"><tt class="docutils literal"><span class="pre">#</span> <span class="pre">condition:</span></tt> snippet condition</a></li>
|
||||
<li><a class="reference internal" href="#expand-env-expand-environment" id="id10"><tt class="docutils literal"><span class="pre">#</span> <span class="pre">expand-env:</span></tt> expand environment</a></li>
|
||||
<li><a class="reference internal" href="#binding-direct-keybinding" id="id11"><tt class="docutils literal"><span class="pre">#</span> <span class="pre">binding:</span></tt>: direct keybinding</a></li>
|
||||
<li><a class="reference internal" href="#contributor-snippet-author" id="id12"><tt class="docutils literal"><span class="pre">#</span> <span class="pre">contributor:</span></tt>: snippet author</a></li>
|
||||
<li><a class="reference internal" href="#binding-direct-keybinding" id="id11"><tt class="docutils literal"><span class="pre">#</span> <span class="pre">binding:</span></tt> direct keybinding</a></li>
|
||||
<li><a class="reference internal" href="#contributor-snippet-author" id="id12"><tt class="docutils literal"><span class="pre">#</span> <span class="pre">contributor:</span></tt> snippet author</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference internal" href="#template-syntax" id="id13">Template syntax</a><ul>
|
||||
@ -89,6 +89,7 @@
|
||||
<li><a class="reference internal" href="#yas-after-exit-snippet-hook-and-yas-before-expand-snippet-hook" id="id33"><tt class="docutils literal"><span class="pre">yas/after-exit-snippet-hook</span></tt> and <tt class="docutils literal"><span class="pre">yas/before-expand-snippet-hook</span></tt></a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference internal" href="#importing-textmate-snippets" id="id34">Importing TextMate snippets</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="snippet-development">
|
||||
@ -233,7 +234,7 @@ your hard work. You can then use:</p>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="section" id="binding-direct-keybinding">
|
||||
<h2><a class="toc-backref" href="#id11"><tt class="docutils literal"><span class="pre">#</span> <span class="pre">binding:</span></tt>: direct keybinding</a></h2>
|
||||
<h2><a class="toc-backref" href="#id11"><tt class="docutils literal"><span class="pre">#</span> <span class="pre">binding:</span></tt> direct keybinding</a></h2>
|
||||
<p>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 <tt class="docutils literal"><span class="pre">yas/kill-
|
||||
undefine all the keybindings.</p>
|
||||
</div>
|
||||
<div class="section" id="contributor-snippet-author">
|
||||
<h2><a class="toc-backref" href="#id12"><tt class="docutils literal"><span class="pre">#</span> <span class="pre">contributor:</span></tt>: snippet author</a></h2>
|
||||
<h2><a class="toc-backref" href="#id12"><tt class="docutils literal"><span class="pre">#</span> <span class="pre">contributor:</span></tt> snippet author</a></h2>
|
||||
<p>This is optional and has no effect whatsoever on snippet
|
||||
functionality, but it looks nice.</p>
|
||||
</div>
|
||||
@ -536,10 +537,46 @@ the next field.</p>
|
||||
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.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="importing-textmate-snippets">
|
||||
<h1><a class="toc-backref" href="#id34">Importing TextMate snippets</a></h1>
|
||||
<p>There are a couple of tools that take TextMate's ".tmSnippet" xml
|
||||
files and create YASnippet definitions:</p>
|
||||
<blockquote>
|
||||
<ul class="simple">
|
||||
<li><a class="reference external" href="http://code.nokrev.com/?p=snippet-copier.git;a=blob_plain;f=snippet_copier.py">a python script by Jeff Wheeler</a></li>
|
||||
<li>a <a class="reference external" href="http://yasnippet.googlecode.com/svn/trunk/extras/textmate_import.rb">ruby tool</a>
|
||||
, <tt class="docutils literal"><span class="pre">textmate_import.rb</span></tt> adapted from <a class="reference external" href="http://www.neutronflux.net/2009/07/28/shoulda-snippets-for-emacs/">Rob Christie's</a>,
|
||||
which I have uploaded to the repository.</li>
|
||||
</ul>
|
||||
</blockquote>
|
||||
<p>In this section, i'll shortly cover the <strong>second</strong> option.</p>
|
||||
<p>Download the <tt class="docutils literal"><span class="pre">textmate_import.rb</span></tt> tool and the TextMate
|
||||
bundle you're interested in.</p>
|
||||
<div class="highlight"><pre>$ curl -O http://yasnippet.googlecode.com/svn/trunk/extras/textmate_import.rb
|
||||
$ svn export http://svn.textmate.org/trunk/Bundles/HTML.tmbundle/
|
||||
</pre></div>
|
||||
<p>Then invoke <tt class="docutils literal"><span class="pre">textmate_import.rb</span></tt> like this:</p>
|
||||
<div class="highlight"><pre>$ ./textmate_import.rb -d HTML.tmbundle/Snippets/ -o html-mode -g HTML.tmbundle/info.plist
|
||||
</pre></div>
|
||||
<p>You should end up with a <tt class="docutils literal"><span class="pre">html-mode</span></tt> subdir containing snippets
|
||||
exported from textmate.</p>
|
||||
<div class="highlight"><pre>$ tree html-mode # to view dir contents, if you have 'tree' installed
|
||||
</pre></div>
|
||||
<p>The <tt class="docutils literal"><span class="pre">-g</span></tt> is optional but helps the tool figure out the grouping.
|
||||
According to <a class="reference external" href="snippet-organization.html">Organizing Snippets</a>, don't forget to touch
|
||||
<tt class="docutils literal"><span class="pre">.yas-make-groups</span></tt> and <tt class="docutils literal"><span class="pre">.yas-ignore-filename-triggers</span></tt> inside the
|
||||
<tt class="docutils literal"><span class="pre">html-mode</span></tt> dir.</p>
|
||||
<p>Also try <tt class="docutils literal"><span class="pre">textmate_import.rb</span> <span class="pre">--help</span></tt> for a list of options.</p>
|
||||
<p>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 <tt class="docutils literal"><span class="pre">textmate_import.rb</span></tt> to automatically perform them and submit
|
||||
that.</p>
|
||||
<!-- LocalWords: html YASnippet yas sourcecode pluskid init filenames filename -->
|
||||
<!-- LocalWords: env varlist keybinding keymap rinari ifndef upcase endif -->
|
||||
<!-- LocalWords: nondirectory autorelease aValue inline -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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
|
||||
<http://code.nokrev.com/?p=snippet-copier.git;a=blob_plain;f=snippet_copier.py>`_
|
||||
|
||||
* a `ruby tool
|
||||
<http://yasnippet.googlecode.com/svn/trunk/extras/textmate_import.rb>`_
|
||||
, ``textmate_import.rb`` adapted from `Rob Christie's
|
||||
<http://www.neutronflux.net/2009/07/28/shoulda-snippets-for-emacs/>`_,
|
||||
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
|
||||
|
@ -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,18 +164,15 @@ if $0 == __FILE__
|
||||
puts "Will try to convert #{snippet_files.length} snippets...\n"
|
||||
|
||||
snippet_files.each do |file|
|
||||
begin
|
||||
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|
|
||||
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}"
|
||||
end
|
||||
else
|
||||
if Choice.choices.print_pretty
|
||||
puts "--------------------------------------------"
|
||||
@ -186,5 +183,8 @@ if $0 == __FILE__
|
||||
end
|
||||
puts "\n\n"
|
||||
end
|
||||
rescue Exception => e
|
||||
$stderr.puts "Oops... #{e.class}:#{e.message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user