Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
105 lines (93 sloc) 3.04 KB
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>bundleUUID</key>
<string>F80D3822-6EE8-11D9-BF2D-000D93589AF6</string>
<key>command</key>
<string>#!/usr/bin/env ruby18
require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes"
require "#{ENV['TM_SUPPORT_PATH']}/lib/escape"
line = STDIN.read
def candidates_or_exit(methodSearch="")
zGrepped = %x{ zgrep ^#{e_sh methodSearch } #{e_sh ENV['TM_BUNDLE_SUPPORT']}/OCamlSnippets.txt.gz }
candidates = zGrepped.split("\n")
TextMate.exit_show_tool_tip "No completion available" if candidates.empty?
return candidates
end
def prettify(candidate)
candidate.gsub(/\$\{\d+:|\}|\$0/,"")
end
def snippet_generator(cand, start)
cand[start..-1]
end
def pop_up(candidates, searchTerm)
start = searchTerm.size
prettyCandidates = candidates.map { |candidate| [prettify(candidate), candidate] }.sort
if prettyCandidates.size &gt; 1
require "enumerator"
pruneList = []
prettyCandidates.each_cons(2) do |a|
pruneList &lt;&lt; (a[0][0] != a[1][0]) # check if prettified versions are the same
end
pruneList &lt;&lt; true
ind = -1
prettyCandidates = prettyCandidates.select do |a| #remove duplicates
pruneList[ind+=1]
end
end
if prettyCandidates.size &gt; 1
#index = start
#test = false
#while !test
# candidates.each_cons(2) do |a,b|
# break if test = (a[index].chr != b[index].chr || a[index].chr == "\t")
# end
# break if test
# searchTerm &lt;&lt; candidates[0][index].chr
# index +=1
#end
require "#{ENV['TM_SUPPORT_PATH']}/lib/osx/plist"
dialog_path = "#{ENV['TM_SUPPORT_PATH']}/bin/tm_dialog"
pl = {'menuItems' =&gt; prettyCandidates.map { |pretty, full | { 'title' =&gt; pretty, 'cand' =&gt; full} }}
plist = pl.to_plist
res = OSX::PropertyList::load(%x{ #{e_sh dialog_path} -up #{e_sh plist} })
if res.has_key? 'selectedMenuItem'
snippet_generator( res['selectedMenuItem']['cand'], start )
else
""
end
else
snippet_generator( candidates[0], start )
end
end
caret_placement =ENV['TM_LINE_INDEX'].to_i - 1
backContext = line[1+caret_placement..-1].match /^[a-zA-Z0-9_]/
if backContext
print line[0..caret_placement]+ "$0"+ line[caret_placement+1..-1]
TextMate.exit_discard
end
alpha_and_caret = /[a-zA-Z_][_a-zA-Z0-9]*\(?$/
if k = line[0..caret_placement].match(alpha_and_caret)
candidates = candidates_or_exit(k[0])
res = pop_up(candidates, k[0])
else
res = ""
end
print line[0..caret_placement] + res + "$0"+ line[caret_placement+1..-1]</string>
<key>input</key>
<string>selection</string>
<key>keyEquivalent</key>
<string>^~@</string>
<key>name</key>
<string>OCaml Completion - disabled</string>
<key>output</key>
<string>insertAsSnippet</string>
<key>scope</key>
<string>source.ocaml</string>
<key>uuid</key>
<string>C6EBDA90-DEEF-43B8-BE1C-78759877BA35</string>
</dict>
</plist>
Jump to Line
Something went wrong with that request. Please try again.