TextMate中的^ H用’Tidy’HTML导致NoMethodError

昨天我第一次尝试在HTML文档中使用’Tidy’,并得到了……

/tmp/temp_textmate.Z2P0KX:30:in `': undefined method `empty?' for nil:NilClass (NoMethodError) 

我没有对包中的代码做任何事情……

 #!/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  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?("
") in_pre = false if line.include?("

") end end

问题是unless log.empty?

我在OS X 10.6.6上运行TextMate 1.5.10(1631)。 我最近安装了rvm并将默认Ruby升级到1.9.2,虽然强制TextMate使用1.8.7并没有解决问题。

我有同样的问题。 我已经设置了我的Textmate以使用ruby的RVM版本,以便我可以快速测试脚本。

我通过取消选中我创建的环境变量的“TM_RUBY”解决了这个问题。

似乎正在发生的是包含/ usr / bin / tidy命令的Textmate脚本在使用除OSX附带的ruby版本之外的其他ruby版本时未正确执行。

我很想知道Lion出来后会发生什么。 希望Textmate能够再看一下这些内置脚本并给它们一些“粉尘”。

如果你看一下log的作业,你会看到:

 log = File.read('/tmp/tm_tidy_errors').to_a.select do |line| ... end.join rescue nil 

如果/tmp/tm_tidy_errors文件不存在或者无法读取或者什么都rescue nil ,那么最后的rescue nil会将nil写入log 。 然后脚本会调用.empty? nil方法,但是nil对象没有这样的方法,脚本会崩溃并死掉。

您可以通过将rescue nil更改为rescue ''或通过更改unless log.empty? unless log.nil? || log.empty? unless log.nil? || log.empty? 但这可能不是真正的问题。

您是否设置了TM_TIDY环境变量? 你的PATH有一个tidy命令吗? 看起来你的Tidy安装不对(或者根本不可能)。 我的OSX有/usr/bin/tidy ,显然这是标准的。 尝试在终端中手动运行那个大tidy命令,看看会发生什么。

我也有同样的问题,在运行OS X 10.9.5的机器上,Ruby升级到ruby 2.0.0。 通过采取mu太短的建议来修复它, unless log.empty? unless long.nil? || log.empty? unless long.nil? || log.empty? 。 这使得Tidy能够正常运行,但我的HTML选择的顶部仍然显示我烦人的错误:

 ruby: warning: -K is specified; it is for 1.8 compatibility and may cause odd behavior /Applications/TextMate.app/Contents/SharedSupport/Support/lib/ui.rb:129: warning: assigned but unused variable - pid 

我通过将脚本的第一行从#!/usr/bin/env ruby -wKU#!/usr/bin/env ruby -wKU -W0 。 显然问题仍然存在,但是对于有用但不重要的东西,正如这个function一样,我认为它足够好了。