Notepad++: Some Less Known Features

0325-215400-Notepad++
Microsoft’s default text editor Notepad is not good.  Especially for us programmers there is Notepad++. It is the fast pure text editor for programmers. Everytime you need to edit a small script and you don’t want to boot up your big IDE, Notepad++ is the editor to go for.


  • It is fast.
  • It’s got syntax highlighting for most programming languages.
  • It can handle multiple open files in tabs.

Probably you knew this already. But maybe you do not know some of the less known features of Notepad++ which often come in handy for a developer.

Less Known Features of Notepad++

With Notepad++, you can …. With these commands
change tab to space and vice versa Edit/Blank Operations/TAB to Space
convert end of line Edit/EOL Conversion
change the encoding of a file. ANSI, UTF-8, UCS2, … Encoding
encode and decode Base64 Plugins/Mime-Tools/Base64 …
do URL en- and decoding Plugins/Mime-Tools/URL …
convert between ASCII, decimal, hex, binary and octal Plugins/Converter/Conversion Panel
do block indentation and de-indentation Tab, Shift-Tab
change all keyboard shortcuts to your preferred ones. Settings/Shortcut Mapper…
apply syntax folding on multiple levels View/Fold All, Unfold All, Collapse Current Level, Uncollapse Current Level, Collapse Level/1,2,3,4,5,6,7, …
zoom in and out Ctrl-Num+ or Ctrl-Mouse-Wheel-Up
sort lines Edit/Line Operations/Sort Lines…
record and play macros Macro/Start Recording, Macro/Playback
use a function list View/Function List
diff files Plugins/Compare/…
use the plugin-manager to browse and install from dozens of special plugins that may be helpful for you Plugins/Plugin-Manager/Show Plugin Manager

Make Notepad++ Your Default Editor

I’ve associated many file types, including txt, ini, cs, cpp, tcl, bsh and others with Notepad++, so if I double click on such a file, Windows opens it with Notepad++ automatically. You can do this easily in Notepad++ by selecting Settings/Preferences/File Association .

0319-131138-Notepad++-Preferences

Here, for every extension you want to be associated with Notepad++, do

  1. Select an entry in the Supported exts column, e.g public script.
  2. Select the extension you want to be associated with Notepad++ besides.
  3. Click the arrow right.

Also, I have set Notepad++ as the text editor in Double Commander, so I can open any file in Notepad++ by clicking F4 in Double Commander, completely independent of its extension.

Stuff That Needs Improvement

There are some features in Npp that are meant well, but which need improvement.

Function List

A function list is a nice thing for a programmer, no question. A slight pity here is, it doesn’t work too well. I’ve tested it with bash, C++, C# and Tcl.

  • It doesn’t work at all with bash, C# and Tcl.
  • It doesn’t show constructors and destructors in C++

Diff Function

It is a good idea to build a diff function into a programmer’s editor of course. But pitily, the compare feature in Notepad++ is not mature at all. Ok, you can do a rudimentary comparison of two files. But that seems to be all. And before you do the comparison, you must make sure that the second of the files to compare is zoomed to the default level.

You just can’t compare Notepad++’s compare function to a real comparison tool, like Beyond Compare or WinMerge. (Sorry, this sentence just had to be.)

This post refers to Notepad++ version 6.5.5.

Double Commander: Add 7-zip Support

I’ve sung a hymn on Double Commander in a previous post.

And after having used Double Commander some weeks, I got a bit annoyed by the fact that it didn’t handle 7z archives like zip archives. How to add 7-zip support to Double Commander 0.5.8 will be explained here.

Double Commander supports Total Commander plugins. There are several 7-zip plugins for Total Commander available from the net. Which is a problem, because only the last one you’ll try will work 😉

Do not use version 1.0.1.0 of 2005 of the 7-zip plugin by Alexander Cherenkov. This won’t work well, at least not with any of the four or so 7-zip versions I’ve tested. It will cause hangs and other malfunctions.

I’ve also come across a 7-zip plugin that has been marked as malware by VirusTotal. But you are careful in respect to what you download from the internet, isn’t it?

I now use version 0.7.6.5.a of 2011 by Adam Strzelecki and others. This has a fitting 7-zip version built into itself. It does not work perfectly, but quite well. I’ve removed some stuff that’s unneeded for Double Commander and repacked it to create wcx_7zip0.7.6.5b.bin.zip. You can download wcx_7zip0.7.6.5b.bin.zip here.

DC-Options

Installing it is no problem:

  1. Crete a directory $DC/plugins/wcx/7z, where $DC is the root installation folder of Double Commander.
  2. Extract 7zip.wcx or 7zip.wcx64 and 7zip.ini from the package wcx_7zip_0.7.6.5b.bin_.zip into the directory $DC/plugins/wcx/7z. You don’t need the other files in the package.
  3. In Double Commander, open the Options dialog and select  Plugins in the tree at the left and then the Packer Plugins tab.
  4. Press Add and select $DC/plugins/wcx/7z/7zip.wcx.
  5. Connect it with the file extension 7z.
  6. See image above for the result in the Packer Plugins tab.

How to Add Jar Extension to Zip Packer Plugin

Just because it fits here somehow and doesn’t deserve an own post:

  1. In Double Commander, open the Options dialog and select Plugins in the tree at the left and then the Packer Plugins tab.
  2. Select the line with the name zip.
  3. Press the Tweak button at the bottom of the page.
  4. In the upcoming dialog, press the Add new… button.
  5. In the following message box, type in jar and press Ok
  6. Close the dialog and press Apply on the Options dialog.

Fiddler: How to Add a Http Verb, a SOAP Action and a Duration Column

Fiddler is a terrific and free web debugger for any browser, system or platform. You can see much information about every http request that is made. But even better, you can set breakpoints and tamper with the content of a request before continuing.

If you are doing web development, you need to know Fiddler. If you are starting web development, you should invest an hour or more to install and learn about Fiddler. It is a very good investment of your time.

How to Add a Http Verb Column

What I’ve missed from the beginning is a column which shows me the http method (POST, PROPFIND, GET, …) of a request. Many thanks to A. Mackert for the following solution:

In Fiddler, select Rules/Customize Rules. Notepad opens, with some predefined custom rule stuff. Scroll down unto class Handlers.
Uncommment the five marked lines and save the file.

CustomRules

If you have an older version, close and reopen Fiddler. Closing and reopeneing is not needed with the latest versions of Fiddler. Look for the new column – called Method at the right and drag it to the left. Voilá, you have a nice column with the http verb.

Fiddler-1

How to Change the Editor for the CustomRules File

If you want to do more changes than just uncommenting some lines, it is better to use another editor than notepad. To change the editor, go to Tools/Fiddler Options…/ Tools/FiddlerScriptEditor and select your preferred editor. Notepad++ will do well for now. For extended stuff, there is a special FiddlerScript Editor available. The FiddlerScript Editor has got a built in class explorer which helps with Fiddler classes and types.

How to Add a Column for the Duration of the Request

You can add a column which shows the time in seconds from start to end of a request.

With a current Fiddler version (I’m using 2.4.6.2) you must search for the class Handlers in the CustomRules-file and add the following snippet of code to the class:

public static BindUIColumn("Duration", 60)
function CalcDurationCol(oS: Session){
  var result = String.Empty;
  if ((oS.Timers.ServerDoneResponse > oS.Timers.ClientDoneRequest)) {
    var duration = oS.Timers.ServerDoneResponse -
           oS.Timers.ClientDoneRequest;
     result = String.Format("{0:0.0000}",
           duration.TotalMilliseconds/1000);
  }
  return result;
}

In some previous Fiddler version,   you could just search for m_ShowTTLB in the CustomRules-file and set the value to true.

How to Add a Column Containing the Start Time of the Request

In the CustomRules-file, in the class Handlers add the following snippet of code:

public static BindUIColumn("Starttime", 80)
function CalcStarttimeCol(oS: Session){
  var result = oS.Timers.ClientDoneRequest.ToString("HH:mm:ss.ff");
  return result;
}

The language used in the CustomRules.js is JScript.NET. So you can use all of .Net’s String.Format possibilities to format the output of the added columns.

How to Add a Column for the SOAP Action

I’ve copied this one from KorteAchternaam.

public static BindUIColumn("SOAP", 120)
function FillSoapAction(oS: Session) {
        if ((oS.oRequest != null)
                && (oS.oRequest.headers != null)
                && (oS.oRequest.headers.Exists("SOAPAction"))) {
            var action = oS.oRequest.headers.Item["SOAPAction"];
            return action.replace(/^.*\//, "").replace(/"/, "");
        } 
        else 
            return String.Empty;
}

Happy fiddling.

Code Complete: The Law

There should be a law, which makes it a duty to every software developer to read this book – Code Complete by Steve McConnell – every two years or so.

Code Complete treats everything that needs to be known by a developer at the code front. This book is very detailed and without any ideology or religion. McConnells only religion seems to be to use hard facts, nothing else.

Facts, Hard Facts

Much of the book is based on hard facts, measurements, science. This is in stark and refreshing contrast to some other famous books for programmers…  which seem to be based more on ideology than anything else.

Some examples of these hard facts.

In chapter 9.1, Considerations in Choosing Good Names, he cites a study that showed that loger names are better for rarely used or global variables and shorter names are better for local or loop variables.

In chapter 18.2, Layout Techniques, he explains, that there have been studies that show:

  • An indentation of two to 4 spaces makes code best understandable.
  • An indentation of 6 spaces is worse.
  • No indentation is the worst for understandability.

In chapter 19.4, Keys to Effective Comments, he mentions a study which found that maintenance programmers most often said that it was most difficult to understand the original programmers intent.

McConnell continues: So, the only two kinds of comments that are acceptable for completed code are intent and summary comments.

Checklists

Every chapter ends with an extensive checklist which summarizes the key points of the chapter. This makes the volume quite useful as a reference on every topic that you might face as a developer.

Summary

I really love this book. I recommend to you: If you haven’t read it already, go, run, fly to get one and enjoy it.

If you read only one book about your prefession in your whole life as a developer, it should be Code Complete.

 

Procdump: Creating Crashdumps Automatically

Problems:
a) Sometimes, an application crashes on a test computer 😉  And sometimes this occurs immediately at startup, so that you don’t have time to attach windbg before to get a crashdump.

b) Sometimes, an application crashes, and immediately restarts on a test computer. This can be hindering the debugging. E.g. because it would be nice to look at the state of the databases at the time of the crash. And because you would like to have a crashdump.

Solution:
There is a solution for both of these problems. Use the procdump.exe utility of Russinovich. You can attach it to your application immediately at startup and make creating crashdumps automatic.
I use a batchfile procdump.bat with this content:

procdump.exe -e -ma -x %1.exe %1.dmp

Then I open a commandline in the program folder where the app under examination resides (e.g. C:\Program Files (x86)\Xyz\App) and start the batch via

procdump.bat AppNameWithoutDotExe

When the application crashes now, a crashdump is written to the program folder, called AppNameWithoutDotExe_140304_161853.dmp or the like. The numbers contain date and time. At the same time, in the cmd window where you started it, there is written something like “The process has crashed. A dump has been written to …”

Disadvantage:
Procdump is something like a debugger and it attaches itself immediately to the app. Therefore debugging protection is triggered when you start to do something in your app that uses debugging protection.
Then, it may be that the app just silently closes. This is reflected in the cmd window by a line like “The process has exited.”

CPU Monitoring:
Before I forget it, procdump has another feature that may come in handy sometime. It can monitor an application for its CPU load and create a crasdump when the load gets too high.