How do you go about reading Notepad++ source code?

Notepad++ is open-source:

and I'd like to read the source code to understand how it was written (and how some features were implemented -- like how to persist and restore tabs between startup).

The project doesn't appear to be managed by any particular IDE and the directory structure is fairly deep. Say you've never looked at the source code before.

1. How would you go about figuring out where things are (without using the project forum -- which isn't always available)?
2. What would you read first?
3. How would you find the files containing the source code you'd like to read?

Here's how I'd approach it:

1. Figure how the application is built (if it isn't managed by an IDE): Makefiles will name .cpp files containing main() and all of the "core" .cpp that needs to be compiled with it.
2. Execution of any C++ program begins in main(). Find the .cpp file with main() and start reading there.
3. I use the search bar to look for function declarations/definitions but it could take a while for the results to load. I'd attempt to create a project for it in an IDE and rely on the IDE's "find definition" feature. Do you know of any better ways?
Last edited on
I don't think this is the optimal answer, but if you're dealing with a big source code tree, I personally like to use grep -r. the -r stands for "recursive" and you can search recursively from a top directory downward for text inside files.
The output of grep will show the lines that match your search term, and which file they're in.

grep is available on *nix platforms but also has downloads available for Windows if you search it.

e.g. search for all instance of "tab" (could be a lot of hits!)
grep -ri "tab" .
The "i" here means case-insensitive, and the dot at the end means start searching in the current directory.

If you're trying to learn about the project, one thing I'd try to do is say "how do I change a small, small part of the program from X to Y?", or "how does X work", like you said.
Then, l would poke around trying to find which part of the logic deals with that.

For instance, if I search for grep -ri "Close ALL But this" -C 5 .
I get a result that includes:
./PowerEditor/src/NppNotification.cpp-                  if (!_tabPopupMenu.isCreated())
./PowerEditor/src/NppNotification.cpp-                  {
./PowerEditor/src/NppNotification.cpp-                          // IMPORTANT: If list below is modified, you have to change the value of tabContextMenuItemPos[] in localization.cpp file
./PowerEditor/src/NppNotification.cpp-                std::vector<MenuItemUnit> itemUnitArray;

So that gives us some code that relates to the pop-up menu coming up when you right-click on a tab. Then you can open this file, and follow it backwards to see just how it knows what a tab is, and then figure out how that tab is loaded, etc. Maybe.

I would love to hear other people's ideas for exploring an unknown codebase.
Registered users can post here. Sign in or register to post.