org.gjt.sp.jedit package is a class called Macros. It is so named because it was written to record and run jEdit macros. It also contains a few methods useful for displaying output messages or obtaining input from a macro. Two methods that are particularly useful are error() and message(). These methods take a View and a String as arguments and create a dialog box with the string argument displayed. To use these methods, you should be sure your actions.xml file passes the current view to your plugin and in your plugin, do the following:
import org.gjt.sp.jedit.Macros;
Macros.message(view, "DEBUG: someVariable = " + someVariable);
The advantage to this method is that it is easy. Most plugins already pass view to the action and import all classes from org.gjt.sp.jedit. So usually, inserting the message line is good enough to print a debug message.
The disadvantage to this method is that only one dialog shows at a time and you must click Ok to dismiss the dialog and continue execution. If you have many debug messages, this method can become messy. In some cases, it would be better if you could just print all your debug mesages to a separate area and let the program continue executing. This is where using Error List becomes a better alternative.
Error List to report debugging messages is relatively easy, but requires a little more setup than the Macros.message() method discussed above.
Here is a distilled version of what you need to do to use the Error List plugin to report debug messages:
Error List plugin documentation (RTFM).
build.xml file, in the path section, add a pathelement setting with a location that points to where ErrorList.jar is installed.
DefaultErrorSource. For example, in the class YourPlugin in the start() method. The jEdit manual recommends against using start() as a place to register the error source because it forces the ErrorList class to be loaded, but we can ignore this recommendation since during debugging we will always want to use the plugin and display messages. Just remember to remove the debug code for production builds.
ErrorSource.registerErrorSource(errorsource);
YourPlugin in the stop() method.
addError() call that adds a warning, covering the entire line:
errorsource.addError(new DefaultErrorSource.DefaultError(errorSource,
ErrorSource.WARNING, currentFullPath, currentLine, 0,0,
"DEBUG message here."));
The advantages to this method are:
Error List pane
Error List can slow down loading and unloading of your plugin
| Topic PluginDebuggingTechniques . { Edit | Attach | Ref-By | Printable | Diffs | r1.4 | > | r1.3 | > | r1.2 | More } |
|
Revision r1.4 - 31 Jan 2006 - 21:21 GMT - Rob York Parents: Writing Plugins? |
Copyright © 1999-2011 by the contributing authors.
All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding jEdit Community Wiki? Send feedback. |