TextMate包搜索和粘贴代码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TextMate包搜索和粘贴代码相关的知识,希望对你有一定的参考价值。

  1. #!/usr/bin/env ruby -wKU
  2. # Copyright 2008 Hirotsugu Asari
  3.  
  4. require "xmlrpc/client"
  5. require 'cgi'
  6.  
  7. CMD = [ ENV['TM_SUPPORT_PATH'] +
  8. '/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog' ]
  9.  
  10. srv = XMLRPC::Client.new2("http://snipplr.com/xml-rpc.php")
  11.  
  12.  
  13. if ENV['SNIPPLR_KEY'].nil?
  14. args = [
  15. 'ok-msgbox', '--no-cancel', '--title "Snipplr"',
  16. '--text "Environment variable SNIPPLR_KEY missing."', '2>/dev/null'
  17. ]
  18. %x{ #{ (CMD + args).join(" ") } }
  19. exit
  20. end
  21.  
  22.  
  23. # get tags from user
  24. args = [
  25. 'standard-inputbox', '--title "Get Snippet from Snipplr"',
  26. '--informative-text "Enter tags to search for"', '--string-output',
  27. '2>/dev/null'
  28. ]
  29.  
  30. user_response_for_tags = %x{#{(CMD + args).join(" ")}}.split(" ")
  31. if user_response_for_tags[0] == 'Cancel'
  32. exit
  33. end
  34.  
  35. # grab snippets from server
  36. matches = []
  37. begin
  38. matches = srv.call('snippet.list',ENV['SNIPPLR_KEY'],user_response_for_tags[1],'date')
  39. rescue
  40. args = [
  41. 'ok-msgbox', '--no-cancel', '--title "Snipplr"',
  42. "--text 'No matching snippet found.'", '2>/dev/null'
  43. ]
  44. %x{ #{ (CMD + args).join(" ") } }
  45. exit
  46. end
  47.  
  48. ## XML-RPC call may return multiple instances of identical item, so trim
  49. ## the hash to our needs
  50. snippet_title = {}
  51. matches.each do |h|
  52. if !snippet_title.has_key?(h['id'])
  53. snippet_title[h['id']] = h['title']
  54. end
  55. end
  56.  
  57. item_string = '' # for CocoaDialog option
  58. snippet_title.each_value do |s|
  59. item_string += %Q{ '#{s}' }
  60. end
  61.  
  62. args = [
  63. 'standard-dropdown', '--title "Snipplr"', '--text "Select Snippet"',
  64. '--exit-onchange', '--string-output', '--items ' + item_string,
  65. '2>/dev/null'
  66. ]
  67.  
  68. user_choice_for_snippet = %x{#{(CMD + args).join(" ")}}.split(" ")
  69. if user_choice_for_snippet[0] == 'Cancel'
  70. exit
  71. end
  72.  
  73. begin
  74. puts CGI.unescapehtml(srv.call('snippet.get',snippet_title.index(user_choice_for_snippet[1]))["source"])
  75. rescue
  76. args = [
  77. 'ok-msgbox', '--no-cancel', '--title "Snipplr"',
  78. "--text 'No matching snippet found.'", '2>/dev/null'
  79. ]
  80. %x{ #{ (CMD + args).join(" ") } }
  81. end

以上是关于TextMate包搜索和粘贴代码的主要内容,如果未能解决你的问题,请参考以下文章

TextMate:下载Flex包

从GIT刷新并添加textmate包

将捆绑包从git添加到textmate

雪豹升级后修复textmate包

TextMate:搜索当前文件夹

ä¸èè½/æ›´æ–“TextMate捆绑包