I'd like to be able to open the Windows hosts file in Notepad++ and have it automatically associated with a programming language, such as Perl. Unfortunately, since the hosts file doesn't have an extension, I'm not sure how to do this.
If a file doesnt have an extension, it is not able to be set to open with a specific application to my knowledge, however once you have opened the file in notepad++ before, you can open it back up and it will show the document in the "Open recent files" under the file tab. This is typically the easiest way for me to open files without extensions like that.
I ran into this very issue some years ago, and ended up getting something workable:
First I grabbed a Hosts user language (this is different than the one I used, but should work). Add the script there to your userDefineLang.xml file in either your "%appdata%/Roaming/Notepad++" or in "Program Files (x86)/Notepad++". That will let set the language for syntax highlighting hosts files manually.
Next get and configure the PythonScript extension for Notepad++ (also available via the Plugin Manager). After it's installed, go to it under "Plugins", and select "Configuration...". At the bottom in the "Initialization:" dropdown, select "ATSTARTUP" so that it will automatically launch its startup script when you open Notepad++.
Then I got the Modeline Parser extension. Download it, and follow the instructions in the README. Esentially, copy the contents into your plugins folder (wherever PythonScript is). Then it has you modify "startup.py" in PythonScript's "scripts" directory, and add the following lines to the bottom of it:
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()
This includes and launches the Modeline Parser.
Lastly, you need to tell the Modeline Parser what a hosts file looks like and what to do with it. To do that go into PythonScripts' "lib" directory and edit "ModelineLanguageDetectors.py". After the default 'makefile' entry, add something very similar for your hosts file:
ModelineParser_dll.modeline_add_preparse(lambda settings, name, path, text: fnmatch.fnmatch(name, 'hosts*') and settings.__setitem__('language','hosts') )
Then at the end of that file, associate your hosts file with the hosts user language we added in the first step. Add an entry for the language to the dictionary in the modeline_add_languages method call's parameters:
After that, close and restart Notepad++ if it's open. Re-open it, and try opening your hosts file. It should automatically have the syntax highlighting applied. I found something along the lines of these instructions years ago, but can no longer find it via Google. Credit mostly goes to whoever wrote that at the time.