{"id":522,"date":"2014-04-25T17:04:49","date_gmt":"2014-04-25T09:04:49","guid":{"rendered":"http:\/\/blog.nami.idv.tw\/?p=522"},"modified":"2019-07-11T18:41:58","modified_gmt":"2019-07-11T10:41:58","slug":"notepad-less-file-helper-script-python-script","status":"publish","type":"post","link":"https:\/\/blog.nami.idv.tw\/?p=522","title":{"rendered":"Notepad++ LESS file helper script (Python Script)"},"content":{"rendered":"<ol>\n<li>download Python Script from <a href=\"http:\/\/npppythonscript.sourceforge.net\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/npppythonscript.sourceforge.net\/<\/a><\/li>\n<li>download nodejs from <a href=\"http:\/\/nodejs.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/nodejs.org\/<\/a><\/li>\n<li>install LESS compiler ( <a href=\"http:\/\/lesscss.org\/usage\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/lesscss.org\/usage\/<\/a> )<\/li>\n<li>copy &amp; paste code below into your startup.py<\/li>\n<li>change your Python Script initialisation to <strong>ATSTARTUP<\/strong><\/li>\n<li>restart Notepad++ or run startup.py<\/li>\n<li>DONE. \u30fd(\u00b4\u30fc\uff40)\u30ce<\/li>\n<\/ol>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; auto-links: false; title: ; notranslate\" title=\"\">\n# Just in case, we&#039;ll clear all the existing callbacks\nnotepad.clearCallbacks(&#x5B;NOTIFICATION.FILEOPENED])\nnotepad.clearCallbacks(&#x5B;NOTIFICATION.FILESAVED])\n \nclass LessFileHelper:\n \n    # Define the function to call just after the file is opened\n    def fileOpened(self, args):\n \n        bufferID = args&#x5B;&#039;bufferID&#039;]\n        filename = notepad.getBufferFilename(bufferID)\n         \n        if filename&#x5B;-5:] == &#039;.less&#039;:\n            #console.write(filename)\n            notepad.activateBufferID(bufferID)\n            notepad.setLangType(LANGTYPE.CSS)\n            editor.setProperty(&#039;lexer.css.less.language&#039;, &#039;1&#039;)\n \n    # Define the function to call just after the file is saved\n    def fileSaved(self, args):\n \n        bufferID = args&#x5B;&#039;bufferID&#039;]\n        filename = notepad.getBufferFilename(bufferID)\n         \n        if filename&#x5B;-5:] == &#039;.less&#039;:\n            #console.write(filename)\n            cmd = r&#039;cmd \/c %APPDATA%\\npm\\lessc.cmd -s &quot;{0}&quot; &gt; &quot;{1}.css&quot;&#039;.format(filename, filename&#x5B;:-5])\n            console.write(cmd + &quot;\\n&quot;)\n            console.run(cmd)\n \nlessFileHelper = LessFileHelper()\n \n# ... and register the callback    \nnotepad.callback(lessFileHelper.fileOpened, &#x5B;NOTIFICATION.FILEOPENED])\nnotepad.callback(lessFileHelper.fileSaved, &#x5B;NOTIFICATION.FILESAVED])\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>download Python Script from http:\/\/npppy &hellip; <a href=\"https:\/\/blog.nami.idv.tw\/?p=522\">\u95b1\u8b80\u5168\u6587 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10],"tags":[],"class_list":["post-522","post","type-post","status-publish","format-standard","hentry","category-it-note"],"_links":{"self":[{"href":"https:\/\/blog.nami.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nami.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nami.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nami.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nami.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=522"}],"version-history":[{"count":7,"href":"https:\/\/blog.nami.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/522\/revisions"}],"predecessor-version":[{"id":708,"href":"https:\/\/blog.nami.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/522\/revisions\/708"}],"wp:attachment":[{"href":"https:\/\/blog.nami.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nami.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nami.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}