The EditBus

jEdit (and some plugins) generate several kinds of messages to alert plugins and other components of jedit-specific events. The message classes, all derived from EBMessage cover the opening and closing of the application, changes in the status of buffers and views, changes in user settings, as well as changes in the state of other program features. A full list of messages can be found in the org.gjt.sp.jedit.msg package.

For example, the ViewUpdate messages are all related to the jEdit View, or the top-level window. If the user creates multiple Views, a plugin may need to know when they are created or destroyed, so it would monitor ViewUpdate messages.

BufferUpdate messages are all related to jEdit buffers. They let plugins know when a buffer has become dirty, when it is about to be closed, after it is closed, created, loaded, or saved. Each of these messages are described in further detail in the API docs.

As another example, The Navigator plugin monitors an EBMessage of the kind BufferChanging. The BufferChanging event provides Navigator enough advance notice to save the TextArea's caret just before the current EditPane changes its active Buffer. The BufferChanged event, another EditPaneUpdate message, is thrown shortly afterward. This is not used by Navigator, but it is used by SideKick to determine when it is time to reparse the buffer.

Plugins register EBComponent instances with the EditBus to receive messages reflecting changes in jEdit's state.

EBComponents are added and removed with the EditBus.addToBus() and EditBus.removeFromBus() methods.

Typically, the EBComponent.handleMessage() method is implemented with one or more if blocks that test whether the message is an instance of a derived message class in which the component has an interest.

if(msg instanceof BufferUpdate) {
    // a buffer's state has changed!
else if(msg instanceof ViewUpdate) {
    // a view's state has changed!
// ... and so on

If a plugin core class will respond to EditBus messages, it can be derived from EBPlugin, in which case no explicit addToBus() call is necessary. Otherwise, EditPlugin will suffice as a plugin base class. Note that QuickNotepad uses the latter.

Using the Activity Log to see the EditBus

To determine precisely which EditBus messages are being sent by jEdit or the plugins, start up jEdit with an additional argument, -log=5. You can set an even lower log level to see further details (the default is 7). With a log level of 5 or lower, the Activity Log will include [notice]s, which will show us exactly which EditBus message is sent and when. See Appendix B, The Activity Log for more details.