Skip to content

Commit 1e047e0

Browse files
committed
Improve matching of excluded items during condensing
Use the parsed version of the document from TextMate to remove all comment types and exclude all string types from the condensing. Fixes textmate#4.
1 parent c978af8 commit 1e047e0

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

Commands/Copy Condensed SQL.tmCommand

+40-12
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,61 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
55
<key>beforeRunningCommand</key>
66
<string>nop</string>
77
<key>command</key>
8-
<string>#!/usr/bin/env perl
9-
$/=\0;$_=&lt;&gt;; # Read all input
8+
<string>#!/usr/bin/env ruby
109
11-
s/\s*\-\-.*$//g; # Strip comments
10+
res = STDIN.read
1211
13-
1while s@^(([^'"]*["'][^'"]*["'])*[^"']*)(\n+|\s{2,})@$1 @; # Compact whitespace
12+
# Remove extraneous scope xml
13+
res.gsub!(/&lt;(?!\/?(string|comment)\.)[^&gt;]*&gt;/, '')
1414
15-
# set defaultCStringEncoding to UTF-8 and open pbcopy
16-
open(PBCOPY, '|__CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 pbcopy');
17-
print PBCOPY; # Print the SQL to pbcopy
18-
close PBCOPY;
19-
print "Copied SQL to Clipboard";</string>
15+
# Remove comments
16+
res.gsub!(/&lt;comment\.[^&gt;]*&gt;[^&lt;]*?&lt;\/comment\.[^&gt;]*&gt;/, '')
17+
18+
# Compact whitespace, leaving strings alone
19+
res.gsub!(/(?:([^&lt;]+)|(&lt;string\.[^&gt;]*&gt;[^&lt;]*?&lt;\/string\.[^&gt;]*&gt;))/) {
20+
if $1
21+
out = $1
22+
out = out.gsub(/\n/, ' ')
23+
out = out.gsub(/\s{2,}/, ' ')
24+
elsif $2
25+
$2
26+
end
27+
}
28+
29+
# Remove string tags
30+
res.gsub!(/&lt;\/?string\.[^&gt;]*&gt;/, '')
31+
32+
# Un-encode entities
33+
res.gsub!(/&amp;amp;/, '&amp;')
34+
res.gsub!(/&amp;lt;/, '&lt;')
35+
36+
IO.popen('pbcopy', 'w') { |io| io &lt;&lt; res }
37+
38+
puts "Copied SQL to Clipboard"
39+
</string>
2040
<key>input</key>
2141
<string>selection</string>
42+
<key>inputFormat</key>
43+
<string>xml</string>
2244
<key>keyEquivalent</key>
2345
<string>~@C</string>
2446
<key>name</key>
2547
<string>Copy Condensed SQL</string>
26-
<key>output</key>
27-
<string>showAsTooltip</string>
48+
<key>outputCaret</key>
49+
<string>afterOutput</string>
50+
<key>outputFormat</key>
51+
<string>text</string>
52+
<key>outputLocation</key>
53+
<string>toolTip</string>
2854
<key>scope</key>
2955
<string>source.sql</string>
3056
<key>uuid</key>
3157
<string>37E7E7F5-DD1E-4306-B258-0F9176DC8D7E</string>
58+
<key>version</key>
59+
<integer>2</integer>
3260
</dict>
3361
</plist>

0 commit comments

Comments
 (0)