Menu

Style Configurator -- Double Extension

tgknight
2008-07-23
2012-11-13
  • tgknight

    tgknight - 2008-07-23

    I have some files that have double extensions. Specifically something like this: "file.xml.php"

    I would like to be able to associate the XML style to these files by entered "xml.php" in the "User Ext" field on the Style Configurator.

    If this is possible, I would be eternally grateful :)

    Thanks!

     
    • Sune Marcher

      Sune Marcher - 2008-07-23

      Extending this idea a bit, it would be cool if you could set syntax highlight based on regular expressions - or at least some wildcard matching. For instance, when dealing with www.scons.org build scripts, it would be useful to have filenames SConstruct/SConscript open automatically with Python syntax coloring...

       
    • eto

      eto - 2008-07-24

      I have observed this as well and would welcome solution to this.

       
  • Lordcatalien

    Lordcatalien - 2011-08-30

    Has this been made possible yet? I want to do the same thing (with css.php and js.php files). Please advise.

     
  • Lordcatalien

    Lordcatalien - 2011-08-30

    Doesn't seem I can edit my reply in order to monitor the thread, so I'm submitting another. :/

     
  • François-R Boyer

    I made a modeline/shebang plugin, which will read a special comment in the file to set language, tab stops, etc.  It also supports to choose language based on any part of path or file name (an example script is given to detect *_user1.* as a specified user defined language) or on file content (an example script is given to detect XML from the XML tag on first line of file).  You can find it here https://sourceforge.net/projects/npppythonplugsq/files/Modeline%20Parser/.

     
  • Lordcatalien

    Lordcatalien - 2011-09-01

    Sorry, I'm not sure I understand how this works. You're saying that if I install your plugin, I can make it so that files named "myfile.css.php" will be detected as CSS and "myfile.js.php" will be detected as JavaScript? If so, please let me know if this is how I use the plug-in (I'm uncertain of your directions):

    1. Install Python Plug-in Script (https://sourceforge.net/projects/npppythonscript/) by extracting into the program directory found here: c:/program files (x86)/notepad++/. It will put the "python27.dll" directly into the program directory and copy the associated plug-in files to the "plugins" directory.

    2. Install Modeline Parser (https://sourceforge.net/projects/npppythonplugsq/files/Modeline%20Parser/) by extracting into the program directory found here: c:/program files (x86)/notepad++/. It will copy the associated plug-in files to the "plugins" directory.

    3. Activate both plug-ins using the Plug-In Manager in Notepad++ by selecting Plugins->Plugin Manager -> Show Plugin Manager and checking the box by PythonScript and Modeline Parser in the "Installed" tab.

    4. Add the following lines to the end of the startup.py script:
    import ModelineParser_dll
    import ModelineFoldmethod        # If you want to use the example option to fold based on indent
    import ModelineLanguageDetectors # If you want to use the example language detectors
    ModelineParser_dll.modeline_start()

    5. Add the following to custom extensions under "CSS"  in the style configurator: *.css.php*

    6. Add the following to custom extensions under "JavaScript"  in the style configurator: *.js.php*

    7. Restart Notepad++

    8. Open a file with one of the above extensions

    If so, this did not work for me. If not, please tell me how to get it to work. My files still show as PHP when I open them.

     
  • François-R Boyer

    @lordcatalien:  You need to activate Python Script on Notepad++ startup, by default it loads the first time you use its menu to run a script. Verify in Plugins->Python Script->Configuration that "Initialisation" (at the bottom of the window) is "ATSTARTUP" (not "LAZY").  The other thing is that my plugin is configured in script files, not in the style configurator:
    Change your steps 5 and 6 for: Open the file "Notepad++\plugins\PythonScript\lib\ModelineLanguageDetectors.py" (you can edit it with Notepad++). Then add lines like the examples. First be sure that "import fnmatch" is before your lines (this is for matching the wildcards like "*" and "?" in filenames), then the lines to add will look like:

    ModelineParser_dll.modeline_add_preparse(lambda settings, name, path, text:
        fnmatch.fnmatch(name, '*.css.*') and settings.__setitem__('language','css') or
        fnmatch.fnmatch(name, '*.js.*') and settings.__setitem__('language','js') 
        )
    

    Then your steps 7 and 8 should work as expected.

     
  • Lordcatalien

    Lordcatalien - 2011-09-01

    Worked brilliantly, just as you said! Thank you. the only change I had to make was changing "js" at the end of the second example above to "javascript"

    Thanks so much! You rock!