Module: Castanaut::Plugin::Textmate

Defined in:
lib/plugins/textmate.rb

Overview

Modified by Brian Hogan www.napcs.com/

Instance Method Summary collapse

Instance Method Details

#tm_insert_text(text, as_snippet = false) ⇒ Object

Types text into TextMate all at once.

The as_snippet option is documented but doesn’t seem to do anything.



17
18
19
20
21
22
23
24
25
26
# File 'lib/plugins/textmate.rb', line 17

def tm_insert_text(text, as_snippet=false)
  escaped_text = text.gsub(/"/, '\"')
  snippet_directive = (as_snippet ? "with as snippet" : "")

  execute_applescript(%Q`
    tell application "TextMate"
      insert "#{escaped_text}" #{snippet_directive}
    end
  `)
end

#tm_move_to(line = 0, column = 0) ⇒ Object

Position the cursor at the given coordinates.



40
41
42
43
44
45
46
47
48
# File 'lib/plugins/textmate.rb', line 40

def tm_move_to(line=0, column=0)
  full_url = "txmt://open?line=#{line}&column=#{column}"

  execute_applescript(%Q`
    tell application "TextMate"
      get url "#{full_url}"
    end
  `)
end

#tm_new_file(file) ⇒ Object

Create a new file on the filesystem and open it in textmate.



51
52
53
54
55
56
57
58
59
60
# File 'lib/plugins/textmate.rb', line 51

def tm_new_file(file)
  execute_applescript(%Q`
      do shell script "touch #{file}"
      tell application "TextMate"
        activate
      end
  `)

  tm_open_file(file)
end

#tm_open_file(file_path, line = 0, column = 0) ⇒ Object

Open a file, optionally at a specific line and column.



30
31
32
33
34
35
36
37
# File 'lib/plugins/textmate.rb', line 30

def tm_open_file(file_path, line=0, column=0)
  full_url = "txmt://open?url=file://#{file_path}&line=#{line}&column=#{column}"
  execute_applescript(%Q`
    tell application "TextMate"
      get url "#{full_url}"
    end
  `)
end