Saturday 29 March 2014

Compile and Run Programs in Notepad++

Yo, most of the people I know use Notepad++ and swear by it that it's the best text editor any one can use. Me, I frankly use Vim. But, I gave it a shot and it's pretty useful. It's got tons of features. This post is not about Notepad++ and it's features.

Now, back to post. The major problem any guy or gal has is that once you write your program in Notepad++, you cannot compile or interpret in it nor can you run your compiled programs in it. So, you would have to use some other application with it. But, now you don't need to (unless you want to debug). I tried that, but it did not work.

Here is the how-to:
  • Install the compiler or interpreter you want to use.
  • Install NppExec Plugin (I won't write how to install it)
  • Now, goto Plugins -> NppExec -> Execute or press F6
  • In the Execute Dialog Box, write
 For C, write
 cd "$(CURRENT_DIRECTORY)"
set obj = $(CURRENT_DIRECTORY)\$(NAME_PART)
gcc "$(FILE_NAME)" -o "$(obj).exe"
NPP_RUN "$(obj).exe"
unset obj
 For C++, you can write
 cd "$(CURRENT_DIRECTORY)"
set obj = $(CURRENT_DIRECTORY)\$(NAME_PART)
g++ "$(FILE_NAME)" -o "$(obj).exe"
NPP_RUN "$(obj).exe"
unset obj
For Java,
 cd "$(CURRENT_DIRECTORY)"
javac "$(FILE_NAME)"
java "$(NAME_PART)"
NOTE: You can write something similar for the language you want to use.
  •  Click on Save.
  • Give the name something like run@.c for C, run@.cpp for C++ and run@.java for Java. (But, keep the name same, see only the extension has changed,  because you are gonna use this property later)
  • Then, make a new script and write in it,
// Save Current File
NPP_SAVE
// Construct the script name to be called
SET Compiler = run@$(EXT_PART)
// Call the script
NPP_EXEC "$(Compiler)"
  • Save this with a name something like compile.
That's about it. Now, anytime you write you program, just run the compile script and it's done.

I haven't tried it with languages other than the ones that have been mentioned in this post. If you do try it, whether you are successful or not, please let us know.

As always thanks for reading and please comment.

No comments:

Post a Comment

Stuff that most try to do