{"id":276,"date":"2012-11-15T21:49:35","date_gmt":"2012-11-15T13:49:35","guid":{"rendered":"http:\/\/www.bluesdream.com\/blog\/?p=276"},"modified":"2013-01-24T10:30:14","modified_gmt":"2013-01-24T02:30:14","slug":"write-your-own-sublime-text2-plug","status":"publish","type":"post","link":"https:\/\/www.bluesdream.com\/blog\/write-your-own-sublime-text2-plug.html","title":{"rendered":"\u7f16\u5199\u81ea\u5df1\u7684Sublime Text2 \u63d2\u4ef6"},"content":{"rendered":"<p>Sublime Text2\uff08\u4e0b\u6587\u7b80\u79f0ST2\uff09 \u662f\u4e2a\u5c0f\u800c\u5f3a\u608d\u7684\u8de8\u5e73\u53f0\u7f16\u8f91\u5668\uff08\u8c8c\u4f3c\u5f88\u591a\u6587\u7ae0\u5f00\u5934\u90fd\u559c\u6b22\u8fd9\u6837\u8bf4\u4e00\u53e5\uff0c\u6211\u4e5f\u5c31\u4e0d\u514d\u4fd7\u4e86\uff09\uff0c\u81f3\u4e8e\u7279\u70b9\u548c\u4ecb\u7ecd\u6211\u5c31\u4e0d\u91cd\u590d\u4e86\uff0c\u76f8\u4fe1\u770b\u8fd9\u7bc7\u6587\u7ae0\u7684\u4f60\uff0c\u4e00\u5b9a\u5bf9\u8be5\u8f6f\u4ef6\u6709\u7740\u4e00\u5b9a\u7684\u4e86\u89e3\u3002\u4e0d\u8fc7\u6709\u4e00\u70b9\u4e0d\u5f97\u4e0d\u8bf4\uff0c\u90a3\u5c31\u662f\u5f3a\u5927\u7684\u63d2\u4ef6\u529f\u80fd\uff0c\u8ba9\u539f\u672c\u7cbe\u608d\u7684ST2\u53d8\u7684\u65e0\u6bd4\u5f3a\u5927\u3002\u672c\u6587\u5462\uff0c\u5c31\u662f\u8981\u4ecb\u7ecd\u7ed9\u5927\u5bb6\uff0c\u5982\u4f55\u521b\u5efa\u81ea\u5df1\u7684ST2\u63d2\u4ef6\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u8bdd\u4e0d\u591a\u8bf4\uff0c\u5f00\u59cb\u5207\u5165\u4e3b\u9898\u3002\u5927\u5bb6\u8ddf\u7740\u6b65\u9aa4\u4e00\u8d77\u64cd\u4f5c\u5427\uff1a<\/p>\n<p>1. To to <span style=\"color: #800000;\">Preferences -&gt; Browse Packages\u2026<\/span> \u6253\u5f00Packages\u6587\u4ef6\u5939\uff0c\u5728\u91cc\u9762\u521b\u5efa\u4e00\u4e2a\u5b50\u6587\u4ef6\u5939\uff08\u4f8b\uff1aMypluginFolder\uff09\uff0c\u7528\u6765\u5b58\u653e\u6211\u4eec\u81ea\u5df1\u7684\u63d2\u4ef6\u3002<\/p>\n<p>2. To to <span style=\"color: #800000;\">Tools -&gt; New Plugin...<\/span> \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u63d2\u4ef6\u3002\u73b0\u5728\u4f60\u6240\u770b\u5230\u5185\u5bb9\u5c31\u662f\u4e00\u4e2a\u9ed8\u8ba4\u7684\u793a\u4f8b\uff0c\u6211\u4eec\u628a\u5b83\u4fdd\u5b58\u5230\u6211\u4eec\u521a\u624d\u6240\u521b\u5efa\u7684\u6587\u4ef6\u5939\u4e2d\uff08\u4f8b\uff1a<span style=\"color: #800000;\">MyPlugin.py<\/span>\uff09\u3002<!--more--><\/p>\n<p>3. \u4f7f\u7528\u5feb\u6377\u952e\uff1a<span style=\"color: #800000;\">ctrl+`<\/span> \u6765\u6253\u5f00Sublime Txt\u7684\u63a7\u5236\u53f0\uff0c\u5728\u8f93\u5165\u6846\u4e2d\u8f93\u5165\uff1a<span style=\"color: #800000;\">view.run_command('example')<\/span> \u5e76\u6309\u56de\u8f66\u6267\u884c\u3002\u5982\u679c\u5728\u6587\u4ef6\u7684\u6700\u4e0a\u65b9\uff0c\u770b\u5230\"Hello, World!\"\u5b57\u6837\u7684\u63d2\u5165\uff0c\u90a3\u4e48\u4f60\u7684\u7b2c\u4e00\u4e2a\u63d2\u4ef6\u5df2\u6210\u529f\u6267\u884c\u4e86\u3002<\/p>\n<p>4. \u63a5\u7740\uff0c\u6211\u4eec\u628a\u793a\u4f8b\u4e2d\u7684<span style=\"color: #800000;\">\"ExampleCommand\"<\/span>\u6539\u4e3a\u4f60\u81ea\u5df1\u7684\u63d2\u4ef6\u540d\u79f0\uff08<span style=\"color: #800000;\">\u4f8b\uff1aMypluginCommand<\/span>\uff09\u3002<\/p>\n<p>5. \u4e3a\u4e86\u65b9\u4fbf\u4f7f\u7528\u63d2\u4ef6\uff0c\u8fd8\u9700\u8981\u7ed9\u5b83\u5b9a\u4e49\u4e00\u4e2a\u5feb\u6377\u952e\u3002\u5728\u6211\u4eec\u7684\u63d2\u4ef6\u76ee\u5f55\u4e0b\uff0c\u521b\u5efa<span style=\"color: #800000;\">Default (Windows).sublime-keymap\u3001Default (Linux).sublime-keymap\u548cDefault (OSX).sublime-keymap<\/span>\u8fd93\u4e2a\u6587\u4ef6\uff0c\u5b83\u4eec\u5206\u522b\u5bf9\u5e94\u7684\u4e0d\u540c\u5e73\u53f0\u3002\u5982\u679c\u6211\u4eec\u662fwindows\u7cfb\u7edf\uff0c\u90a3\u4e48\u6253\u5f00\u521a\u624d\u6240\u521b\u5efa\u7684<span style=\"color: #800000;\">Default (Windows).sublime-keymap<\/span>\u6587\u4ef6\uff0c\u8f93\u5165\uff1a<\/p>\n<pre style=\"color: #800000;\">[\r\n      {\"keys\": [\"f12\"], \"command\": \"myplugin\"}\r\n]<\/pre>\n<p>\u6ce8\uff1a\u8fd9\u91cc\u6709\u4e00\u4e2a\u9700\u8981\u6ce8\u610f\u7684\u5730\u65b9\uff0c\u8fd9\u91cc\u7684command\u503c\u5fc5\u987b\u662f\u5c0f\u5199\uff08\u4f8b\uff1a<span style=\"color: #800000;\">MyPluginCommand -&gt; my_plugin<\/span>\uff09\u3002\u53e6\u5916\uff0c\u5982\u679c\u6211\u4eec\u7684\u63d2\u4ef6\u540d\u79f0\u662f\u9a7c\u5cf0\u5f0f\u547d\u540d\uff0c\u90a3\u5927\u5c0f\u5199\u4e4b\u95f4\u8981\u7528\"_\"\u8fde\u63a5\uff08\u4f8b\uff1a<span style=\"color: #800000;\">MyPluginCommand -&gt; my_plugin<\/span>\uff09\u3002<\/p>\n<p>6. \u628a\u6211\u4eec\u7684\u63d2\u4ef6\uff0c\u52a0\u5165\u5230\u9876\u90e8\u83dc\u5355\u680f\u6216\u53f3\u952e\u83dc\u5355\u680f\u3002\u6839\u636e\u9700\u6c42\u521b\u5efa\u5bf9\u5e94\u7684\u6587\u4ef6\uff0c<span style=\"color: #800000;\">Main.sublime-menu \u9876\u90e8\u83dc\u5355\u3001 Side Bar.sublime-menu \u53f3\u952e\u64cd\u4f5c\u5de6\u4fa7Side Bar\u83dc\u5355\u3001Context.sublime-menu controls<\/span> \u53f3\u952e\u64cd\u4f5c\u6587\u4ef6\u83dc\u5355\u3002<br \/>\n\u73b0\u5728\u6211\u4eec\u628a\u5b83\u52a0\u5165\u5230\u9876\u90e8\u83dc\u5355\u680f\uff0c\u6253\u5f00<span style=\"color: #800000;\">Main.sublime-menu<\/span>\uff1a<\/p>\n<pre style=\"color: #800000;\">[\r\n     {\r\n          \"caption\": \"Preferences\",\r\n          \"mnemonic\": \"n\",\r\n          \"id\": \"preferences\",\r\n          \"children\":\r\n          [\r\n               {\r\n                    \"caption\": \"Package Settings\",\r\n                    \"mnemonic\": \"P\",\r\n                    \"id\": \"package-settings\",\r\n                    \"children\":\r\n                    [\r\n                         {\r\n                              \"caption\": \"My Plugin\",\r\n                              \"mnemonic\": \"M\",\r\n                              \"id\": \"my-plugin\",\r\n                              \"children\":\r\n                              [\r\n                                   {\r\n                                        \"command\": \"open_file\", \"args\":\r\n                                   {\r\n                                        \"file\": \"${packages}\/MypluginFolder\/Myplugin.py\"\r\n                                   },\r\n                                        \"caption\": \"View Source\"\r\n                                   },\r\n                                   {\r\n                                        \"caption\": \"Running plugin\",\r\n                                        \"id\": \"running-plugin\",\r\n                                        \"command\": \"my_plugin\"\r\n                                   }\r\n                              ]\r\n                         }\r\n                    ]\r\n               }\r\n          ]\r\n     }\r\n]<\/pre>\n<p>\u6211\u4eec\u5728\u83dc\u5355\u680f\u4e2d\u9009\u62e9\u00a0Preferences -&gt; Package Settings \u770b\u770b\u662f\u4e0d\u662f\u5df2\u7ecf\u6709\u6211\u4eec\u6240\u521b\u5efa\u7684\u5185\u5bb9\u4e86\uff1f\u63d2\u4ef6\u7684\u6267\u884c\u65b9\u5f0f\uff0c\u53ef\u4ee5\u6839\u636e\u6211\u4eec\u6240\u7684\u5feb\u6377\u952e\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u83dc\u5355\u9009\u9879\u6765\u6267\u884c\u3002<\/p>\n<p>\u81f3\u6b64\uff0c\u4e00\u4e2a\u7b80\u5355\u7684ST2\u63d2\u4ef6\u4fbf\u5168\u90e8\u521b\u5efa\u5b8c\u6210\u3002\u5927\u5bb6\u5982\u6709\u9047\u5230\u4ec0\u4e48\u95ee\u9898\u548c\u4e0d\u660e\u767d\u7684\u53ef\u4ee5\u7ed9\u6211\u7559\u8a00\uff0c\u76f8\u4e92\u5171\u52c9O(\u2229_\u2229)O<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sublime Text2\uff08\u4e0b\u6587\u7b80\u79f0ST2\uff09 \u662f\u4e2a\u5c0f\u800c\u5f3a\u608d\u7684\u8de8\u5e73\u53f0\u7f16\u8f91\u5668\uff08\u8c8c\u4f3c\u5f88\u591a\u6587\u7ae0\u5f00\u5934\u90fd\u559c\u6b22\u8fd9\u6837\u8bf4\u4e00\u53e5\uff0c\u6211\u4e5f\u5c31\u4e0d\u514d\u4fd7\u4e86\uff09\uff0c\u81f3\u4e8e\u7279\u70b9\u548c\u4ecb\u7ecd\u6211\u5c31\u4e0d\u91cd\u590d\u4e86\uff0c\u76f8\u4fe1\u770b\u8fd9\u7bc7\u6587\u7ae0\u7684\u4f60\uff0c\u4e00\u5b9a\u5bf9\u8be5\u8f6f\u4ef6\u6709\u7740\u4e00\u5b9a\u7684\u4e86\u89e3\u3002\u4e0d\u8fc7\u6709\u4e00\u70b9\u4e0d\u5f97\u4e0d\u8bf4\uff0c\u90a3\u5c31\u662f\u5f3a\u5927\u7684\u63d2\u4ef6\u529f\u80fd\uff0c\u8ba9\u539f\u672c\u7cbe\u608d\u7684ST2\u53d8\u7684\u65e0\u6bd4\u5f3a\u5927\u3002\u672c\u6587\u5462\uff0c\u5c31\u662f\u8981\u4ecb\u7ecd\u7ed9\u5927\u5bb6\uff0c\u5982\u4f55\u521b\u5efa\u81ea\u5df1\u7684ST2\u63d2\u4ef6\u3002 \u597d\u4e86\uff0c\u8bdd\u4e0d\u591a\u8bf4\uff0c\u5f00\u59cb\u5207\u5165\u4e3b\u9898\u3002\u5927\u5bb6\u8ddf\u7740\u6b65\u9aa4\u4e00\u8d77\u64cd\u4f5c\u5427\uff1a 1. To to Preferences -&gt; Browse Packages\u2026 \u6253\u5f00Packages\u6587\u4ef6\u5939\uff0c\u5728\u91cc\u9762\u521b\u5efa\u4e00\u4e2a\u5b50\u6587\u4ef6\u5939\uff08\u4f8b\uff1aMypluginFolder\uff09\uff0c\u7528\u6765\u5b58\u653e\u6211\u4eec\u81ea\u5df1\u7684\u63d2\u4ef6\u3002 2. To to Tools -&gt; New Plugin... \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u63d2\u4ef6\u3002\u73b0\u5728\u4f60\u6240\u770b\u5230\u5185\u5bb9\u5c31\u662f\u4e00\u4e2a\u9ed8\u8ba4\u7684\u793a\u4f8b\uff0c\u6211\u4eec\u628a\u5b83\u4fdd\u5b58\u5230\u6211\u4eec\u521a\u624d\u6240\u521b\u5efa\u7684\u6587\u4ef6\u5939\u4e2d\uff08\u4f8b\uff1aMyPlugin.py\uff09\u3002<\/p>\n","protected":false},"author":1,"featured_media":284,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75],"tags":[77,85,29],"class_list":["post-276","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-front-end","tag-sublime","tag-sublime-text","tag-original"],"_links":{"self":[{"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/posts\/276"}],"collection":[{"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/comments?post=276"}],"version-history":[{"count":0,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/posts\/276\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/media\/284"}],"wp:attachment":[{"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/media?parent=276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/categories?post=276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/tags?post=276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}