notepad - ghdrako/doc_snipets GitHub Wiki
Notepad++
NPPN_FILEOPENEDnotification allows detection immediately after a file is loaded into the editorNPPN_SHUTDOWNsignals impending exit, usable for finalization tasksFILEBEFORESAVEevent can perform cleanup transforms, whileFILECLOSETARGEThooks enable resource deallocation or session state serialization
PythonScript example for trimming trailing whitespace before every save operation leverages the FILEBEFORESAVE hook to iterate over each line buffer, removing extraneous spaces:
def trim_trailing_whitespace():
  editor.beginUndoAction()
  line_count = editor.getLineCount()
  for line in range(line_count):
    line_text = editor.getLine(line)
    trimmed = line_text.rstrip(ā \t\r\nā)
    if trimmed != line_text:
      editor.setTargetStart(editor.positionFromLine(line))
      editor.setTargetEnd(editor.getLineEndPosition(line))
      editor.replaceTarget(trimmed)
      editor.endUndoAction()
# Hook to file save event
notepad.callback(trim_trailing_whitespace, [NOTIFICATION.FILEBEFORESAVE])