user1010892
user1010892

Reputation: 1189

aptana studio 3 - snippets and key commands

I've seen that you can create snippets which as far as I understand are almost like code complete - in that you start typing something and it brings up your snippet.

http://wiki.appcelerator.org/display/tis/Creating+a+new+snippet

Firstly where is the "existing bundle.rb file"?

Secondly, if I wanted to add html tags around text, is there a way to do this? For example, highlight a few lines of text and add

or tags around it? Or even at the beginning and

at the end.

much appreciated.

Upvotes: 1

Views: 2887

Answers (2)

user2684124
user2684124

Reputation: 11

Actually, the built-in Ctrl-Shift-Command+W binding will allow you to surround the highlighted text with any tag you want. It just defaults to <p>[Highlighted text]</p>. If you start typing after hitting the shortcut, it will replace the "p" in both tags with whatever you type, until you hit return or an arrow key.

Upvotes: 1

Ingo Muschenetz
Ingo Muschenetz

Reputation: 3352

Follow the instructions in the note in the linked wiki page to create a new ruble. That will create a project in your workspace. Inside that folder you will find a bundle.rb file (or alternately, there is also a snippets.rb file in that new project you can use as well with an example snippet already created)

As to inserting items around a selection, yes. In that case, I would use a command, since it's a little easier to trigger. You'd make a selection, and then use a key shortcut or menu command to trigger it. An example below:

require 'ruble'

command 'Wrap' do |cmd|
  cmd.key_binding = 'CONTROL+SHIFT+COMMAND+W'
  cmd.output = :insert_as_snippet
  cmd.input = :selection
  cmd.invoke do |context|
    input = STDIN.read
    input.gsub(/[\$`\\]/, '\\1').gsub(/([ \t]*)(.+)/, '\1<${1:li}>\2</${1:li}>')
  end
end

Note that this takes the current selection, wraps it in open/close tags, and re-inserts that as a snippet, suck that you can re-edit the open/close tags to your liking. If you didn't need that, you could make a simpler version:

require 'ruble'

command 'Wrap' do |cmd|
  cmd.key_binding = 'CONTROL+SHIFT+COMMAND+W'
  cmd.output = :replace_selection
  cmd.input = :selection
  cmd.invoke do |context|
    input = STDIN.read
    input.gsub(/[\$`\\]/, '\\1').gsub(/([ \t]*)(.+)/, '\1<li>\2</li>')
  end
end

Upvotes: 1

Related Questions