LESS support (Python Script)

2014-04-25
2014-09-15
  • Dragon Chuang

    Dragon Chuang - 2014-04-25

    Open LESS file with Notepad++ and auto compile when file saved.

    Environment:
    Windows 7
    Notepad++ 6.5.5
    Python Script 1.0.4.0
    node.js
    Lessc

    # 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':
                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':
                cmd = r'cmd /c %APPDATA%\npm\lessc.cmd "{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])
    
     
  • Dragon Chuang

    Dragon Chuang - 2014-04-30

    Update: add -s option to lessc, or notepad++ will hangs at lessc compile error.

    cmd = r'cmd /c %APPDATA%\npm\lessc.cmd -s "{0}" > "{1}.css"'.format(filename, filename[:-5])
    
     
  • rUiSuATP

    rUiSuATP - 2014-09-15

    This implies you have %APPDATA%\npm\lessc.cmd, which is in the "Environment" that I didn't read.

     
    Last edit: rUiSuATP 2014-09-15

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks