Notepad++ LESS file helper script (Python Script)

  1. download Python Script from http://npppythonscript.sourceforge.net/
  2. download nodejs from http://nodejs.org/
  3. install LESS compiler ( http://lesscss.org/usage/ )
  4. copy & paste code below into your startup.py
  5. change your Python Script initialisation to ATSTARTUP
  6. restart Notepad++ or run startup.py
  7. DONE. ヽ(´ー`)ノ
# Just in case, we'll clear all the existing callbacks
notepad.clearCallbacks([NOTIFICATION.FILEOPENED])
notepad.clearCallbacks([NOTIFICATION.FILESAVED])
 
class LessFileHelper:
 
    # Define the function to call just after the file is opened
    def fileOpened(self, args):
 
        bufferID = args['bufferID']
        filename = notepad.getBufferFilename(bufferID)
         
        if filename[-5:] == '.less':
            #console.write(filename)
            notepad.activateBufferID(bufferID)
            notepad.setLangType(LANGTYPE.CSS)
            editor.setProperty('lexer.css.less.language', '1')
 
    # Define the function to call just after the file is saved
    def fileSaved(self, args):
 
        bufferID = args['bufferID']
        filename = notepad.getBufferFilename(bufferID)
         
        if filename[-5:] == '.less':
            #console.write(filename)
            cmd = r'cmd /c %APPDATA%\npm\lessc.cmd -s "{0}" > "{1}.css"'.format(filename, filename[:-5])
            console.write(cmd + "\n")
            console.run(cmd)
 
lessFileHelper = LessFileHelper()
 
# ... and register the callback    
notepad.callback(lessFileHelper.fileOpened, [NOTIFICATION.FILEOPENED])
notepad.callback(lessFileHelper.fileSaved, [NOTIFICATION.FILESAVED])
分類: 資訊技術相關雜記。這篇內容的永久連結