Samuel Jacob's Weblog

Just another technical blog

Notepad++ as IDE

without comments

I have been using Noetpad++ for more than 2 years. It is a wonderful editor – it is very light and feature rich. I use it for editing any text files (txt, ini, C, C++, html, css..). I was happy with Notepad++ for editing my C project source files. Only thing I didn’t like was, to compile I have to go to command prompt and then to correct errors I have to note down the line numbers and open notepad++ modify….

Yesterday, I started searching for a new notepad replacement cum IDE for my Ace(C on cygwin) project. Dev-Cpp and PSPad were IDEs I got. I downloaded and installed both of them. Here comes the problem, both are heavier than notepad++. I might have not explored well, both don’t have option to run cygwin make and capture output and process it.

So I decided to create a notepad++ plugin for my need. But before that wanted to try existing plug-ins and found NppExec. This plug-in allows to run command inside notepad++ and captures the output. It also opens a C file and goto line numbers if it was in the error output if you double click on a line containing “error:” or “warning:” string (I found this one accidently). Downloaded NppExec and ran “make” inside it; but got what I really expected. The output of cygwin “make” has relative path.

i386/io.c:19: error: `Port’ undeclared (first use in this function)
make[1]: *** [i386/io.o] Error 1
make: *** [kernel] Error 2

Since my project make works by invoking “make” inside each directory, relative path will be little complicated – so decided to use absolute path in the output of gcc warning and errors. So modified the explicit rule like following.

$(CC) -c $(abspath $I./include $(CFLAGS)

Out of topic – good make file http://make.paulandlesley.org/autodep.html

Now the output is like the following

/cygdrive/e/sam/Ace3/src/kernel/i386/io.c:19: error: `Port’ undeclared (first use in this function) make[1]: *** [i386/io.o] Error 1 make: *** [kernel] Error 2

This output was not enough because, if I double click this line, notepad tries to open c:/ /cygdrive/e/sam/Ace3/src/kernel/i386/io.c instead of e:/sam/Ace3/src/kernel/i386/io.c.

To solve this problem the I used the following script in notepad++ run command(hotkey – F6)

c:\cygwin\bin\bash -l -c ‘cd src;make 2> err; sed -e “s@\(\/cygdrive\/\)\([a-zA-Z]\)@\2:@g” err; rm err’

Sed help: http://www.ibm.com/developerworks/linux/library/l-sed2.html

Explanation of this command:

c:\cygwin\bin\bash -l –c

Tells NppExec to execute bash and capture its ouput. –l means login and execute bash scripts and profile – I need this for setup my make environment. –c means execute the commands given as argument and exit. Each command is separated by semi-colon.

cd src; – needs no explanation – not needed may be in your case.

make 2> err; – run make and redirect errors to “err” file.

sed -e “s@\(\/cygdrive\/\)\([a-zA-Z]\)@\2:@g” err; – find the pattern /cygdrive/? And replace it with /cygdrive/?:

rm err – remove the error file.

If double clicking on the error/warning message is not opening the file, then try configuring NppExec’s console output filter by using the following %ABSFILE%:%LINE%: warning:* and %ABSFILE%:%LINE%: error:*

Now I am able to create, edit, compile and modify my project without leaving cygwin. Since I am using SVN no problem for source control also. 
Recently I switched to CodeLite and detail are here http://samueldotj.blogspot.com/2008/09/codelite-ide-for-c.html. CodeLite is lightweight IDE.

Written by samueldotj

October 23rd, 2007 at 10:30 pm

Posted in Softwares,Tools,Windows