Skip Navigation LinksHome > View Post

Visual Notepad2

Back in January I posted about Visual Notepad and at the end of the post I gave a passing mention to Notepad2.

Well, it deserves a little more than that: Notepad2 is the shiznit. I've even dropped a copy in my system32 folder and called it "n2.exe" so I can start it from the run dialog super quick.

It has tons of cool features that I won't list here (read about them whilst you're downloading it - go on).

However, there is one cool feature I want to discuss that I've recently taken advantage of.

Notepad2's launch menu

Notepad2 has the ability to launch the current document. You can either launch it with the default handler for the file extension or select an application to open the file. I realised that this could be a great way to get my Visual Notepad code to build without having to keep flipping between windows.

The script

All I need is a batch file that can execute the build for me. Easy peasy:

call "C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat"

echo Building %1...

call csc /out:c:\temp\visnotepadapp.exe /d:TRACE,DEBUG %1

if ERRORLEVEL 1 GOTO END-ROUTINE

echo -----------------------

call c:\temp\visnotepadapp.exe

echo -----------------------

:END-ROUTINE

pause

In summary, the script sets up the console to work as a Visual Studio 2005 command prompt and then builds the file passed in the command line. If the build didn't error the application is launched in the current window. You should note that the new exe file is always located in the C:\temp directory and called visnotepadapp.exe but you could easily change that. Also, the csc.exe args specify the TRACE and DEBUG conditional compilation constants.

You now need to put this script into a text file with a .bat extension (why not use Notepad2?) and save it into a nice clean folder; I used "C:\temp\n2apps\n2build.bat" (or you can download it).

Using it in Notepad2

The default extension for a .cs file is Visual Studio and I don't want to muck around with that so I'd have to use the Open With functionality. That's OK because I can quickly access this option with the keyboard command Alt+L, which brings up this dialog:

Notepad2's Open with dialog

You can use the little button with an arrow to specify the default directory for the list of applications shown in this dialog so just point it to the folder containing your new batch file.

Now when you want to build your Visual Notepad code you just press Alt+L followed by the Up cursor (to select n2build.bat) and hit ENTER.

n2build.bat building and executing my code

Thanks to Simon Gent for his help with the script, which you can download here.

Tags: Other

 
Josh Post By Josh Twist
1:18 AM
11 Mar 2006

» Next Post: Initialisation using constructors
« Previous Post: DateTime in Web Services

Comments are closed for this post.

Posted by Pandurang @ 22 Mar 2006 4:04 PM
Have you seen Scite? Another Scintilla implementation. I thought it did a better job at many things.

Posted by Stefano @ 09 Jan 2007 8:41 AM
Why not use SnippetCompiler???

http://www.sliver.com/dotnet/SnippetCompiler/

Posted by Josh @ 09 Jan 2007 1:32 PM
Good question. Part of the attraction of the visual notepad approach is that you DON'T have any support from intellisense etc! It's a struggle at first but you start to *really* learn the basics without the advanced tool support. Remember - this is just for throwaway stuff though. Not for building actual apps :). Whatever floats your boat.

Posted by Martin @ 25 Feb 2009 4:44 AM
I found this feature somewhere, some time ago... I love it...
I am using notepad2 as my default IE browser source code viewer...
With "Alt+L" I am able to reformat code using "tidy" so even messy html is readable. See my blog for more info.
Also I am trying to use "AStyle" to reformat C# source code but I am facing one problem.
It seems that notepad2 is passing path and filename in old DOS "8.3" notation and AStyle can't locate the file... still digging and hopefully I can find a workaround...

© 2005 - 2014 Josh Twist - All Rights Reserved.