Python Script for Notepad++

The scripting plugin

  • Full programmatic access to Notepad++ features and menus
  • Full programmatic access to all of Scintilla features
  • Call other plugin menu items
  • Assign menu items, shortcuts and toolbar icons to scripts
  • Process Notepad++ and Scintilla events, direct from a Python script
  • Python console built-in
  • Full regular expression support for search and replace - script Python regular expression replaces
  • Start external programs and pipe the output direct to a Notepad++ document, or filter it, or simply to the console window
  • Full documentation for all the objects and methods



Here's a sample...

# Simple search / replace
editor.replace("old", "new")

# Regular expressions search and replace
editor.rereplace(r"^([A-Z]{3,5})--\1", r"CODE: \1")

# Call a Scintilla function
editor.appendText("Changed codes\r\n");

# Save the file
newFilename = notepad.getCurrentFilename() + ".changed"
notepad.saveAs(newFilename);

# Write to the console window
console.write("Saved as %s\n" % newFilename)

# Create a new document
notepad.new()

# Run a command on the file, and output results to the new file
console.run('compiler.exe "%s"' % newFilename, editor)



So, why another scripting plugin...
  1. It uses python.
  2. See reason 1.
  3. It's lightweight, a 2MB download, it doesn't start up until it's needed (which normally takes about 0.2 seconds), and it doesn't start anything extra (like webservers... :)
  4. Full access to all of Scintilla features, and access to respond to events
  5. Did I mention it uses Python?
  6. Interoperable from other plugins - call Python function from your own plugin
  7. Very quick and easy to create a new script, and add it to the menu
  8. Python is so easy to learn, you'll be writing scripts that save you hours in no time


Python's a great choice for a scripting language - it's very easy to learn, very easy to read and write, and can be object oriented (in fact, it has an excellent model), but doesn't need to be. A script that looks like
	notepad.open("c:\autoexec.bat")
	
is just as valid as a full blown object oriented magic system that turns Notepad++ into a coffee-making spreadsheet application.

Donations


So, I do this for fun - Notepad++ is a great editor, but I missed not being able to script things properly, so I put this together.
I'm not after donations towards my coffee, but, my sister's a doctor, and is trying to build a hospital in Ghana. She's already raised enough to send a load of equipment over to an existing hospital, which makes a terrific difference in a place where equipment is scarce. She needs 100,000GBP to build the hospital and fill it with decent equipment. It sounds like a lot, but it isn't really. If one in fifty of the people that downloaded my last plugin (Plugin Manager) gave 1 pound each, that would be enough.
It's not compulsory by any means (and specifically, for UK tax reasons, is not by way of payment for goods, you get the plugins for free), but, it would bring some meaning to the months of work I put into this, and you know that you've made a difference - and it's got to be a better cause than handing over hard earned cash to profit some software firm.

Visit the charity, or go straight to the online donation page (whatever amount you can, every penny counts).