diff --git a/Commands/Tidy.plist b/Commands/Tidy.plist
index f6c3590..1fb5028 100644
--- a/Commands/Tidy.plist
+++ b/Commands/Tidy.plist
@@ -9,26 +9,63 @@
capturePattern
line (\d+) column (\d+) - (.*?)$
command
- "${TM_TIDY:-tidy}" -f /dev/null -iq -utf8 \
- -wrap 0 --tab-size $TM_TAB_SIZE --indent-spaces $TM_TAB_SIZE \
- ${TM_SELECTED_TEXT:+--show-body-only yes} \
- ${TM_XHTML:+-asxhtml} \
- --doctype strict \
- --enclose-text yes \
- --tidy-mark no|\
-if [[ "$TM_SOFT_TABS" == "YES" ]]; then cat; else ruby -pe '
-
- unless $in_pre
- tab_size = ENV["TM_TAB_SIZE"].to_i
- space, text = /( *)(.*)/m.match($_)[1..2]
- $_ = "\t" * (space.length / tab_size).floor +
- " " * (space.length % tab_size) + text
- end
-
- $in_pre = true if(/<pre>/)
- $in_pre = false if(/<\/pre>/)
- '
-fi
+ #!/usr/bin/env ruby -wKU
+
+require ENV['TM_SUPPORT_PATH'] + '/lib/ui.rb'
+require ENV['TM_SUPPORT_PATH'] + '/lib/exit_codes.rb'
+
+result = `"${TM_TIDY:-tidy}" -f /tmp/tm_tidy_errors -iq -utf8 \
+ -wrap 0 --tab-size $TM_TAB_SIZE --indent-spaces $TM_TAB_SIZE \
+ --indent yes \
+ ${TM_XHTML:+-asxhtml --output-xhtml yes} \
+ ${TM_SELECTED_TEXT:+--show-body-only yes} \
+ --enclose-text yes \
+ --doctype strict \
+ --wrap-php no \
+ --tidy-mark no`
+status = $?.exitstatus
+
+at_exit { File.unlink('/tmp/tm_tidy_errors') } # Clean up error log
+
+if status == 2 # Errors
+
+ msg = "Errors: " + File.read('/tmp/tm_tidy_errors')
+ TextMate.exit_show_tool_tip msg
+
+elsif status == 1 # Warnings - use output but also display notification with warnings
+
+ log = File.read('/tmp/tm_tidy_errors').to_a.select do |line|
+ ! (ENV['TM_SELECTED_TEXT'] and (line.include?('Warning: missing <!DOCTYPE> declaration') or line.include?("Warning: inserting missing 'title' element")))
+ end.join rescue nil
+
+ unless log.empty?
+ options = {
+ :title => "Tidy Warnings",
+ :summary => "Warnings for tidying your document (press escape to close):",
+ :log => log
+ }
+ TextMate::UI.simple_notification(options)
+ end
+
+end
+
+if ENV['TM_SOFT_TABS'] == "YES"
+ print result
+else
+ in_pre = false
+ result.each_line do |line|
+ unless in_pre
+ tab_size = ENV["TM_TAB_SIZE"].to_i
+ space, text = /( *)(.*)/m.match(line)[1..2]
+ line = "\t" * (space.length / tab_size).floor + " " * (space.length % tab_size) + text
+ end
+
+ print line
+
+ in_pre = true if line.include?("<pre>")
+ in_pre = false if line.include?("</pre>")
+ end
+end
input
selection
keyEquivalent