You probably have noticed that Notepad++ comes with few plugins included since the installation. One of them is called NppExec.
This plugin lets you create command macro withing a built-in console of Notepad++, and prints the results in that console. It's really useful if you want to see the output immediately. For example, this is how a merge-sort algorithm looks in the built-in console window.
First, we need to add the compiler to the PATH variable in our computer. You can see here (after the image of a console) how to do that. If you don't want to mess with the system environment variables, you will need the whole path of the compiler.
C - C:\MinGW\bin\gcc.exe
Python - C:\Python27\python.exe
Next, click on the Plugins menu, select NppExec, and press Execute. Now, we need to type some commands in here, so the plugin knows what we want. It's good to save the code so we can make it into a shortcut later. Just press Save when you have the script, and give it a name.
cmd /c "$(CURRENT_DIRECTORY)\a.exe"
or if you prefer the full path, just change the second line with this line:
Now, we want a compile button shortcut, don't we?
Well, we need to have the script saved first. In order to do that, go to NppExec->Execute, and check if you have the script in the drop-down menu. If not, press Save when you have the script ready (Check the image above).
Now, go to NppExec->Advanced options. Select the script from the drop-down menu in the bottom-left corner, and press Add/Modify. You will see the script name added in the list above. Press OK, and restart Notepad++.
Next, we need to link our shortcut button, and our script. Go to Settings-> Shortcut mapper. Select the Plugin section, and scroll to the bottom of the list. There you will find the script you just made.
|Creating a shortcut for your script.|
So, how does this work?
First, we tell Notepad++ to save our file, so we can compile the latest version of it. (npp_save)
Then, we compile the file. (gcc <file path>)
Finally, we execute the "a.exe" file which is generated after a successful compiling. (cmd /c <a.exe path>)
The only thing that may sometimes trick you, is that the "a.exe" file is executed even if the code won't compile. For example, you changed the code, it doesn't compile, but the "a.exe" file from the previous version is executed. You just need to notice the errors in the compiling, and you'll know it's not the latest version that is executed.
How to compile other languages?
The process is very similar to this one. We only need to change the second line, because we are using another compiler, and delete the third one if we are not using C/C++, because those languages create an .exe file which we need to executed.
Note for Java: If your project contains more .java files, you will need to compile each one of them, and execute the main.
NAME_PART = "Main" from "Main.java". It takes the filename without the extension.
C++: Same as C.