Home
jEdit 4.2 User Manual
Contents
1. Listing of the Macro The macro script follows You can find it in the jEdit distribution in the Text subdirectory of the macros directory You can also try it out by invoking Macros Text A dd Prefix and Suffix beginning of Add Prefix and Suffix bsh import statement s the section called Import Statements import javax swing border main routine void prefixSuffixDialog create dialog object s the section called Create the Dialog title Add prefix and suffix to selected lines dialog new JDialog view title false content new JPanel new BorderLayout content setBorder new EmptyBorder 12 12 12 12 content setPreferredSize new Dimension 320 160 dialog setContentPane content add the text fields see the section called 92 A Dialog Based Macro Create the Text Fields fieldPanel new JPanel new GridLayout 4 1 0 6 prefixField new HistoryTextField macro add prefix prefixLabel new JLabel Prefix to add suffixField new HistoryTextField macro add suffix suffixLabel new JLabel Suffix to add fieldPanel add prefixLabel fieldPanel add prefixField fieldPanel add suffixLabel fieldPanel add suffixField content add fieldPanel Center add a panel containing the buttons see the section called Create th
2. lt ACTION NAME quicknotepad copy to buffer lt CODE gt wm getDockable QuickNotepadPlugin NAME copyToBuffer lt CODE gt lt ACTION gt lt ACTIONS gt This file defines three actions They use the current view s DockableWindowManager object and the method getDockable to find the QuickNotepad plugin window and call the desired method When an action is invoked the BeanShell scripts address the plugin through static methods or if instance data is needed the current View its DockableWindowManager and the plugin object return by the getDockable method If you are unfamiliar with BeanShell code you may nevertheless notice that the code statements bear a strong resemblance to Java code with one exception the variable view is never assigned any value For complete answers to this and other BeanShell mysteries see Part III Writing Macros two observations will suffice here First the variable view is predefined by jEdit s implementation of BeanShell to refer to the current View object Second the BeanShell scripting language is based upon Java syntax but allows variables to be typed at run time so explicit types for variables need not be declared A formal description of each element of the act ions xml file can be found in the documentation of the Act ionSet class The Dockable Window Catalog The jEdit plugin API uses BeanShell to create the top level visible container of a plug
3. Move Line Down bsh Moves the current line down one with automatic indentation Move Line Up bsh Moves the current line up one with automatic indentation File Management Macros These macros automate the opening and closing of files Browse Directory bsh Opens a directory supplied by the user in the file system browser Buffer Switcher bsh 61 Macros Included With jEdit Displays a modal dialog listing all open buffers allowing one to switch to and or close buffers ENTER switches to a buffer and closes the dialog DELETE closes a buffer SPACE switches to a buffer but does not close the dialog Close All Except Active bsh Closes all files except the current buffer Prompts the user to save any buffer containing unsaved changes Copy Path to Clipboad bsh Copies the current buffer s path to the clipboard Copy Name to Clipboad bsh Copies the current buffer s filename to the clipboard Delete Current bsh Deletes the current buffer s file on disk but doesn t close the buffer e Glob Close bsh Closes all open buffers matching a given glob pattern Insert Selection bsh Assumes the current selection is file path and tries replaces the selection with the contents of the file Does nothing if no text is selected or the selection spans multiple lines Next Dirty Buffer bsh Switches to the next dirty buffer if there is one Open Path bsh Opens the file
4. sese mH He mH en nenne 123 The QuickNotepadToolBar Class esee 125 The QuickNotepadOptionPane Class see 126 Plugin Documentation eee eere i aed E ease o eee del CREER 128 Compilns the during T 128 Reloading the Plugm ou ue ed 129 19 Plugin Tips and Techniques iere ertet desee tire rte ET e i per uess 130 Bundling Additional Class Libraries ee 130 Vil Part I Using jEdit This part of the user s guide covers jEdit s text editing commands along with basic usage of macros and plugins This part of the user s guide was written by Slava Pestov lt slava jedit org gt Chapter 1 Conventions Several conventions are used throughout jEdit s user interface and this manual They will be described here Macintosh users should note how their modifier keys map to the terms used in the manual View gt Scrolling gt Scroll to Current Line The Scroll to Current Line command contained in the Scrolling submenu of the View menu Edit gt Go to Line Menu items that end with ellipsis display dialog boxes The primary modifier key in jEdit On MacOS X this is actually the key known as Command On most other keyboards this key is labelled Control The secondary modifier key in jEdit On MacOS X this is actually the key labelled Control On most other keyboards this key is labelled Alt The standard S
5. BeanShell Dynamic Typing Without an explicit type declaration like String result BeanShell variables can change their type at runtime depending on the object or data assigned to it This dynamic typing allows you to write code like this if you really wanted to note no type declaration result Macros input view Type something here this is our predefined current View result view this is an int for integer in Java and BeanShell int is one of a small number of primitive data types which are not classes result 14 However if you first declared result to be type St ring and and then tried these reassignments BeanShell would complain While avoiding explicit type declaration makes writing macro code simpler using them can act as a check to make sure you are not using the wrong variable type of object at a later point in your script It also makes it easier if you are so inclined to take a BeanShell prototype and incorporate it in a Java program One last thing before we bury our first macro The double slashes in the examples just above signify that everything following them on that line should be ignored by BeanShell as a comment As in Java and C C you can also embed comments in your BeanShell code by setting them off with pairs of as in the following example This is a long comment that covers several lines and will be totally ignored by BeanShell regardless of how many line
6. C END End of buffer C Go to matching bracket Cte 3 Go to previous next bracket GEL Go to line Selecting Text For details see the section called Selecting Text the section called Working With Words the section called Working With Lines the section called Working With Paragraphs and the section called Bracket Matching S Arrow Extend selection by one character or line CS Arrow Extend selection by one word or paragraph S PAGE_UP S PAGE_DOWN Extend selection by one screenful S HOME Extend selection to first non whitespace character of line beginning of line first visible line repeated presses S END Extend selection to last non whitespace character of line end of line last visible line repeated presses CS HOME Extend selection to beginning of buffer CS END Extend selection to end of buffer C Select code block Cte w l p Select word line paragraph Cte Ctl Select line range Ctra Select all ESCAPE Select none At Switch between range and rectangular selection mode CEFN Switch between single and multiple selection mode Cte i Invert selection 49 Keyboard Shortcuts Scrolling For details see the section called Multiple Views C Cj Ensure current line is visible and send focus to the text area C C n Center caret on screen CE WO Scroll up dow
7. Macro Basics Note that these variables are set at the beginning of macro execution If the macro switches views buffers or edit panes the variable values will be out of date In that case you can use the equivalent method calls Helpful Methods in the Macros Class Including message there are five static methods in the Macros class that allow you to converse easily with your macros They all encapsulate calls to methods of the Java platform s JOptionPane class e public static void message Component comp String message public static void error Component comp String message public static String input Component comp String prompt public static String input Component comp String prompt String defaultValue e public static int confirm Component comp String prompt int buttons The format of these four declarations provides a concise reference to the way in which the methods may be used The keyword public means that the method can be used outside the Macros class The alternatives are private and protected For purposes of BeanShell you just have to know that BeanShell can only use public methods of other Java classes The keyword static we have already discussed It means that the method does not operate on a particular object You call a static function using the name of the class like Macros rather than the name of a particular object like view The third word is the type of the value returned by th
8. SE SEQ TYPE OPERATOR gt lt SEQ gt SEQ TYPE OPERATOR gt lt SEQ gt The SEQ REGEXP Tag The SEQ REGEXP rule is similar to the SEQ rule except the match sequence is taken to be a regular expression In addition to the attributes supported by the SEQ tag the HASH CHAR attribute must be specified It must be set to the first character that the regular expression matches This rules out using regular expressions which can match more than one character at the start position The regular expression match cannot span more than one line either Es 10 V Here is an example of a SEQ REGEXP rule that highlights Perl s matcher constructions such as m Nd 9 SEQ REGEXP TYPE MARKUP HASH CHAR m AT WORD START TRUE m punct 1 sgiexom lt SEQ_REGEXP gt Regular expression syntax is described in Appendix E Regular Expressions The IMPORT Tag The IMPORT tag which must be placed inside a RULES tag loads all rules defined in a given ruleset into the current ruleset in other words it has the same effect as copying and pasting the imported ruleset The only required attribute DELEGATE must be set to the name of a ruleset To import a ruleset defined in the current mode just specify its name To import a ruleset defined in another mode specify a name of the form mode ruleset
9. 56 Appendix E Regular Expressions jEdit uses regular expressions to implement inexact search and replace A regular expression consists of a string where some characters are given special meaning with regard to pattern matching Within a regular expression the following characters have special meaning Positional Operators e matches at the beginning of a line e matches at the end of a line e b matches at a word break e NB matches at a non word break matches at the start of a word e N matches at the end of a word One Character Operators e matches any single character e Nd matches any decimal digit D matches any non digit n matches the newline character e s matches any whitespace character e S matches any non whitespace character e Nt matches a horizontal tab character Nw matches any word alphanumeric character NW matches any non word alphanumeric character e XN matches the backslash character Character Class Operator abc matches any character in the set a bor c e abc matches any character not in the set a bor c a z matches any character in the range a to z inclusive A leading or trailing dash will be interpreted literally 57 Regular Expressions s alnum alpha f blank cntrl digit graph lower print i punct y Space supper xdigit matches any alphanumeric character matches
10. 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 119 Implementing a Simple Plugin If a plugin core class will respond to EditBus messages it can be derived from EBP lugin in which case no explicit addToBus call is necessary Otherwise EditPlugin will suffice as a plugin base class Note that QuickNotepad uses the latter The Property File jEdit maintains a list of properties which are name value pairs used to store human readable strings user settings and various other forms of meta data During startup jEdit loads the default set of properties followed by plugin properties stored in plugin JAR files finally followed by user properties Some properties are used by the plugin API itself Others are accessed by the plugin using methods in the jEdit class Property files contained in plugin JARs must end with the filename extension props and have a very simple syntax which the following example illustrates Lines starting with are ignored name value another name another valu
11. Onthe Manage tab uncheck Hide libraries This will allow you to see plugins that are not loaded e Find the plugin on the Manage tab and uncheck it This will unload the plugin You will get a warning if this plugin does not support dynamic reloading If you get that warning you will need to restart jEdit to reload the plugin until the plugin is converted over to the 4 2 API e Recheck the plugin to reload it The jEdit web site contains a macro and an Ant task that can be used as an alternative method for dynamically reloading plugins If you have reached this point in the text you are probably serious about writing a plugin for jEdit Good luck with your efforts and thank you for contributing to the jEdit project 129 Chapter 19 Plugin Tips and Techniques Bundling Additional Class Libraries Recall that any class whose name ends with Plugin class is called a plugin core class JAR files with no plugin core classes are also loaded by jEdit the classes they contain are made available to other plugins Many plugins that rely on third party class libraries ship them as separate JAR files The libraries will be available inside the jEdit environment but are not part of a general classpath or library collection when running other Java applications A plugin that bundles extra JAR files must list them in the plugin class name jars property See the documentation for the EditPlugin class for details 130
12. lt property name install dir value gt lt path id project class path gt lt pathelement location jedit install dir jedit jar gt lt pathelement location gt lt path gt lt target name compile gt lt javac srcdir deprecation on includeJavaRuntime yes gt lt classpath refid project class path gt lt javac gt lt target gt 128 Implementing a Simple Plugin lt target name dis lt mkdir dir i t depends compile gt nstall dir jar jarfile fileset dir include include include include include fileset jar target lt project gt na na na na na install dir S jar name gt ons me class me props me html me actions xml me dockables xml For a full discussion of the Ant file format and command syntax you should consult the Ant documentation site Modifying this makefile for a different plugin will likely only require three changes the name of the plugin e the choice of compiler made by inserting and deleting the comment character and e the classpath variables for jedit jar any plugins this one depends on Reloading the Plugin Once you have compiled your plugin using the 4 2 API you will need to reload it to test it Follow these steps to reload your plugin without restarting jEdit From the Plugins menu open the Plugin Manager
13. pressing ESCAPI hide the search bar Note Incremental searches cannot be not recorded in macros If your macro needs to perform a search use the search and replace dialog box instead See Chapter 8 Using Macros for information about macros Search HyperSearch Bar shortcut C PERIOD displays the search bar if necessary gives it keyboard focus and selects the HyperSearch check box If this command is invoked while there is a selection the selected text will be searched for immediately and the search bar will not be shown If the HyperSearch check box is selected pressing Enter in the search string field will perform a HyperSearch in the current buffer Search HyperSearch for Word shortcut A PERIOD performs a HyperSearch for the word at the caret This command does not show the search bar or give it keyboard focus 30 Chapter 6 Editing Source Code Edit Modes An edit mode specifies syntax highlighting rules auto indent behavior and various other customizations for editing a certain file type This section only covers using existing edit modes information about writing your own can be found in Part IL Writing Edit Modes When a file is opened jEdit first checks the file name against a list of known patterns For example files whose names end with c are opened with C mode and files named Makefile are opened with Makefile mode If a suitable match based on file name cannot be found
14. Control scrolls a single line at a time Alt moves the caret up and down instead of scrolling e Alt Shift extends the selection up and down instead of scrolling 23 Editing Text Keyboard commands for scrolling the text area are also available View gt Scrolling gt Scroll to Current Line shortcut Cte C scrolls the text area in order to make the caret visible if necessary It does nothing if the caret is already visible View gt Scrolling gt Center Caret on Screen shortcut Cte C n moves the caret to the line in the middle of the screen View gt Scrolling gt Line Scroll Up shortcut C QUOTE scrolls the text area up by one line View gt Scrolling gt Line Scroll Down shortcut C SLASH scrolls the text area down by one line View gt Scrolling gt Page Scroll Up shortcut A QUOTE scrolls the text area up by one screenful View gt Scrolling gt Page Scroll Down shortcut A SLASH scrolls the text area down by one screenful The above scrolling commands differ from the caret movement commands in that they don t actually move the caret they just change the scroll bar position Transferring Text jEdit provides a rich set of commands for moving and copying text Commands are provided for moving chunks of text from buffers to registers and vice versa A register is a holding area for an arbitrary length of text with a single character name Most other programs can only transfer text to and from the
15. computer for example Has no effect when connecting to another instance via the edit server newplainview Opens the specified files in a new plain view For more information about views see the section called Multiple Views newview Opens the specified files in a new view reuseview Opens the specified files in an existing view quit Exits the currently running editor instance server Store the server port info in the file named server inside the settings directory Sserver name Store the server port info in the file named name File names for this parameter are relative to the settings directory noserver Do not attempt to connect to a running edit server and do not start one either wait Keeps the client open until the user closes the specified buffer in the server instance Does nothing if passed to the initial jEdit instance Use this switch if jEdit is being invoked by another program as an external editor otherwise the client will exit immediately and the invoking program will assume you have finished editing the given file Chapter 3 jEdit Basics Interface Overview A view is the jEdit term for an editor window It is possible to have multiple views open at once and each view can be split into multiple panes jEdit remembers the state of open views between editing sessions An open file is referred to as a buffer Unlike some editors where each buffer gets its own view jEdit
16. jEdit checks the first line of the file For example files whose first line is bin sh are opened with shell script mode Mode Selection File name and first line matching is done using glob patterns similar to those used in Unix shells Glob patterns associated with edit modes can be changed in the Editing pane of the Utilities gt Global Options dialog box Note that the glob patterns must match the file name or first line exactly so to match files whose first line contains begin you must use a first line glob of begin See Appendix D Glob Patterns for a description of glob pattern syntax The default edit mode for files which do not match any pattern can be set in the Editing pane as well The edit mode can be specified manually as well The current buffer s edit mode can be set on a one time basis in the Utilities Buffer Options dialog box see the section called The Buffer Options Dialog Box To set a buffer s edit mode for future editing sessions place the following in one of the first or last 10 lines of the buffer where edit mode is the name of the desired edit mode mode edit mode Syntax Highlighting Syntax highlighting is the display of programming language tokens using different fonts and colors This makes code easier to follow and errors such as misplaced quotes easier to spot All edit modes except for the plain text mode perform some kind of syntax highlighting The colors and styles used to highlight syntax
17. jEdit remembers open buffers views and split window configurations between editing sessions so you can get back to work immediately after starting jEdit This feature can be disabled in the General pane of the Utilities gt Global Options dialog box see the section called The General Pane The edit server and security Since Java does not provide any interprocess communication facility other than TCP IP jEdit takes extra precautions to prevent remote attacks Not only does the edit server pick a random TCP port number on startup it also requires that clients provide an authorization key a randomly generated number only accessible to processes running on the local machine So not only will bad guys have to guess a 64 bit integer they will need to get it right on the first try the edit server shuts itself off upon receiving an invalid packet In environments that demand absolute security the edit server can be disabled by specifying the noserver command line switch Command Line Usage On operating systems that support a command line jEdit can be passed various arguments to control its behavior When opening files from the command line a line number or marker to position the caret on can be specified like so jedit MyApplet java line 10 jedit thesis tex tmarker c Starting jEdit Command line switches begin with a Some take a parameter A file whose name begins with can be opened like so
18. jedit myfile Miscellaneous Options Option Effect log level Set the minimum log level to an integer between 1 and 9 Default is 7 Has no effect when connecting to another instance via the edit server usage Show a brief command line usage message without starting jEdit This message is also shown if an invalid switch was specified version Show the version number without starting jEdit Specifies the end of command line processing Further parameters are treated as file names even if they begin with a dash Configuration Options Option Effect plugins Enable loading of plugins Has no effect when connecting to another instance via the edit server See Chapter 9 Installing and Using Plugins noplugins Disable loading of plugins Has no effect when connecting to another instance via the edit server restore Restore previously open files on startup This is the default This feature can also be set permanently in the General pane of the Utilities Global Options dialog box see the section called The General Pane norestore Do not restore previously open files on startup run script Run the specified BeanShell script There can only be one of these parameters on the command line See the section called Running Scripts from the Command Line settings dir Store user specific settings in the directory named dir instead of the default user home jedit
19. macros in the Macros menu When scanning the names jEdit will delete underscore characters and the bsh extension for menu labels so that List_Useful_Information bsh for example will be displayed in the Macros menu as List Useful Information You can browse the user and system macro directories by opening the macros directory from the Utilities gt jEdit Home Directory and Utilities gt Settings Directory menus Macros can be opened and edited much like ordinary files from the file system browser Editing macros from within jEdit will automatically update the macros menu however if you modify macros from another program or add macro files to the macro directories you should run the Macros gt Rescan Macros command to update the macro list 45 Chapter 9 Installing and Using Plugins A plugin is an application which is loaded and runs as part of another host application Plugins respond to user commands and perform tasks that supplement the host application s features This chapter covers installing updating and removing plugins Documentation for the plugins themselves can be found in Help gt jEdit Help and information about writing plugins can be found in Part IV Writing Plugins The Plugin Manager Plugins gt Plugin Manager displays the plugin manager window The plugin manager lists all installed plugins clicking on a plugin in the list will display information about it To remove plugins select them multiple p
20. non whitespace text in the line AT WORD START If set to TRUE the sequence will only be highlighted if it occurs at the beginning of a word e EXCLUDE MATCH If set to TRUE the match will not be highlighted only the text before it will Here is a rule that highlights labels in Java mode for example XXX 76 Mode Definition Syntax lt MA RK_PRI EXCLUDE_MATCH TRUI EVIOUS AT_WHIT ESPACE END TRUE E gt lt MARK_PREVIOUS gt The MARK_FOLLOWING Tag The MARK_FOLLOWING rule which must be placed inside a RULES tag highlights from the start of the match to the next syntax token The text to match is specified between opening and closing MARK_FOLLOWING tags The following attributes are supported TYP token types AT INE S START If set to TRUI beginning of a line E The token type to highlight the text with See the section called Token Types for a list of E the sequence will only be highlighted if it occurs at the AT WHITESPACE END If set to TRUE the sequence will only be highlighted if it is the first non whitespace text in the line AT WORD START If set to TRUE the sequence will only be highlighted if it occurs at the beginning of a word EXCLUDE MATCH If set to TRUE the match will not be highlighted only the text after it will Here is a rule that highlights va
21. selectedLines array which represents the number of a selected line and apply the following routine e Get the buffer position of the start of the line expressed as a zero based index from the start of the buffer by calling textArea getLineStartOffset selectedLines i Move the caret to that position by calling textArea setCaretPosition e Find the first and last non whitespace characters on the line by calling textArea goToStartOfWhiteSpace andtextArea goToEndOfWhiteSpace The goTo methods in JEditTextArea take a single parameter which tells jEdit whether the text between the current caret position and the desired position should be selected Here we call textArea goToStartOfWhiteSpace false so that no text is selected then call textArea goToEndOfWhiteSpace true so that all of the text between the beginning and ending whitespace is selected Retrieve the selected text by storing the return value of textArea getSelectedText ina new variable text If the line is empty getSelectedText will return nu11 In that case we assign an empty string to text to avoid calling methods on a null object e Change the selected text to prefix text suffix by calling textArea setSelectedText If there is no selected text for example if the line is empty the prefix and suffix will be inserted without any intervening characters Compound edits Note the beginCompoundEdit an
22. void dir String dirname Displays the contents of directory dirname The format of the display is similar to the Unix 1s 1 command void mv String fromFile String toFile Moves the file named by romFileto toFile File pathToFile String filename Create a File object corresponding to filename Relative paths are resolved with reference to the BeanShell interpreter s working directory void pwd void Writes the current working directory of the BeanShell interpreter to the output stream of the current 110 BeanShell Commands process void rm String pathname Deletes the file name by pathname Component Commands e JFrame frame Component frame Displays the component in a top level JF rame centered and packed Returns the JF rame object e Object load String filename Loads and returns a serialized Java object from filename void save Component component String filename Saves component in serialized form to filename Font setFont Component comp int ptsize Set the font size of component to ptsize and returns the new font Resource Management Commands e URL getResource String path Returns the resource specified by path An absolute path must be used to return any resource available in the current classpath Script Execution Commands Thread bg String filename Run the BeanShell script named by filename in a copy of the existing namespace and in a separate thread Returns t
23. Code More code 70 Mode Definition Syntax If lineUpClosingBracket is set to false the line after a closing bracket will be lined up with the line containing the matching opening bracket For example in Lisp mode lineUpClosingBracket is set to false resulting in brackets being indented like so foo a parameter crazy p bar baz print hello world e If the previous line contains no opening brackets or if the doubleBracketIndent property is set to t rue the previous line is checked against the regular expressions in the indentNextLine and indentNextLines properties If the previous line matches the former the indent of the current line is increased and the subsequent line is shifted back again If the previous line matches the latter the indent of the current and subsequent lines is increased In Java mode for example the indentNextLine property is set to match control structures such 66 as if else while and so on The doubleBracketIndent property if set to the default of false results in code indented like so while objects hasNext Object next objects hasNext if next instanceof Paintable next paint g On the other hand settings this property to true will give the following result while objects hasNext Object next objects hasNext if next instanceof Paintable next paint g Here is the complete lt PROPS gt
24. GETO AE Ren 73 The TERMINATE Ta g mine RIDRAI Mr IATER 73 The SPAN Tag 3c or esr NU eR D UNUM 74 The SPAN REGEXP Tag xcii e pet epe NOI ient 75 The FOL SPAN Tag o de Seo Rr ee PI UR ee 75 The EOE SPANCREGEXP Tag noe terret ep tette Coo sesh e terrens 76 The MARK PREVIOUS Talu ceee arrea a m emen nhe nen he Henn ene 76 The MARK FOLLOWING Tae eot Stead os see eio tinent eee inei eo eoe erp ie vede 77 The SEQ Tag utter mp ERE AEI odes 77 The SEQ REGEXP Tag 3t eer er meret dened EE ri herr 78 The IMPORT Tag ete teer rege ear itr Te diet RETE Pr ege de Ert ceeds 78 The KEYWORDS Fag eerte rb tae RT EU 79 Token Types TE 79 1 Installing Edit Modes rete Pe Re age EEEE ENESES KESSE EEES 81 12 Updating Edit Modes for jEdit 4 1 4 2 sse 82 TT Writings Macros 2 so e e Gand eres e e Ero E Ua SOR PR d vo Ud es 83 13 M cro Basics yicsi sce ssedeseennsa oop pane E E EE A O E EEE dsshaumedenaSel ghebsvenegene seeds 84 Introducing BeanShell esessesseee HH emen 84 single Execution Macros 3 oett te ees itte ETA iex ione ds 84 The Mandatory First Example sse 85 Predefined Variables in BeanShell sss 87 Helpful Methods in the Macros Class ssse HH 88 BeanShell Dynamic Typing 1 eite remp ree rtr E EEES 89 Now For Something Useful esses Hee eere 89 14 A Dialog Based
25. However if a new instance of jEdit is being started the script will be run at the same time as all other startup scripts that is before the first view is opened 105 Macro Tips and Techniques If your script needs a view instance to operate on you can use the following code pattern to obtain one no matter how or when the script is being run void doSomethingUseful void run view jEdit getLastView put actual script body here if jEdit getLastView null VFSManager runInAWTThread this else run doSomethingUseful If the script is being run in a loaded instance it can be invoked to perform its work immediately However if the script is running at startup before an initial view exists its operation must be delayed to allow the view object first to be created and displayed In order to queue the macro s operation the scripted closure named doSomethingUseful implements the Runnable interface of the Java platform That interface contains only a single run method that takes no parameters and has no return value The macro s implementation of the run method contains the working portion of the macro Then the scripted object represented by a reference to this is passed to the runlInAWTThread method This schedules the macro s operations for execution after the startup routine is complete As this example illustrates the zunInAWTThread metho
26. If set to TRUE the span will not cross word breaks Note that the AT LINE START AT WHITESPACE END and AT WORD START attributes can also be used on the BEGIN and END elements Setting these attributes to the same value on both elements has the same effect as setting them on the SPAN element Here is a SPAN that highlights Java string literals which cannot include line breaks SPAN TYPE LITERAL1 NO LINE BREAK TRUE lt BEGIN gt lt BEGIN gt lt END gt lt END gt lt SPAN gt Here is a SPAN that highlights Java documentation comments by delegating to the JAV ADOC ruleset defined elsewhere in the current mode lt SPAN TYPE COMMENT2 DELEGATE JAVADOC gt lt BEGIN gt lt BEGIN gt 74 Mode Definition Syntax lt END gt lt lt SPAN gt END Here is a SPAN that highlights HTML cascading stylesheets inside STYLE tags by delegating to the main ruleset in the CSS edit mode lt SPAN TYPE MARKUP DELEGATE css MAIN lt BEGIN gt amp 1lt style amp gt lt B END amp 1 lt SPAN gt t style amp gt EN EGIN D The SPAN REGEXP Tag The SPAN REGI EXP rule is similar to the SPAN rule except the start sequence is taken to be a regular expression In addition to the attributes supported by the SPAN tag the HASH CHAR attribute
27. Note that the first unnamed ruleset in a mode is called MAIN One quirk is that the definition of the imported ruleset is not copied to the location of the IMPORT tag but rather to the end of the containing ruleset This has implications with rule ordering see the section called Rule Ordering Requirements Here is an example from the PHP mode which extends the inline JavaScript highlighting to support embedded PHP RULES SET JAVASCRIPT PHP gt lt SPAN TYPE MARKUP DELEGATE php PHP gt lt BEGIN gt amp 1t php lt BEGIN gt lt END gt amp gt lt END gt lt SPAN gt lt SPAN TYPE MARKUP DELEGATE php PHP gt lt BEGIN gt amp 1t lt BEGIN gt lt END gt amp gt lt END gt lt SPAN gt GI GATE php PHP lt SPAN TYPE MARKUP DE lt BEGIN gt amp 1t E END amp gt END SPAN 78 Mode Definition Syntax lt IMPORT DEL lt RULES gt EGATI E javascript MAIN The KEYWORDS Tag The KEYWORDS tag which must be placed inside a RULES tag and can only appear once specifies a list of keywords to highlight Keywords are similar to SEQs except that SEOs match anywhere in the text whereas keywords only match whole words Words are considered to be runs of text separated by non alphanumeric characters The KEYWORDS tag does
28. Plugin public static final String OPTION PREFIX options quicknotepad First we define a few static St ring data members to enforce consistent syntax for the name of properties we will use throughout the plugin public void createMenuItems Vector menuItems menultems addElement GUIUtilities loadMenu MENU This implementation of the EditPlugin createMenulItems method is very typical It uses a jEdit utility function to create the menu taking the list of actions from the quicknotepad property and the label from quotenotepad label If the plugin only had a single menu item for example an item activating a dockable window we would call GUIUtilities loadMenuItem instead of GUIUtilities loadMenu public void createOptionPanes OptionsDialog od od addOptionPane new QuickNotepadOptionPane This implementation of the EditPlugin createOptionPanes method adds a new instance of Qui ckNotepadOptionPane to the given instance of the Global Options dialog box The EditBus Plugins register EBComponent instances with the Edit Bus to receive messages reflecting changes in jEdit s state The message classes derived from EBMes sage 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
29. Re chives tete ote RETE PERLE ER eR aed 31 Syntax Haghbhehting esaet e teeth etes 31 Tabbing and Indentation essere 31 SOL TADS M tur osenieedeteee swans shuted obey eoonacsppntdauses sands NEEE ESES 32 Automatic Indent 4 o eee obe Re een cu ei iH 32 Commenting Qut Code ertt mere eo terrse ie tbe iot ere SOT h 33 Bracket Matching eost eee KET EEEE SURE RET REEERE ESS 33 Abbreviations eccess naeris ei Er Petri Pere Pret S ES EPRE ret ED 34 Positional Parameters o Ier 34 Folding 5 t tere PR e ORE iere EE Ebo OE PRESE ees 35 Collapsing and Expanding Folds eee 36 Navigating Around With Folds ssse HH 36 Miscellaneous Folding Commands se 36 NtrOWIDg i xo ebd e NR Peu der eee o ep o presa Et A ieee 37 T CUStOMUIZING JEGlt ioter odere te oo Ee rude e bad eave pr Sumas Ceo Pe pe ode re eyes 38 The Buffer Options Dialog Box sese 38 B ffet Local Properties 12 d het ient ei e snsanvegtews ino EP eee oerte 38 The Global Options Dialog Box see 39 The Abbreviations Pane 5 een ee ier teer ee EE IRE rey Re Ee 39 The Appearance Pane 0 eee ee cece nce ece eee HH eere 40 The Autosave and Backup Pane 0 eee eee cece ee ceeeceeeceeeea teen seen eeaes 40 The Context Menu Pane eterne entes vede PRU 40 The Docking Pane c rire Ere ttes 40 The Bdi ng Pane eei ete tete taste
30. Text sese eere 20 Undo nd R do er er ere eed irop tede ree i tines ces 21 Working With Words i e emet dete ee e leo e Vented per osten ive t etie 21 What s Word reco ec ee eet eee e RD PRRET RETI eoees 21 Working With Lines smiono Rr PIRE PERIERE Ras Ere rat Etpe ERR 22 Working With Paragraphs sseessseeseeee m e m e hme hee eere 22 Wrapping Long Lines net ep SERERE ERES RR VERRE PREMIER Tete 22 SOft Wrap ipee te vete ertt tere eoe Api ESES 23 Hard Wrap iig fem Ee eer er eerte ree EP edi rete eer 23 SCHOVING sce I pL 23 Transferring Text 5 o reo eee OVE tee O RE IKE ements 24 The Chipboard wes cose ett ret ot retire eave sh tuber te o ire esee RE 24 jEdit 4 2 User s Guide Quick Copy ui EUER nre e e e CECI 24 General Register Commands sss 25 Markers 325 RUN RN NND de NS eU E UE 26 search and Replace eee rere re eee odes esten festes iod vera ete seen weer 26 Searching For Text verte ie Se Re Meas ERE Ere ee rri cR eee 26 Replacing Text ido ek er ERES REPOS X SEPARAR e PATRES VOLES ERERUEEATE 27 HyperSearch ier Ie Weel betes town stil pO EISE ES 28 Multiple Eile Search i erret metr Rete EPI E rer RR 29 The Search Bar eto tenore dede Pe pere Py p yets 29 6 Editing Source Code s deep E ee sit p Poe ei eR 31 Edit Modes eror erro sh Soars tete See pred iet poe dee pte geo te veatrsneved ate vue o eg ved 31 Mode Selection eoe repo
31. a selected line If you want to leave the line s current text as an element of the modified line you must include the defined variable text as part of the BeanShell expression that you enter Utilities gt BeanShell gt Evaluate Selection evaluates the selected text as a BeanShell script and replaces it 84 Macro Basics with the return value of the statement Using Evaluate Selection is an easy way to do arithmetic calculations inline while editing BeanShell uses numbers and arithmetic operations in an ordinary intuitive way Try typing an expression like 3745 856 74 in the buffer select it and choose Utilities gt BeanShell gt Evaluate Selection The selected text will be replaced by the answer 3205794 Console plugin You can also do the same thing using the BeanShell interpreter option of the Console plugin The Mandatory First Example Macros message view Hello world Running this one line script causes jEdit to display a message box more precisely a JOpt ionPane object with the traditional beginner s message and an OK button Let s see what is happening here This statement calls a static method or function named message in jEdit s Macros class If you don t know anything about classes or static methods or Java or C which employs the same concept you will need to gain some understanding of a few terms Obviously this is not the place for academic precision but if you are entirely new to obje
32. any alphabetical character matches a space or horizontal tab matches a control character matches a decimal digit matches a non space non control character matches a lowercase letter same as graph but also space and tab matches a punctuation character matches any whitespace character including newlines matches an uppercase letter matches a valid hexadecimal digit Subexpressions and Backreferences e abc matches whatever the expression abc would match and saves it as a subexpression Also used for grouping e pure grouping operator does not save contents e embedded comment ignored by engine e positive lookahead the regular expression will match if the text in the brackets matches but that text will not be considered part of the match e negative lookahead the regular expression will match if the text in the brackets does not match and that text will not be considered part of the match e nwhere 0 n lt 10 matches the same thing the nth subexpression matched Can only be used in the search string e nwhere 0 n lt 10 substituted with the text matched by the nth subexpression Can only be used in the replacement string Branching Alternation Operator e aj bmatches whatever the expression a would match or whatever the expression b would match Repeating Operators These symbols operate on the previous atomic expression 58 Regular Expressio
33. calls fora String If you are a Java programmer you might wonder about a few things missing from this one line program There is no class definition for example You can think of a BeanShell script as an implicit definition of amain method in an anonymous class That is in fact how BeanShell is implemented the class is derived from a BeanShell class called XThis If you don t find that helpful just think of a script as one or more blocks of procedural statements conforming to Java syntax rules You will also get along fine for the most part with C or C syntax if you leave out anything to do with pointers or memory management Java and BeanShell do not have pointers and deal with memory management automatically Another missing item from a Java perspective is a package statement In Java such a statement is used to bundle together a number of files so that their classes become visible to one another Packages are not part of BeanShell and you don t need to know anything about them to write BeanShell macros Finally there are no import statements in this script In Java an import statement makes public classes from other packages visible within the file in which the statement occurs without having to specify a fully qualified class name Without an import statement or a fully qualified name Java cannot identify most classes using a single name as an identifier jEdit automatically imports a number of commonly used packages into the names
34. doesn t do anything Without more code it will not respond to user input and will not accomplish any text manipulation The remainder of the script deals with these two requirements The Action Listener this method will be called when a button is clicked or when ENTER is pressed void actionPerformed e if e getSource cancel dialog dispose processText The method actionPerformed nested inside prefixSuffixDialog implements the implicit ActionListener interface It looks at the source of the Act ionEvent determined by a call to get Source What we do with this return value is straightforward if the source is not the Cancel button we call the processText method to insert the prefix and suffix text Then the dialog is closed by calling its dispose method The ability to implement interfaces like Act ionListener inside a BeanShell script is one of the more powerful features of the BeanShell package this technique is discussed in the next chapter see the section called Implementing Classes and Interfaces Get the User s Input this is where the work gets done to insert the prefix and suffix void processText prefix prefixField getText suffix suffixField getText if prefix length 0 amp amp suffix length 0 return prefixField addCurrentToHistory suffixField addCurrentToHistory The method processText does the work of our
35. macro First we obtain the input from the two text fields with a call to their get Text methods If they are both empty there is nothing to do so the method returns If there is input any text in the field is added to that field s stored history list by calling addCurrentToHistory We do not need to test the pre ixFieldorsuffixField controls for null or empty values because addCurrentToHistory does that internally 97 A Dialog Based Macro Call jEdit Methods to Manipulate Text text manipulation begins here using calls to jEdit methods buffer beginCompoundEdit selectedLines textArea getSelectedLines for i 0 i lt selectedLines length i offsetBOL textArea getLineStartOffset selectedLines i l textArea setCaretPosition offsetBOL textArea goToStartOfWhiteSpace false textArea goToEndOfWhiteSpace true text textArea getSelectedText if text null text textArea setSelectedText prefix text suffix buffer endCompoundEdit The text manipulation routine loops through each selected line in the text buffer We get the loop parameters by calling textArea getSelectedLines which returns an array consisting of the line numbers of every selected line The array includes the number of the current line whether or not it is selected and the line numbers are sorted in increasing order We iterate through each member of the
36. make it fit within the wrap column position If nothing is selected the paragraph containing the caret is formatted instead See the section called Wrapping Long Lines for information and word wrap and changing the wrap column Edit gt Text gt Delete Paragraph shortcut Cte qd deletes the paragraph containing the caret Wrapping Long Lines The word wrap feature splits lines at word boundaries in order to fit text within a specified wrap margin The wrap margin position is indicated in the text are as a faint blue vertical line There are two wrap modes soft and hard they are described below The current wrap mode is shown in the status bar see the section called The Status Bar The wrap mode can be changed in one of the following ways 22 Editing Text Ona global or mode specific basis in the Editing pane of the Utilities gt Global Options dialog box See the section called The Editing Pane e Inthe current buffer for the duration of the editing session e By clicking the status bar indicator In the Utilities gt Buffer Options dialog box See the section called The Buffer Options Dialog Box e From the keyboard if a keyboard shortcut has been assigned to the Toggle Word Wrap command in the Shortcuts pane of the Utilities gt Global Options dialog box By default this command does not have a keyboard shortcut Inthe current buffer for future editing sessions by placing the foll
37. not define any attributes Each child element of the K1 EYWORDS tag is an element whose name is a token type and whose content is the keyword to highlight For example the following rule highlights the most common Java keywords KI Y K K K K lt lt lt lt K lt WORDS gt EYWORDI gt if lt K EYWORD1 gt else lt EYWORD3 gt int lt K EYWORD3 gt void lt EYWORDS gt Token Types Parser rules can highlight tokens using any of the following token types K K EYWORD1 EYWORD1 YWORD3 EYWORD3 e NULL no special highlighting is performed on tokens of type NULL COMMEN 1 COMMEN 2 e COMMENT3 e COMMENT4 e FUNCTION INVALID e KEYWORD1 e KEYWORD2 e KEYWORD3 KEYWORD4 ABEL ITERAL1 jITERAL2 79 Mode Definition Syntax iT ERAL iT ERAL MAR OPERATOR KUP 80 Chapter 11 Installing Edit Modes jEdit looks for edit modes in two locations the modes subdirectory of the jEdit settings directory and the modes subdirectory of the jEdit install directory The location of the settings directory is system specific see the section called The jEdit Settings Directory Each mode directory contains a catalog file All edit modes contained in that directory must be listed in the catalog otherwise they will not be availabl
38. save the temporary macro 44 Using Macros contents it is immediately available for playback Macros gt Run Temporary Macro shortcut C m C p plays the macro recorded to the Temporary_Macro bsh buffer Only one temporary macro is available at a time If you begin recording a second temporary macro the first is erased and cannot be recovered unless you have saved the contents to a file with a name other than Temporary_Macro bsh If you do not save the temporary macro you must keep the buffer containing the macro script open during your jEdit session To have the macro available for your next jEdit session save the buffer Temporary_Macro bsh as an ordinary macro with a descriptive name of your choice The new name will then be displayed in the Macros menu Running Macros Macros supplied with jEdit as well as macros that you record or write are displayed under the Macros menu in a hierarchical structure The jEdit installation includes about 30 macros divided into several major categories Each category corresponds to a nested submenu under the Macros menu An index of these macros containing short descriptions and usage notes is found in Appendix F Macros Included With jEdit To run a macro choose the Macros menu navigate through the hierarchy of submenus and select the name of the macro to execute You can also assign execution of a particular macro to a keyboard shortcut toolbar button or context menu using the Macro Short
39. scroll pane with a text area Above the scroll pane we will place a panel containing a small tool bar and a label displaying the path of the current notepad file We have identified three user actions that need implementation here chooseFile saveFile and copyToBuf fer As noted earlier we also want the text area to change its appearance in immediate response to a change in user options settings In order to do that the window class must respond to a PropertiesChanged message from the EditBus Unlike the EBP lugin class the EBComponent interface does not deal with the component s actual subscribing and unsubscribing to the EditBus To accomplish this we use a pair of methods inherited from the Java platform s JComponent class that are called when the window is made visible and when it is hidden These two methods addNotify and removeNotify are overridden to add and remove the visible window from the list of EditBus subscribers We will provide for two minor features when the notepad is displayed in the floating window First when a floating plugin window is created we will give the notepad text area input focus Second when the notepad if floating and has input focus we will have the Escape key dismiss the notepad window An AncestorListener anda KeyListener will implement these details Here is the listing for the data members the constructor and the implementation of the EBComponent interface public class Q
40. see the section called The Autosave and Backup Pane The default behavior is to back up the original contents to the buffer s file name suffixed with a tilde For example a file named paper tex is backed up to paper tex The Max number of backups setting determines the number of backups to save Setting this to zero disables the backup feature Settings this to more than one adds numbered suffixes to file names By default only one backup is saved Ifthe Backup directory setting is non empty backups are saved in that location Otherwise they are saved in the same directory as the original file The latter is the default behavior The Backup filename prefix setting is the prefix that is added to the backed up file name This is empty by default The Backup filename suffix setting is the suffix that is added to the backed up file name This is by default e Backups can optionally be saved in a specified backup directory instead of the directory of the original file This can reduce clutter 12 Working With Files The Backup on every save option is off by default which results in a backup only being created the first time a buffer is saved in an editing session If switched on backups are created every time a buffer is saved Line Separators Unix systems use newlines n to mark line endings in text files The MacOS uses carriage returns Nx Windows uses a carriage return followed by a new
41. system clipboard in jEdit the system clipboard is just another register with the special name S The Clipboard jEdit offers the usual text transfer operations that operate on the register Edit gt Cut shortcut C x places the selected text in the clipboard and removes it from the buffer Edit gt Copy shortcut C c places the selected text in the clipboard and leaves it in the buffer Edit gt Paste shortcut C v inserts the clipboard contents in place of the selection or at the caret position if there is no selection The Cut and Copy commands replace the old clipboard contents with the selected text There are two alternative commands which add the selection at the end of the existing clipboard contents instead of replacing it Edit gt More Clipboard gt Cut Append shortcut C e C u appends the selected text to the clipboard then removes it from the buffer After this command has been invoked the clipboard will consist of the former clipboard contents followed by a newline followed by the selected text Edit gt More Clipboard gt Copy Append shortcut C e C a is the same as Cut Append except it does not remove the selection from the buffer Quick Copy The quick copy feature is usually found in Unix text editors Quick copy is disabled by default but it can be enabled in the Mouse pane of the Utilities gt Global Options dialog box The quick copy feature is accessed using the middle mouse button If you do not ha
42. the shortcut is already assigned The Status Bar Pane The Status Bar option pane contains settings to customize the status bar or disable it completely See the section called The Status Bar The Syntax Highlighting Pane The Syntax Highlighting pane can be used to customize the fonts and colors for syntax highlighting See the section called Syntax Highlighting The Text Area Pane The Text Area pane contains settings to customize the appearance of the text area See the section called Interface Overview The Tool Bar Pane The Tool Bar option pane lets you edit the tool bar or disable it completely See the section called Multiple Views The View Pane The View option pane lets you change various settings related to the editor window s appearance including the arrangement of dockable windows and if the search bar and buffer switcher should be visible See the section called Multiple Views 41 Customizing jEdit The File System Browser Panes The File System Browser group contains two option panes General and Colors The former contains various file system browser settings The latter configures glob patterns used for coloring the file list See the section called The File System Browser for more information The jEdit Settings Directory jEdit stores settings macros and plugins as files inside the settings directory In most cases editing these files by hand is not necessary since grap
43. will be checked in order and the first rule will be the first to match However if you write FOO it will be highlighted using the second rule which is exactly what you would expect Per Ruleset Properties The PROPS tag described in the section called The PROPS Tag can also be placed inside the RULES tag to define ruleset specific properties The following properties can be set on a per ruleset basis e commentEnd the comment end string commentStart the comment start string lineComment the line comment string This allows different parts of a file to have different comment strings in the case of HTML for example in HTML text and inline JavaScript For information about the commenting commands see the section called Commenting Out Code The TERMINATE Tag The TERMINATE rule which must be placed inside a RULES tag specifies that parsing should stop after the specified number of characters have been read from a line The number of characters to terminate after should be specified with the AT CHAR attribute Here is an example 73 Mode Definition Syntax lt TERMINATE AT CHAR 1 gt This rule is used in Patch mode for example because only the first character of each line affects highlighting The SPAN Tag The SPAN rule which must be placed inside a RULI The start and end strings are specified inside child e are supported ES tag highlights text between a star
44. with commands for docking the window in one of four sides of the view On each side of the text area where there are docked windows a strip of buttons is shown There is a button for activating each docked window as well as a close box and a popup menu button which when clicked shows a menu for moving or undocking the currently selected window The popup menu also contains a command for opening a new floating instance of the current window jEdit Basics The commands in the View gt Docking menu move keyboard focus between docking areas Dockable windows can also be configured in the Docking pane of the Utilities gt Global Options dialog box For power users Each dockable has three commands associated with it one is part of the menu bar and opens the dockable The other two commands are Window Name Toggle opens the dockable window if it is hidden and hide it if its already open Window Name New Floating Instance opens a new instance of the dockable in a floating window regardless of the docking configuration For example this can be used to view two different directories side by side in two file system browser windows A new floating instance can also be opened from the dockable window s popup menu These commands cannot be invoked from the menu bar However they can be added to the tool bar or context menu and given keyboard shortcuts see the section called The Global Options Dialog Box The Status Bar T
45. Author s name message 4 authorField message 5 Box createVerticalStrut 10 message 6 Enter description message 7 descFielg message 8 Box createVerticalStrut 5 if JOptionPane OK OPTION JOptionPane showConfirmDialog view message title JOptionPane OK CANCEL OPTION JOptionPane QUESTION MESSAGE return null remainder of macro script omitted end excerpt from Write File Header bsh This macro takes several items of user input and produces a formatted file header at the beginning of the buffer The full macro is included in the set of macros installed by jEdit There are a number of input features of this excerpt worth noting e The macro uses a total of seven visible components Two of them are created behind the scenes by showConfirmDialog the rest are made by the macro To arrange them the script creates an array of Ob ject objects and assigns components to each location in the array This translates to a fixed top to bottom arrangement in the message box created by showConfirmDialog e The macro uses JTextField objects to obtain most of the input data The fields nameField and authorField are created with constructors that take the initial default text to be displayed in the field as a parameter When the message box is displayed the default text will appear and can be altered or deleted by the user 101 Macro Tips and Techniques e The text f
46. CEL OPTION orJOptionPane OK CANCEL OPTION The return value of the method is also an int and should be tested against the value of other predefined constants JOptionPane YES OPTION JOptionPane NO OPTION JOptionPane OK OPTION or JOptionPane CANCEL OPTION We ve looked at using Macros message To use the other methods you would write something like the following Macros error view Goodbye cruel world 88 Macro Basics String result Macros input view Type something here String result Macros input view When were you born I don t remember I was very young at the time int result Macros confirm Do you really want to learn about BeanShell JOptionPane YES NO OPTION In the last three examples placing the word St ring or int before the variable name result tells BeanShell that the variable refers to an integer or a St ring object even before a particular value is assigned to the variable In BeanShell this declaration of the type of result is not necessary BeanShell can figure it out when the macro runs This can be helpful if you are not comfortable with specifying types and classes just use your variables and let BeanShell worry about it Note that macros are not limited to using these methods for presenting a user interface In fact full blown user interfaces using the Java Swing APIs are also possible and will be covered later on in Chapter 14 A Dialog Based Macro
47. ERE ESTIS edere RS 40 The General Pane eee S e dd Pee Ups 40 The Gutter Pane serne ertet eter oth ro oet pe ETUR or Tende ea Se loeo e o Epi ted 40 The Mouse Pane e Re PES 40 The Printing Pane nis uo reete ciere e havea INO E ERES 41 The Plugin Manager Pane sseeeseee m e m e Hee 41 The Proxy Servers Pane nicer terere syoiaadasta seawaevoneassecssteassys 41 The Shortcuts Pane 2 eftt serrer IER et Eve cin EEN ds 41 The Status Bar Pane 2 ette fe te eet rS EOE sees 41 The Syntax Highlighting Pane 2 0 0 sss 41 The Text Area Pane onte ure noceret ete EPI re eris 41 The Tool Bar Pane tete eerte tener EES ESES 41 The Wiew Pane iiS edo 41 The File System Browser Panes esee 42 The jEdit Settings Directory sess 42 S USE Macros eo ioesccectis te cote n tees sette etae escas eae eue ates eeu td oa duse e REPE RUS 44 R cording Macros wits i ire Ies eee bee e ner ete EE ree eee oe E Regen 44 RUNNIN MACOS c 45 How jEdit Organizes Macros sss Herrn 45 9 Installing and Using Plugins 5 rette rei eere hte E e EO D RPIH SEDI PERS 46 The Plugin Manager ete ern De I See E EID y RR eE 46 Installing and Updating Plugins ese He 46 A Keyboard Shortcuts t rp tree oer ere aei esy eoe aep dore yen 48 B The Activity Log etre n a E Eoo ee PEE SERE Seaton peed 53 jEdit 4 2 User s Guide C History Text Fields ci oft e
48. EYWORD1 HASH CHAR amp lt DELEGATE EXPRESSION gt GIN gt amp 1lt ftl gt lt ND gt amp gt lt END gt REGEXP gt BEGIN gt EOL_SPAN tags The following attributes are supported PE The token type to highlight the span with See the section called Token Types for a list of LINE START If set to TRUE the span will only be highlighted if the start sequence occurs at the beginning of a line EX the span will only be highlighted if the sequence is the first non whitespace text in the line 75 Mode Definition Syntax e AT WORD START If set to TRU the beginning of a word GJ DELEGATE text inside the span will be highlighted with the the span will only be highlighted if the start sequence occurs at specified ruleset To delegate to a ruleset defined in the current mode just specify its name To delegate to a ruleset defined in another mode specify a name of the form mode ruleset Note that the first unnamed ruleset in a mode is called MAIN e EXCLUDE_MATCH If set to TRUE the start and end sequences will not be highlighted only the text between them will Here is an EOL_SPAN that highlights C comments lt EOL_SPAN TYPI The EOL_SPAN_REGEXP Tag The EOL_SPAN_REGEXP rule is similar to the EOL_ SPAN rule be a regular expression In addition to the attributes supported by attribute must be specified It must be set to th
49. Keywords BeanShell uses special keywords to refer to variables or methods defined in the current or an enclosing block s scope The keyword this refers to the current scope The keyword super refers to the immediately enclosing scope e The keyword global refers to the top level scope of the macro script The following script illustrates the use of these keywords a top n foo a middle n bar a bottom n textArea setSelectedText global a textArea setSelectedText super a equivalent to textArea setSelectedText this a textArea setSelectedText a bar foo When the script is run the following text is inserted in the current buffer top middle bottom Implementing Classes and Interfaces As discussed in the macro example in Chapter 14 A Dialog Based Macro scripted objects can implicitly implement Java interfaces such as Act ionListener For example myRunnable run System out println Hello world return this Runnable r myRunnable new Thread r start Frequently it will not be necessary to implement all of the methods of a particular interface in order to specify the behavior of a scripted object To prevent BeanShell from throwing exceptions for missing interface methods implement the invoke method which is called when an undefined method is invoked on a scripted object Typically the implementation of this method wi
50. Line Numbers shortcut C e C t command is invoked Note this command only takes effect until the view is closed To have line numbers visible all the time enable the appropriate setting in the Gutter pane of the Utilities gt Global Options dialog box Switching Buffers In addition to using the drop down list at the top of the view as documented in the previous section the current buffer can also be switched using menu item commands and their keyboard shortcuts View gt Go to Previous Buffer keyboard shortcut C PAGE_UP switches to the previous buffer in the list View gt Go to Next Buffer keyboard shortcut C PAGE DOWN switches to the next buffer in the list View gt Go to Recent Buffer keyboard shortcut C BACK QUOTE flips between the two most recently edited buffers View gt Show Buffer Switcher keyboard shortcut A BACK_QUOTE has the same effect as clicking on the buffer switcher combo box If you prefer an alternative graphical paradigm for switching buffers take a look at one of these plugins e BufferList BufferSelector jEdit Basics e BufferTabs If you decide to use one of these plugins you can hide the popup menu buffer switcher in the View pane of the Utilities gt Global Options dialog box A number of plugins that implement fast keyboard based buffer switching are available as well e FastOpen e Openlt e SwitchBuffer Multiple Views As documented at the beginning of this cha
51. Macro vos i rige eere Perret EE IR Pre Reha 92 Use of the Macro erroe ree febre esr OE EESE RE ESEE EE S 92 Lasting of the Macro oss EDO WR Co edo rs 92 Analysis o the Macio ce aues teure tese Caro abe o opes thet nade ret dee Ce ibd et pedes voee rU 94 Inport Statements sco bss een m ies ete ve x Er EE rte Crede 94 Create the Dialog 32 inte qt tto deti S Ee INSEL Ene ded eot der due due nene 94 Create the Text Fields 5 2 ite eU este ete esa 95 Create the Buttons Joiner eot et eter re ERR ep vex Qro Een dee PRU Eo EE HN DES abusers 96 Register the Action Listeners ess Hem 96 Make the Dialog Visible nerd rere hte Feet des 96 The Action Listener eet eme cen eheu ET een b evens 97 Getthe Users Input em af cece cede ree eter EPI ERR 97 Call jEdit Methods to Manipulate Text se 98 The Main Routine tenerte Prem EE EE E EREHE E 99 vi jEdit 4 2 User s Guide 15 Macro Tips and Techniques vesine noriai cece cece cece HH Ie 100 Getting Input Tor Macro beet ipie Debt Neas 100 Getting a Single Line of Text sess 100 Getting Multiple Data Items sss 100 Selecting Input From a List 2 0 00 cece cece teen seen seca eeee sean eeaeeees 102 Using a Single Keypress as Input 103 Startup Scripts PD Een 104 Running Scripts from the Command Line eee 105 Advanced BeanShell Techniques ssseem IH 106 Bean
52. Macros Included With jEdit Selections Single Space Buffer bsh Removes every second line if they are all blank 67 Part Il Writing Edit Modes This part of the user s guide covers writing edit modes for jEdit Edit modes specify syntax highlighting rules auto indent behavior and various other customizations for editing different file types For general information about edit modes see the section called Edit Modes This part of the user s guide was written by Slava Pestov lt slava jedit org gt Chapter 10 Mode Definition Syntax Edit modes are defined using XML the extensible markup language mode files have the extension xml XML is a very simple language and as a result edit modes are easy to create and modify This section will start with a short XML primer followed by detailed information about each supported tag and highlighting rule Editing a mode or a mode catalog file within jEdit will cause the changes to take effect immediately If you edit modes using another application the changes will take effect after the Utilities gt Reload Edit Modes command is invoked An XML Primer A very simple XML file which also happens to be an edit mode looks like so xml version 1 0 lt DOCTYPE MODE SYSTEM xmode dtd T MODE lt PROPS gt lt PROPERTY NAME commentStart VALUE gt lt PROPERTY NAME commentEnd VAL
53. Returns the name of the file or other source from which the BeanShell interpreter is reading 113 Part IV Writing Plugins This part of the user s guide covers writing plugins for jEdit Like jEdit itself plugins are written primarily in Java While this guide assumes some working knowledge of the language you are not required to be a Java wizard If you can write a useful application of any size in Java you can write a plugin This part of the user s guide was written by John Gellene lt jgellene nyc rr com gt Chapter 17 Introducing the Plugin API The jEdit Plugin API provides a framework for hosting plugin applications without imposing any requirements on the design or function of the plugin itself You could write an application that performs spell checking displays a clock or plays chess and turn it into a jEdit plugin There are currently over 50 released plugins for jEdit While none of them play chess they perform a wide variety of editing and file management tasks A detailed listing of available plugins is available at plugins jedit org You can also find beta versions of new plugins in the Downloads area of community jedit org Using the Plugin Manager feature of jEdit users with an Internet connection can check for new or updated plugins and install and remove them without leaving jEdit See Chapter 9 Installing and Using Plugins for details Requirements for plugging in to jEdit are as
54. Shell s Convenience Syntax esseseee 106 Special BeanShell Keywords seee seen sean scans 107 Implementing Classes and Interfaces esee 107 Debus eins Macros I CH T 108 Identifying Exceptions seem Ie 108 Using the Activity Log as a Tracing Tool eeeene 108 16 BeanShell Commands E e E eee eem ee He mee hee menn 110 Output Commands 2 trei teer Pete ER Eh Free x Pe ie Re Re PR DERE SETUP Re 110 File Management Commands sese mem een 110 Component Commands te hereto rre ores Re rte Pre Pea Rhe 111 Resource Management Commands sese 111 Script Execution Commands sissies erne ie ener 111 BeanShell Object Management Commands ses 112 Other Commands o iv DR RE DUNS d 113 IV Waitin PIU SINS suot E ak yatae te eek De SON E Otis tee E A osten olore aves 114 17 Introducing the Plugin API rr Re Ree RW epe UU tei 115 18 Implementing a Simple Plugin eseee HH 117 How Plugins are Loaded ce ceceeececceecneeneceeeneceeeeeaeeeecaeeeeeeeeeeeeneeaeenes 117 The QuickNotepadPlugin Class esee 118 The EditBus 4 sss eee deve tI IURI E TEENE 119 The Property File hr oerte EES EEE EEE O STRESS 120 The Action Catalog 2 ret testeur rie ode npe ESEE reb e px 121 The Dockable Window Catalog sese HH 122 The QuickNotepad Class
55. The directory will be created automatically if it does not exist Has no effect when connecting to another instance via the edit server See the section called The jEdit Settings Directory nosettings Start jEdit without loading user specific settings startupscripts Run startup scripts This is the default Has no effect when connecting to another instance via the edit server See the section called Startup Scripts nostartupscripts Disable startup scripts Has no effect when connecting to another instance via the edit server Edit Server Options See Chapter 2 Starting jEdit for a brief description of the edit server Option Effect background Run jEdit in background mode In background mode the edit server will continue listening for client connections even after all views are closed Has 4 Starting jEdit Option Effect no effect when connecting to another instance via the edit server nobackground Disable background mode This is the default Has no effect when connecting to another instance via the edit server gui Open an initial view This is the default Has no effect when connecting to another instance via the edit server nogui Do not open an initial view and instead only open one when the first client connects Can only be used in combination with the background switch You can use this switch to pre load jEdit when you log in to your
56. Trailing Whitespace shortcut Cte r removes all whitespace from the end of each selected line or the current line if there is no selection Soft Tabs Files containing hard tab characters may look less than ideal if the default tab size is changed so some people prefer using multiple space characters instead of hard tabs to indent code This feature is known as soft tabs Soft tabs can be enabled or disabled in one of several ways Ona global or mode specific basis in the Editing pane of the Utilities gt Global Options dialog box See the section called The Editing Pane Inthe current buffer for the duration of the editing session in the Utilities gt Buffer Options dialog box See the section called The Buffer Options Dialog Box Inthe current buffer for future editing sessions by placing the following in one of the first or last 10 lines of the buffer where flag is either true or false noTabs flag Changing the soft tabs setting has no effect on existing tab characters it only affects subsequently inserted tabs Edit gt Indent gt Spaces to Tabs converts soft tabs to hard tabs in the current selection or the entire buffer if nothing is selected Edit gt Indent gt Tabs to Spaces converts hard tabs to soft tabs in the current selection or the entire buffer if nothing is selected Automatic Indent The auto indent feature inserts the appropriate number of tabs or spaces at the beginning of a line by l
57. UE gt lt PROPS gt lt RULES gt lt SPAN TYPE COMMENT1I gt lt BEGIN gt lt BEGIN gt lt END gt lt END gt lt SPAN gt lt RULES gt lt MODE gt Note that each opening tag must have a corresponding closing tag If there is nothing between the opening and closing tags for example TAG TAG the shorthand notation TAG gt may be used An example of this shorthand can be seen in the PROPERTY tags above XML is case sensitive Span or span is not the same as SPAN To insert a special character such as or literally in XML for example inside an attribute value you must write it as an entity An entity consists of the character s symbolic name enclosed with amp and The most frequently used entities are e amp lt The less than lt character e amp gt The greater than gt character e amp amp The ampersand amp character For example the following will cause a syntax error lt SEQ TYPE OPERATOR gt amp lt SEQ gt Instead you must write 69 Mode Definition Syntax SEQ TYPE OPERATOR amp amp lt SEQ gt Now that the basics of XML have been covered the rest of this section will cover each construct in detail The Preamble and MODE tag Each mode definition must begin with the following lt xml version 1 0 gt lt DOCTYPE MODE SYSTEM xmode dtd gt Each mode d
58. an operate on any register allowing an arbitrary number of text chunks to be retained at a time Each command prompts for a single character register name to be entered after being invoked Pressing ESCAPE instead of specifying a register name cancels the operation Note that the content of registers other than the clipboard and quick copy register are automatically saved between jEdit sessions Edit gt More Clipboard gt Cut to Register shortcut C r C x key stores the selected text in the specified register removing it from the buffer Edit gt More Clipboard gt Copy to Register shortcut C r C c key stores the selected text in the specified register leaving it in the buffer Edit gt More Clipboard gt Cut Append to Register shortcut Ctr C u key adds the selected text to the existing contents of the specified register and removes it from the buffer Edit gt More Clipboard gt Copy Append to Register shortcut C r C a key adds the selected text to the existing contents of the specified register without removing it from the buffer Edit gt More Clipboard gt Paste from Register shortcut C r C v key replaces the selection with the contents of the specified register The following three commands display dialog boxes instead of prompting for a register name Edit gt More Clipboard gt Paste Previous shortcut Cte C v displays a dialog box listing the 20 most recently copied and pasted text strings Edit gt More C
59. ard input in jEdit is normally managed by the derived class DefaultInputHandler One of the methods in the InputHandler class handles input from a single keypress public void readNextChar String prompt String code 103 Macro Tips and Techniques When this method is called the contents of the prompt parameter is shown in the view s status bar The method then waits for a key press after which the contents of the code parameter will be run as a BeanShell script with one important modification Each time the string char appears in the parameter script it will be substituted by the character pressed The key press is consumed by readNextChar It will not be displayed on the screen or otherwise processed by jEdit Using readNextChar requires a macro within the macro formatted as a single potentially lengthy string literal The following macro illustrates this technique It selects a line of text from the current caret position to the first occurrence of the character next typed by the user If the character does not appear on the line no new selection occurs and the display remains unchanged Next Char bsh script new StringBuffer 512 script append start textArea getCaretPosition script append line textArea getCaretLine script append end textArea getLineEndOffset line 1 script append text buffer getText start end start script appen
60. as tooltip text for the buttons There is also a propertiesChanged method for the toolbar that sets the text and visibility of the label containing the notepad file path The QuickNotepadOptionPane Class Using the default implementation provided by Abst ractOpt ionPane reduces the preparation of an option pane to two principal tasks writing a init method to layout and initialize the pane and writing a_save method to commit any settings changed by user input If a button on the option pane should trigger another dialog such as a JFileChooser or jEdit s own enhanced VFSFileChooserDialog the option pane will also have to implement the ActionListener interface to display additional components The QuickNotepad plugin has only three options to set the path name of the file that will store the notepad text the visibility of the path name on the tool bar and the notepad s display font Using the shortcut methods of the plugin API the implementation of init looks like this public class QuickNotepadOptionPane extends AbstractOptionPane implements ActionListener private JTextField pathName private JButton pickPath private FontSelector font public void _init showPath new JCheckBox jEdit getProperty QuickNotepadPlugin OPTION_PREFIX show filepath title Edit getProperty QuickNotepadPlugin OPTION_PR equals true addComponent showPath LI GI FIX show filepath
61. ased seed Pee n rS 54 D Glob Patterns oeste e o tet et t aensi eed Sas abe sdeecueab ted gebes 55 E Regular Expressions v ER Nee e ote TE en iesu Ue ie reus 57 F Mactos Included With JEdit 5 uci ote ctore teeth sh sume seseeeaeste war Pr xe oerte 60 Chipboard Macros 1 o tierce t deret egt ea eei Du Eee ote der TE RUE Ee rU USES 60 Editing Macros irte ets iter seat tag aa Eae ee OEE PR ORE EEEE 60 File Management Macros ssssssse IH e meme mener 61 User Interface MAcr0s 5i eer eer Rire mee tr POEP TISERE EPEE EP ERR ony 62 Java Code M cros ert diee tese dsbeae cues Sots eee eat D RR De rep De 63 Miscellaneous Macros 5 1 oboe p E bte pee Re 64 Property Macros 15 erus opes oe te sese pev iet p ue dee pae geo th vestre e ger UP opp ve So ey veda 65 Text Macros sse ico step ot eo rd teu teet Pe does Erbe to teo ORE TERI OR e ep Ree 66 II Waiting Edit Modes eec ener er da cease tee casas egtes a reed o eed 68 10 Mede Definition Syntax 50e eere hd ge Mh SEP dee pe vus 69 ub Ius sshey anoe EErEE NE EAE EE EEE suse sheSedgbehswunesenbege ss 69 The Preamble and MODE tag 2 2 0 0 cece cece cc neccnece IH erre 70 The PROPS Tag Cereri emere o sper ese potoit Der eor seks 70 The RULES Tag Beeren tete eruere iD SURE EET e RR 72 Highhehting Numbers sieri eei eco rtr ett Po RES E PER ERRARE RES 72 Rule Ordering Requirements sessss eme 72 Per Ruleset Properties inse de eee re Rep aS
62. ave option pane contains settings for the autosave and backup features See the section called Autosave and Crash Recovery and the section called Backups The Context Menu Pane The Context Menu option pane edits the text area s right click context menu See the section called Multiple Views The Docking Pane The Docking option pane specifies docking location for various dockable windows Another way to specify docking locations is to use the popup menus associated with each dockable window see the section called Window Docking The Editing Pane The Editing option pane contains settings such as the tab size syntax highlighting and soft tabs on a global or mode specific basis When changing mode specific settings the File name glob and First line glob text fields let you specify a glob pattern that names and first lines of buffers will be matched against to determine the edit mode See Appendix D Glob Patterns for information about glob patterns This option pane does not change XML mode definition files on disk it merely writes values to the user properties file which override those set in mode files To find out how to edit mode files directly see Part II Writing Edit Modes The General Pane The General pane contains various miscellaneous settings such as the default line separator and file encoding the number of recent files to remember if the buffer list should be sorted and so on The Gutter Pane T
63. bbing and Indentation and the section called Commenting Out Code Cr Expand abbreviation A LEFT A RIGHT Shift current line or all selected lines left right S TAB TAB Shift selected lines left right Note that pressing TAB with no 51 Keyboard Shortcuts selection active will insert a tab character at the caret position Cri Indent current line or all selected lines Range comment selection Line comment selection Folding and Narrowing For details see the section called Folding and the section called Narrowing A BACK SPACE Collapse fold containing caret A ENTER Expand fold containing caret one level only AS ENTER Expand fold containing caret fully Cte x Expand all folds Cte a Add explicit fold Ce s Select fold C e ENTER key Expand folds with level less than key collapse all others Cte nn Narrow to fold Cte ns Narrow to selection A UP A DOWN Moves caret to previous next fold Cte u Moves caret to the parent fold of the one containing the caret Macros For details see Chapter 8 Using Macros C m Ctr Record macro C m C m Record temporary macro C m C Stop recording C m Ct p Run temporary macro Alternative Shortcuts A few frequently used commands have alternative shortcuts intended to help you keep your hands from
64. ble to add new selections until multiple selection mode is reactivated Inserting and Deleting Text Text entered at the keyboard is inserted into the buffer In overwrite mode which can be toggled by pressing INSERT one character is deleted from in front of the caret position for every character that is inserted The caret is drawn as horizontal line while overwrite mode is active The status bar also indicates if overwrite mode is active see the section called The Status Bar for details Inserting text while there is a selection will replace the selection with the inserted text When inserting text the TAB and ENTER keys might not behave entirely like you expect because of various indentation features see the section called Tabbing and Indentation for details The simplest way to delete text is with the BACKSPACE and DELETE keys If nothing is selected they 20 Editing Text delete the character before or after the caret respectively If a selection exists both delete the selection More advanced deletion commands are described in the section called Working With Words the section called Working With Lines and the section called Working With Paragraphs Undo and Redo Edit gt Undo shortcut C z reverses the most recent editing command For example this can be used to restore unintentionally deleted text More complicated operations such as a search and replace can als
65. buffer r Cta key Append selected text to register key leaving it in the buffer r v key Paste contents of register key r Ctp key Vertically paste contents of register key 50 Keyboard Shortcuts lt Paste previous K Paste deleted Markers For details see the section called Markers Cte C4m If current line doesn t contain a marker one will be added Otherwise the existing marker will be removed Use the Markers menu to return to markers added in this manner C t key Add marker with shortcut key Cty key Go to marker with shortcut key Ctu key Select to marker with shortcut key Ctk key Go to marker with shortcut key and move the marker to the previous caret position C C Cte C Move caret to previous next marker Search and Replace For details see the section called Search and Replace CHF Open search and replace dialog box Ctg Find next C h Find previous C b Search in open buffers C d Search in directory CFT Replace in selection C g Replace in selection and find next CA Incremental search bar A HyperSearch bar Crs Incremental search for word under the caret A HyperSearch for word under the caret C i Toggle ignore case x Toggle regular expressions Source Code Editing For details see the section called Abbreviations the section called Ta
66. ckNotepadToolPanel extends JPanel private QuickNotepad pad private JLabel label public QuickNotepadToolPanel QuickNotepad qnpad pad qnpad JToolBar toolBar new JToolBar toolBar setFloatable false toolBar add makeCustomButton quicknotepad choose file new ActionListener public void actionPerformed ActionEvent evt QuickNotepadToolPanel this pad chooseFile toolBar add makeCustomButton quicknotepad save file new ActionListener public void actionPerformed ActionEvent evt QuickNotepadToolPanel this pad saveFile 125 Implementing a Simple Plugin toolBar add makeCustomButton quicknotepad copy to buffer new ActionListener public void actionPerformed ActionEvent evt QuickNotepadToolPanel this pad copyToBuffer label new JLabel pad getFilename SwingConstants RIGHT label setForeground Color black label setVisible jEdit getProperty QuickNotepadPlugin OPTION PREFIX show filepath equals true this setLayout new BorderLayout 10 0 this add BorderLayout WEST toolBar this add BorderLayout CENTER label this setBorder BorderFactory createEmptyBorder 0 0 3 10 The method makeCustomButton provides uniform attributes for the three toolbar buttons corresponding to three of the plugin s use actions The menu titles for the user actions serve double duty
67. completely separates the two concepts A buffer might be visible in several views or none at all The drop down list at the top of the view shows all open buffers selecting one will make it visible in the view s text area Different emblems are displayed next to buffer names in the list depending the buffer s state a red disk is shown for buffers with unsaved changes a lock is shown for read only buffers and a spark is shown for new buffers which don t yet exist on disk As with most other graphical applications there is a tool bar at the top of the view which provides quick access to frequently used commands Also clicking the text area with the right mouse button displays a popup menu which also facilitates quick access to various commands Both the tool bar and the right click menu can be completely customized to suit your tastes in the Utilities Global Options dialog box see the section called The Context Menu Pane and the section called The Tool Bar Pane Most of the view is taken up by the text area If you ve ever used a graphical user interface before the text area will be instantly familiar Text can be inserted simply by typing More details on text insertion and deletion can be found in the section called Inserting and Deleting Text The strip on the left of the text area is called a gutter The gutter displays marker and register locations as well as folding arrows it will also display line numbers if the View gt
68. cros These macros generate various forms of formatted text Add Prefix and Suffix bsh Adds user supplied prefix and suffix text to each line in a group of selected lines Text is added after leading whitespace and before trailing whitespace A dialog window receives input and remembers past entries Color Picker bsh Displays a color picker and inserts the selected color in hexadecimal format prefixed with a Duplicate Line bsh Duplicates the line on which the caret lies immediately beneath it and moves the caret to the new line Insert Date bsh Inserts the current date and time in the current buffer The inserted text includes a representation of the time in the Internet Time format Insert Tag bsh Inserts a balanced pair of HTML SGML XML markup tags as supplied in an input dialog The tags will surround any selected text Next Char bsh Finds next occurrence of character on current line The macro takes the next character typed after macro execution as the character being searched That character is not displayed If the character does not appear in the balance of the current line no action occurs This macro illustrates the use of InputHandler readNextChar asa means of obtaining user input See the section called Using a Single Keypress as Input Reverse Lines bsh Reverses the selected lines or the entire buffer if no lines are selected Does not support Rectangular 66
69. ct oriented programming here are a few skeleton ideas to help you with BeanShell e An object is a collection of data that can be initialized accessed and manipulated in certain defined ways Aclassis a specification of what data an object contains and what methods can be used to work with the data A Java application consists of one or more classes in the case of jEdit over 600 classes written by the programmer that defines the application s behavior A BeanShell macro uses these classes along with built in classes that are supplied with the Java platform to define its own behavior e A subclass or child class is a class which uses or inherits the data and methods of its parent class along with additions or modifications that alter the subclass s behavior Classes are typically organized in hierarchies of parent and child classes to organize program code to define common behavior in shared parent class code and to specify the types of similar behavior that child classes will perform in their own specific ways e A method or function is a procedure that works with data in a particular object other data including other objects supplied as parameters or both Methods typically are applied to a particular object which is an instance of the class to which the method belongs e A static method differs from other methods in that it does not deal with the data in a particular object but is included within a class for the sake of con
70. cuts Tool Bar or Context Menu panes of the Utilities gt Global Options dialog see the section called The Global Options Dialog Box How jEdit Organizes Macros Every macro whether or not you originally recorded it is stored on disk and can be edited as a text file The file name of a macro must have a bsh extension in order for jEdit to be aware of it By default jEdit associates a bsh file with the BeanShell edit mode for purposes of syntax highlighting indentation and other formatting However BeanShell syntax does not impose any indentation or line break requirements The Macros menu lists all macros stored in two places the macros subdirectory of the jEdit home directory and the macros subdirectory of the user specific settings directory see the section called The jEdit Settings Directory for information about the settings directory Any macros you record will be stored in the user specific directory Macros stored elsewhere can be run using the Macros gt Run Other Macro command which displays a file chooser dialog box and runs the specified file The listing of individual macros in the Macros menu can be organized in a hierarchy using subdirectories in the general or user specific macro directories each subdirectory appears as a submenu You will find such a hierarchy in the default macro set included with jEdit When jEdit first loads it scans the designated macro directories and assembles a listing of individual
71. d match text indexOf __char__ 1 script append if match 1 script append if char n match script append textArea select start start match 1 script append view getInputHandler readNextChar Enter a character script toString end Next_Char bsh Once again here are a few comments on the macro s design e A StringBuffer object is used for efficiency it obviates multiple creation of fixed length String objects The parameter to the constructor of script specifies the initial size of the buffer that will receive the contents of the child script Besides the quoting of the script code the formatting of the macro is entirely optional but hopefully makes it easier to read e Jt is important that the child script be self contained It does not run in the same namespace as the parent macro Next_Char bsh and therefore does not share variables methods or scripted objects defined in the parent macro Finally access to the InputHandler object used by jEdit is available by calling get InputHandler on the current view Startup Scripts On startup jEdit runs any BeanShell scripts located in the st art up subdirectory of the jEdit installation and user settings directories see the section called The jEdit Settings Directory As with macros the scripts must have a bsh file name extension Startup scripts are run near the end of the startup sequence after plug
72. d can be used to ensure that a macro will perform operations after other operations have completed If it is invoked during startup it schedules the specified Runnable object to run after startup is complete If invoked when jEdit is fully loaded the Runnable object will execute after all pending input output is complete or immediately if there are no pending I O operations This will delay operations on a new buffer for example until after the buffer is loaded and displayed Advanced BeanShell Techniques BeanShell has a few advanced features that we haven t mentioned yet They will be discussed in this section BeanShell s Convenience Syntax We noted earlier that BeanShell syntax does not require that variables be declared or defined with their type and that variables that are not typed when first used can have values of differing types assigned to them In addition to this loose syntax BeanShell allows a convenience syntax for dealing with the properties of JavaBeans They may be accessed or set as if they were data members They may also be accessed using the name of the property enclosed in quotation marks and curly brackets For example the following statement are all equivalent assuming btn is a JButton instance b setText Choose b text Choose b text Choose The last form can also be used to access a key value pair of a Hashtable object 106 Macro Tips and Techniques Special BeanShell
73. d endCompoundEdit calls These ensure that all edits performed between the two calls can be undone in one step Normally jEdit automatically wraps a macro call in these methods however if the macro shows a non modal dialog box as far as jEdit is 98 A Dialog Based Macro concerned the macro has finished executing by the time the dialog is shown since control returns to the event dispatch thread If you do not understand this don t worry just keep it in mind if your macro needs to show a non modal dialog box for some reason Most macros won t The Main Routine this single line of code is the script s main routine prefixSuffixDialog The call to pre ixSuffixDialog isthe only line in the macro that is not inside an enclosing block BeanShell treats such code as a top level main method and begins execution with it Our analysis of Add Prefix and Suffix bshisnow complete In the next section we look at other ways in which a macro can obtain user input as well as other macro writing techniques 99 Chapter 15 Macro Tips and Techniques Getting Input for a Macro The dialog based macro discussed in Chapter 14 A Dialog Based Macro reflects a conventional approach to obtaining input in a Java program Nevertheless it can be too lengthy or tedious for someone trying to write a macro quickly Not every macro needs a user interface specified in such detail some macros require only a single keystroke or n
74. d here some plugins add their own option panes and information about them can be found in the documentation for the plugins in question The Abbreviations Pane The Abbreviations option pane can be used to enable or disable automatic abbreviation expansion and to edit currently defined abbreviations The combo box labelled Abbrev set selects the abbreviation set to edit The first entry global contains abbreviations available in all edit modes The subsequent entries correspond to each mode s local set of abbreviations To change an abbreviation or its expansion either double click the appropriate table entry or click a table entry and then click the Edit button This will display a dialog box for modifying the abbreviation The Add button displays a dialog box where you can define a new abbreviation The Remove button removes the currently selected abbreviation from the list See the section called Positional Parameters for information about positional parameters in 39 Customizing jEdit abbreviations The Appearance Pane The Appearance pane can be used to change the appearance of user interface controls such as buttons labels and menus The number of items retained in history text fields can also be set here see Appendix C History Text Fields Note that changes to certain settings such as the Swing look and feel require a restart of jEdit to take effect The Autosave and Backup Pane The Autos
75. d on disk when the buffer is saved for the first time Opening Files File gt Open shortcut C o displays a file system browser dialog box and loads the specified file into a new buffer Multiple files can be opened at once by holding down Cont rol while clicking on them in the file system browser The file system browser supports auto completion typing the first few characters of a listed file name will select the file More advanced features of the file system browser are described in the section called The File System Browser The File gt Recent Files menu lists recently viewed files When a recent file is opened the caret is automatically moved to its previous location in that file The number of recent files to remember can be changed and caret position saving can be disabled in the General pane of the Utilities gt Global Options dialog box see the section called The General Pane The Utilities Current Directory menu lists all files and directories in the current buffer s directory Selecting a file opens it in a buffer for editing selecting a directory opens it in the file system browser see the section called The File System Browser Note Files that you do not have write access to are opened in read only mode where editing is not permitted Tip jEdit supports transparent editing of GZipped files if a file begins with the GZip magic number it is automatically decompressed before loading and compress
76. e long property Long property value split over several lines scape property Newlines and tabs can be inserted using the t and n escapes backslash property A backslash can be inserted by writing Now we look at the QUickNotepad props file which contains properties for the QuickNotepad plugin The first type of property data is information about the plugin itself these are the only properties that must be specified in order for the plugin to load general plugin information plugin QuickNotepadPlugin activate defer plugin QuickNotepadPlugin name QuickNotepad plugin QuickNotepadPlugin author John Gellene plugin QuickNotepadPlugin version 4 1 plugin QuickNotepadPlugin docs QuickNotepad html plugin QuickNotepadPlugin depend 0 jedit 04 02 10 00 These properties are described in detail in the documentation for the EditPlugin class and do not require further discussion here Next in the file comes a property that sets the title of the plugin s dockable window Dockable windows are discussed in detail in the section called The Dockable Window Catalog f dockable window name quicknotepad title QuickNotepad Next we see menu item labels for the plugin s actions Actions are discussed in detail in the section called The Action Catalog action labels quicknotepad label QuickNotepad quicknotepad choose file label Choose notepad file quicknotepad save file label Save notepad file quicknotepad copy to buffer label Cop
77. e to create a new line without any indentation type Cte v ENTER Commenting Out Code Most programming and markup languages support the notion of comments or regions of code which are ignored by the compiler interpreter jEdit has commands which make inserting comments more convenient Comment strings are mode specific and some in some modes such as HTML different parts of a buffer can have different comment strings For example in HTML files different comment strings are used for HTML text and inline JavaScript Edit gt Source Code Range Comment shortcut C e C c encloses the selection with comment start and end strings for example and in Java mode Edit gt Source Code gt Line Comment shortcut Cte C k inserts the line comment string for example in Java mode at the start of each selected line Bracket Matching Misplaced and unmatched brackets are one of the most common syntax errors encountered when writing code jEdit has several features to make brackets easier to deal with Positioning the caret immediately after a bracket will highlight the corresponding closing or opening bracket assuming it is visible and draw a scope indicator in the gutter If the highlighted bracket is not visible the text of the matching line will be shown in the status bar If the matching line consists of only whitespace and the bracket itself the previous line is shown instead This feature is very useful when you
78. e useful include the following adescription of the purpose of the plugin e an explanation of the type of input the user can supply through its visible interface such as mouse action or text entry in controls alisting of available user actions that can be taken when the plugin does not have input focus asummary of configuration options information on development of the plugin such as a change log a list of to do items and contact information for the plugin s author and licensing information including acknowledgments for any library software used by the plugin The location of the plugin s help file is stored in the plugin QuickNotepad docs property see the section called The Property File Compiling the Plugin We have already outlined the contents of the user action catalog the properties file and the documentation file in our earlier discussion The final step is to compile the source file and build the archive file that will hold the class files and the plugin s other resources Publicly released plugins include with their source a makefile in XML format for the Ant utility The format for this file requires few changes from plugin to plugin Here is the version of build xml used by QuickNotepad and many other plugins lt project name QuickNotepad default dist basedir gt lt property name jedit install dir value gt lt property name jar name value QuickNotepad jar
79. e Buttons buttonPanel new JPanel buttonPanel setLayout new BoxLayout buttonPanel BoxLayout X AXIS buttonPanel setBorder new EmptyBorder 12 50 0 50 buttonPanel add Box createGlue ok new JButton OK cancel new JButton Cancel ok setPreferredSize cancel getPreferredSize dialog getRootPane setDefaultButton ok buttonPanel add ok buttonPanel add Box createHorizontalStrut 6 buttonPanel add cancel buttonPanel add Box createGlue content add buttonPanel South register this method as an ActionListener for the buttons and text fields see the section called Register the Action Li ok addActionListener this cancel addActionListener this prefixField addActionListener this suffixField addActionListener this locate the dialog in the center of the editing pane and make it visible s the section called Make the Dialog V dialog pack dialog setLocationRelativeTo view dialog setDefaultCloseOperation JDialog DISPOSE ON CLOSE dialog setVisible true this method will be called when a button is clicked or when ENTER is pressed s the section called The Action Listener void actionPerformed e if e getSource cancel dialog dispose processText this is where the work gets done to insert the prefix and suffix see the section called Get the User s Input void processT
80. e Utilities gt Buffer Options dialog box Note that changing this setting has no effect on the buffer s contents if you opened a file with the wrong encoding and got garbage you will need to reload it If a file is opened without an explicit encoding specified and it appears in the recent file list jEdit will use the encoding last used when working with that file otherwise the default encoding will be used Commonly Used Encodings While the world is slowly converging on UTF 8 and UTF 16 encodings for storing text a wide range of older encodings are still in widespread use and Java supports most of them The simplest character encoding still in use is ASCII or American Standard Code for Information Interchange ASCII encodes Latin letters used in English in addition to numbers and a range of punctuation characters Each each ASCII character consists of 7 bits there is a limit of 128 distinct characters which makes it unsuitable for anything other than English text jEdit will load and save files as ASCII if the US ASCII encoding is used Because ASCII is unsuitable for international use most operating systems use an 8 bit extension of ASCII with the first 128 values mapped to the ASCII characters and the rest used to encode accents umlauts and various more esoteric used typographical marks The three major operating systems all extend ASCII in a different way Files written by Macintosh programs can be read using the MacRoman encod
81. e first character tha GI COMMENT1 gt lt EOL_SPAN gt I except the match sequence is taken to the EOL SPAN tag the HASH CHAR t the regular expression matches This rules out using regular expressions which can match more than one character at the start position The regular expression match cannot span more than one line either Regular expression syntax is described in Appendix E Regular Expressions Here is an EOL SPAN REGEXP that highlights MS DOS batch file comments which start with REM followed by any whitespace character and extend until the end of the line T I The MARK PREVIOUS Tag The MARK PREVIOUS rule which must be placed inside a RULI XEOL SPAN REGEXP AT WHITESPACE END TRUE HASH CHAR R TYPI GI COMMENT1 gt REM s lt EOL ES tag highlights from the end of the previous syntax token to the matched text The text to match is specified between opening and closing MARK_PREVIOUS tags The following attributes are supported TYPE The token type to highlight the text with See the section called Token Types for a list of token types AT LINE START If set to TRUE the sequence will only be highlighted if it occurs at the beginning of a line e AT WHITESPACE END If set to TRUE the sequence will only be highlighted if it is the first
82. e implemented public void actionPerformed ActionEvent e BeanShell does not permit a script to create derived classes However BeanShell offers a useful substitute a method can be used as a scripted object that can include nested methods implementing a number of Java interfaces The method pre ixSuffixDialog that we are writing can thus be treated as an ActionListener object To accomplish this we call addActionListener on each of the four components specifying this as th the interface We will do that shortly the Dialog Visible locate the dialog in the center e ActionListener We still need to implement of the editing pane and make it visible dialog pack dialog setLocationRelativeTo view 96 A Dialog Based Macro dialog setDefaultCloseOperation JDialog DISPOSE_ON_CLOSE dialog setVisible true Ij Here we do three things First we activate all the layout routines we have established by calling the pack method for the dialog as the top level window Next we center the dialog s position in the active jEdit view by calling setLocationRelativeTo on the dialog We also call the setDefaultCloseOperation function to specify that the dialog box should be immediately disposed if the user clicks the close box Finally we activate the dialog by calling set Visible with the state parameter set to t rue At this point we have a decent looking dialog window that
83. e method The keyword void is Java s way of saying the the method does not have a return value The error method works just like message but displays an error icon in the message box The input method furnishes a text field for input an OK button and a Cancel button If Cancel is pressed the method returns nu11 If OK is pressed a St ring containing the contents of the text field is returned Note that there are two forms of the input method the first form with two parameters displays an empty input field the other forms lets you specify an initial default input value For those without Java experience it is important to know that nu11 is not the same as an empty zero length St ring It is Java s way of saying that there is no object associated with this variable Whenever you seek to use a return value from input in your macro you should test it to see if it is null In most cases you will want to exit gracefully from the script with a return statement because the presence of a null value for an input variable usually means that the user intended to cancel macro execution BeanShell will complain if you call any methods on a nu11 object The confirm method in the Macros class is a little more complex The buttons parameter has an int type and the usual way to supply a value is to use one of the predefined values taken from Java s JOptionPane class You can choose among JOptionPane YES NO OPTION JOptionPane YES NO CAN
84. e to jEdit Catalogs like modes themselves are written in XML They consist of a single MODES tag with a number of MODE tags inside Each mode tag associates a mode name with an XML file and specifies the file name and first line pattern for the mode A sample mode catalog looks as follows lt xml version 1 0 gt lt DOCTYPE CATALOG SYSTEM catalog dtd gt lt MODES gt MODE NAME shellscript FILE shellscript xml ME GLOB sh FILE NAME FIRST LINE GLOB sh MODES In the above example a mode named shellscript is defined and is used for files whose names end with sh or whose first line starts with and contains sh The MODE tag supports the following attributes NAME the name of the edit mode as it will appear in the Buffer Options dialog box the status bar and so on FILE the name of the XML file containing the mode definition FILE NAME GLOB files whose names match this glob pattern will be opened in this edit mode FIRST LINE GLOB files whose first line matches this glob pattern will be opened in this edit mode Glob pattern syntax is described in Appendix D Glob Patterns Tip If an edit mode in the user specific catalog has the same name as an edit mode in the system catalog the version in the user specific catalog will override the system default 81 Chapter 12 Updating Edit M
85. ed not be at the top level This file contains BeanShell code for creating docking or floating windows that will contain the visible components of the plugin Not all plugins define dockable windows but 117 Implementing a Simple Plugin those that do need a dockables xml file See the section called The Dockable Window Catalog Checks for a class name with a name ending with Plugin class Such a class is known as a plugin core class and must extend jEdit s abstract Edit Plugin class The initialization routine checks the plugin s properties to see if it is subject to any dependencies For example a plugin may require that the version of the Java runtime environment or of jEdit itself be equal to or above some threshold version A plugin can also require the presence of another plugin If any dependency is not satisfied the loader marks the plugin as broken and logs an error message After scanning the plugin JAR file and loading any resources a new instance of the plugin core class is created and added to the collection maintained by the appropriate P luginJAR jEdit then calls the start method of the plugin core class The start method can perform initialization of the object s data members Because this method is defined as an empty no op in the EditPlugin abstract class a plugin need not provide an implementation if no unique initialization is required Updating 4 1 plugins Note that while jEd
86. ed when saving To compress an existing file you need to change a setting in the Utilities gt Buffer Options dialog box see the section called The Buffer Options Dialog Box for details Changed made in a buffer do not affect the file on disk until the buffer is saved File gt Save shortcut C4 s saves the current buffer to disk File gt Save As renames the buffer and saves it in a new location Note that using this command to save over another open buffer will close the other buffer to stop two buffers from being able to share the same path name File gt Save a Copy As saves the buffer to different location but does not rename it but doesn t rename the buffer and doesn t clear the modified flag Note that using this command to save over another 11 Working With Files open buffer will automatically reload the other buffer File gt Save All shortcut C e C s saves all open buffers to disk asking for confirmation first The confirmation dialog can be disabled in the General pane of the Utilities gt Global Options dialog box Two Stage Save To prevent data loss in the unlikely case that jEdit should crash in the middle of saving a file files are first saved to a temporary file named 4 filename save If this operation is successful the original file is replaced with the temporary file However in some situations this behavior is undesirable For example on Unix this creates a new i n
87. efinition must also contain exactly one MODE tag All other tags PROPS RULES must be placed inside the MODE tag The MODE tag does not have any defined attributes Here is an example lt MODE gt mode definition goes here gt He lt MOD The PROPS Tag The PROPS tag and the PROPERTY tags inside it are used to define mode specific properties Each PROPERTY tag must have a NAME attribute set to the property s name and a VALUE attribute with the property s value All buffer local properties listed in the section called Buffer Local Properties may be given values in edit modes The following mode properties specify commenting strings commentEnd the comment end string used by the Range Comment command e commentStart the comment start string used by the Range Comment command e lineComment the line comment string used by the Line Comment command When performing auto indent a number of mode properties determine the resulting indent level e The line and the one before it are scanned for brackets listed in the indentCloseBrackets and indentOpenBrackets properties Opening brackets in the previous line increase indent If lineUpClosingBracket is setto t rue then closing brackets on the current line will line up with the line containing the matching opening bracket For example in Java mode lineUpClosingBracket is set to t rue resulting in brackets being indented like so
88. elected and operated on simultaneously Range Selection Dragging the mouse creates a range selection from where the mouse was pressed to where it was released Holding down Shift while clicking a location in the buffer will create a selection from the caret position to the clicked location L5 Holding down Shift in addition to a caret movement key LEFT UP HOMI selection in the specified direction etc will extend a Edit gt Select All shortcut C a selects the entire buffer Edit gt More Selection gt Select None shortcut ESCAPE deactivates the selection Rectangular Selection Dragging with the Cont rol key held down will create a rectangular selection Holding down Shift and Control while clicking a location in the buffer will create a rectangular selection from the caret position to the clicked location Alternatively invoking Edit More Selection Rectangular Selection shortcut A V toggles rectangular selection mode In rectangular selection mode dragging the mouse always creates a rectangular selection and keyboard commands that would normally create a range selection create a rectangular selection instead A status bar indicator is shown when this mode is enabled It is possible to select a rectangle with zero width but non zero height This can be used to insert a new column between two existing columns for example Such zero width selections are shown as a thin vertical line Inserting
89. elected text item or null representing no selection Any further use of this fragment would have to test the value of result and likely exit from the macro if the value equaled nu11 A set of options can be similarly placed in a JComboBox component created as part of a larger dialog or showMessageDialog layout Here are some code fragments showing this approach fragments from Display Abbreviations bsh import statements and other code omitted from main routine this method call returns an array of Strings representing the names of abbreviation sets abbrevSets getActiveSets rom showAbbrevs method combo new JComboBox abbrevSets set width to uniform size regardless of combobox contents Dimension dim combo getPreferredSize dim width Math max dim width 120 combo setPreferredSize dim combo setSelectedItem STARTING SET defined as global end fragments Using a Single Keypress as Input Some macros may choose to emulate the style of character based text editors such as emacs or vi They will require only a single keypress as input that would be handled by the macro but not displayed on the screen If the keypress corresponds to a character value jEdit can pass that value as a parameter to a BeanShell script The jEdit class InputHandler is an abstract class that that manages associations between keyboard input and editing actions along with the recording of macros Keybo
90. electing one opens it in the file system browser To browse a listed directory double click it or if you have a three button mouse you can click the middle mouse button as well Alternatively click the disclosure widget next to a directory to list its contents in place To browse higher up in the directory hierarchy double click one of the parent directories in the parent directory list Files and directories in the file list are shown in different colors depending on what glob patterns their names match The patterns and colors can be customized in the File System Browser gt Colors pane of the Utilities gt Global Options dialog box To see a specific set of files only for example those whose names end with java enter a glob pattern in the Filter text field This text fields remembers previously entered strings See Appendix D Glob Patterns for information about glob patterns Unopened files can be opened by double clicking or by clicking the middle mouse button Open files have their names underlined and can be selected by single clicking Holding down Shift while opening a file will open it in a new view Clicking a file or directory with the right mouse button displays a popup menu containing various commands Tip The file list sorting algorithm used in jEdit handles numbers in file names in an intelligent manner For example a file named sect ion10 xml will be placed after a file named section5 xml A conventional letter by l
91. ented text definitions of get XXX or set XXX suitable for inclusion in a header file Preview Javadoc of Buffer bsh Create and display API documentation for the current buffer The macro includes various configuration variables you can change see the comment at the beginning of the macro source for details Miscellaneous Macros While these macros do not fit easily into the other categories they all provide interesting and useful functions Display Abbreviations bsh Displays the abbreviations registered for each of jEdit s editing modes The macro provides a read only view of the abbreviations contained in the Abbreviations option pane Pressing a letter key will scroll the table to the first entry beginning with that letter A further option is provided to write a selected mode s abbreviations or all abbreviations in a text buffer for printing as a reference Notes in the source code listing point out some display options that are configured by modifying global variables Display Actions bsh Displays a list of all the actions known to jEdit categorised by their action set This macro can be a useful reference if you want to use the jEdit 4 2 action bar Display Character Code bsh Display int and hex values for the character at the caret in the status bar Display Shortcuts bsh Displays a sorted list of the keyboard shortcuts currently in effect The macro provides a combined read only view of command macro and plugin
92. enu for selecting the character encoding to use when opening files See the section called Character Encodings The Plugins Menu Clicking the Plugins button displays a menu containing plugin commands For information about plugins see Chapter 9 Installing and Using Plugins The Favorites Menu Clicking the Favorites button displays a menu showing all files and directories in the favorites list The Add to Favorites item adds the currently selected file to the favorites list If nothing is selected the current directory is added To remove a file from the favorites invoke Edit Favorites which will show the favorites list in the file system view then select Delete from the right click menu of the entry you want to remove Keyboard Shortcuts Completion behaves differently in file dialogs than in the stand alone file system browser window In the file dialog keyboard input goes in the file name field by default Pressing Enter opens the file or directory path that 1s either fully or partially entered in the file name field Typing the first few characters of a file s name selects that file If the file name field is empty and nothing is selected lists the root directory on Unix and the list of drives on Windows There are two handy abbreviations that may be used in file paths expands to the home directory and expands to the current buffer s directory For example to open a file home slava jEdit doc TODO txt you mi
93. er At Show buffer switcher C q Exit jEdit Views For details see the section called Multiple Views Cre GHE Turn gutter line numbering on and off C 0 Remove split containing current text area only C 1 Remove all splits C 2 Split view horizontally CH3 Split view vertically A PAGE_UP Send keyboard focus to previous text area A PAGE_DOWN Send keyboard focus to next text area C e UP LEFT DOWN RIGHT Send keyboard focus to top bottom left right docking area Cte C Close currently focused docking area Action Bar For details see the section called The Action Bar C E NT ER Display the action bar and give it keyboard focus 48 Keyboard Shortcuts C SPACI Gl Repeat last editor action Moving the Caret For details see the section called Moving The Caret the section called Working With Words the section called Working With Lines the section called Working With Paragraphs and the section called Bracket Matching Arrow Move caret one character or line C Arrow Move caret one word or paragraph PAGE UP PAGE DOWN Move caret one screenful HOME First non whitespace character of line beginning of line first visible line repeated presses END Last non whitespace character of line end of line last visible line repeated presses C HOME Beginning of buffer
94. etter sort would have placed these two files in the wrong order The Tool Bar The file system browser has a tool bar containing a number of buttons Each item in the Commands menu described below except Show Hidden Files and Encoding has a corresponding tool bar button The Commands Menu Clicking the Commands button displays a menu containing the following items Parent Directory moves up in the directory hierarchy e Reload Directory reloads the file list from disk Root Directory on Unix goes to the root directory On Windows and MacOS X lists all mounted drives and network shares Home Directory displays your home directory Directory of Current Buffer displays the directory containing the currently active buffer New File opens new empty buffer in the current directory The file will not actually be created on disk until the buffer is saved New Directory creates a new directory after prompting for the desired name Search in Directory displays the search and replace dialog box set to search all files in the current directory If a file is selected when this command is invoked its extension becomes the file name 15 Working With Files filter for the search otherwise the file name filter entered in the browser is used See the section called Search and Replace for details Show Hidden Files toggles if hidden files are to be shown in the file list e Encoding a m
95. ext prefix prefixField getText suffix suffixField getText if prefix length 0 amp amp suffix length 0 return prefixField addCurrentToHistory suffixField addCurrentToHistory 93 A Dialog Based Macro text manipulation begins here using calls to jEdit methods see the section called Call jEdit Methods to Manipu buffer beginCompoundEdit selectedLines textArea getSelectedLines for i 0 i lt selectedLines length i offsetBOL textArea getLineStartOffset selectedLines i textArea setCaretPosition offsetBOL textArea goToStartOfWhiteSpace false textArea goToEndOfWhiteSpace true text textArea getSelectedText if text null text textArea setSelectedText prefix text suffix buffer endCompoundEdit this single line of code is the script s main routine see the section called The Main Routine prefixSuffixDialog end of Add Prefix and Suffix bsh Analysis of the Macro Import Statements import statement import javax swing border This macro makes use of classes in the javax swing border package which is not automatically imported As we mentioned previously see the section called The Mandatory First Example jEdit s implementation of BeanShell causes a number of classes to be automatically imported Classes that are not automa
96. fer Markers with shortcuts allow for quicker keyboard based navigation The following commands all prompt for a single character shortcut when invoked Pressing ESCAPE instead of specifying a shortcut will cancel the operation Markers gt Add Marker With Shortcut shortcut C t key adds a marker with the specified shortcut If marker with that shortcut already exists it will remain in the buffer but lose its shortcut Markers gt Go to Marker shortcut Cty key moves the caret to the location of the marker with the specified shortcut Markers gt Select to Marker shortcut C u key creates a selection from the caret location to the marker with the specified shortcut Markers gt Swap Caret and Marker shortcut C k key moves the caret to the location of the marker with the specified shortcut and moves the marker to the former caret position Invoke this command multiple times to flip between two locations in the buffer Lines which contain markers are indicated in the gutter with a highlight Moving the mouse over the highlight displays a tool tip showing the marker s shortcut if it has one See the section called Interface Overview for information about the gutter Search and Replace Searching For Text Search gt Find shortcut C displays the search and replace dialog box The search string can be entered in the Search for text field This text field remembers previously entered strings see Appendix C Histo
97. follows e This plugin must supply information about itself such as its name version author and compatibility with versions of jEdit The plugin must provide for activating displaying and deactivating itself upon direction from jEdit typically in response to user input e The plugin may define actions both explicitly with an action definition file or implicitly by providing dockable windows Actions are small blocks of BeanShell code that jEdit will perform on behalf of the plugin upon user request They provide the glue between user input and specific plugin routines By convention plugins display their available actions in submenus of jEdit s Plugins menu each menu item corresponds to an action The user can also assign actions to keyboard shortcuts toolbar buttons or entries in the text area s right click menu e The plugin may but need not provide a user interface If the plugin has a visible interface it can be shown in any object derived from one of Java top level container classes JWindow JDialog or JFrame jEdit also provides a dockable window API which allows plugin windows derived from the JComponent class to be docked into views or shown in top level frames at the user s request Plugins can also act directly upon jEdit s text area They can add graphical elements to the text display like error highlighting in the case of the ErrorList plugin or decorations surrounding the text area like the JDiff plugin s
98. ght enter j d to In the stand alone file system browser keyboard input is handled slightly differently There is no file name field instead shortcuts are active when the file tree has keyboard focus Additionally pressing or always immediately goes to the root home and current buffer s directory respectively Reloading From Disk When a view is brought to the foreground jEdit checks if any open buffers were modified on disk by another application All affected buffers are listed in a dialog box By default buffers without unsaved changes are automatically reloaded This feature can be disabled or changed to prompt if files should be reloaded first in the General pane of the Utilities Global Options dialog box see the section called The Global Options Dialog Box File gt Reload can be used to reload the current buffer from disk at any other time a confirmation dialog box will be displayed first if the buffer has unsaved changes File gt Reload All discards unsaved changes in all open buffers and reload them from disk asking for confirmation first Multi Threaded I O 16 Working With Files To improve responsiveness and perceived performance jEdit executes all buffer input output operations asynchronously While I O is in progress the status bar displays the number of remaining I O operations The Utilities gt Troubleshooting gt I O Progress Monitor command displays a window with more detailed status informat
99. he Gutter option pane contains settings to customize the appearance of the gutter See the section called Interface Overview The Mouse Pane The Mouse option pane contains settings for toggling drag and drop of text as well as gutter mouse click behavior 40 Customizing jEdit The Printing Pane The Printing option pane contains settings to control the appearance of printed output Workarounds that might be needed for your Java version to print correctly can also be enabled here See the section called Printing The Plugin Manager Pane The Plugin Manager pane contains a chooser for the desired download mirror as well as various settings such as the directory where plugins are to be installed See Chapter 9 Installing and Using Plugins The Proxy Servers Pane The Proxy Servers option pane lets you specify HTTP and SOCKS proxy servers to use when jEdit makes network connections for example when downloading plugins The Shortcuts Pane The Shortcuts option pane associates keyboard shortcuts with commands Each command can have up to two shortcuts associated with it The combo box at the top of the option pane selects the command set to edit Command sets include the set of all built in commands the commands of each plugin and the set of macros To change a shortcut click the appropriate table entry and press the keys you want associated with that command in the resulting dialog box The dialog box will warn you if
100. he Thread object so created void exec String cmdline Start the external process by calling Runtime exec on cmdline Any output is directed to the output stream of the calling process e Object eval String expression Evaluates the string expression as a BeanShell script in the interpreter s current namespace Returns the result of the evaluation of nu11 bsh This run String filename Run the BeanShell script named by filename ina copy of the existing namespace The return 111 BeanShell Commands value represent the object context of the script allowing you to access its variables and methods e void setAccessibility boolean flag If f1agis true BeanShell scripts are allowed to change and modify private variables and call private methods The default is false void setStrictJava boolean flag If flagis true BeanShell scripts must follow a much more strict Java like syntax and are not able to use the convenience features described in the section called BeanShell s Convenience Syntax void source String filename Evaluates the contents of filename as a BeanShell script in the interpreter s current namespace BeanShell Object Management Commands bind bsh This ths bsh Namespace namespace Binds the scripted object ths to namespace e void clear void Clear all variables methods and imports from this namespace If this namespace is the root it will be reset to the default imp
101. he beginning and end of the buffer respectively More advanced caret movement is covered in the section called Working With Words the section called Working With Lines and the section called Working With Paragraphs The Home and End keys If you prefer more traditional behavior for the HOME and END keys you can reassign the respective keyboard shortcuts in the Shortcuts pane of the Utilities Global Options see the section called The Shortcuts Pane By default the shortcuts are assigned as follows HOME is bound to Smart Home END is bound to Smart End S S HOME is bound to Select to Smart Home Position END is bound to Select to Smart End Position However you can rebind them to anything you want for example various combinations of the following or indeed any other command or macro Go to Start End of White Space Go to Start End of Line Go to Start End of Buffer Select to Start End of White Space 18 Editing Text e Select to Start End of Line e Select to Start End of Buffer Selecting Text A selection is a block of text marked for further manipulation Range selections are equivalent to selections in most other text editors they cover text between two points in a buffer jEdit also allows rectangular selections that cover a rectangular area some text editors refer to these as column selections Furthermore several chunks of text can be s
102. he status bar at the bottom of the view consists of the following components from left to right e The line number containing the caret e The column position of the caret with the leftmost column being 1 If the line contains tabs the file position where a hard tab is counted as one column is shown first followed by the screen position where each tab counts for the number of columns until the next tab stop Double clicking on the caret location indicator displays the Edit gt Go to Line dialog box see the section called Working With Lines Amessage area where various prompts and status messages are shown e The current buffer s edit mode fold mode and character encoding Double clicking one of these displays the Utilities Buffer Options dialog box For more information about these settings see the section called The Buffer Options Dialog Box the section called Edit Modes the section called Folding the section called Character Encodings Asetofflags which indicate various editor features and settings Clicking each flag will toggle the feature in question hovering the mouse over a flag will show a tool tip with an explanation jEdit Basics e Word wrap see the section called Wrapping Long Lines Multiple selection see the section called Multiple Selection e Rectangular selection see the section called Rectangular Selection e Overwrite mode see the section called In
103. hell script of any length as a text file with the lbsh extension and run it from the Macros menu There are three other ways jEdit lets you use BeanShell quickly without saving a script to storage on a one time only basis You will find them in the Utilities menu Utilities gt BeanShell gt Evaluate BeanShell Expression displays a text input dialog that asks you to type a single line of BeanShell commands You can type more than one BeanShell statement so long as each of them ends with a semicolon If BeanShell successfully interprets your input a message box will appear with the return value of the last statement Utilities gt BeanShell gt Evaluate For Selected Lines displays a text input dialog that asks you to type a single line of BeanShell commands The commands are evaluated for each line of the selection In addition to the standard set of variables described in the section called Predefined Variables in BeanShell this command defines the following e line the line number from the start of the buffer The first line is numbered 0 index the line number from the start of the selection The first line is numbered 0 text the text of the line Try typing an expression like line 1 text in the Evaluate For Selected Lines dialog box This will add a line number to each selected line beginning with the number 1 The BeanShell expression you enter will be evaluated and substituted in place of the entire text of
104. hical tools and editor commands can do the job However being familiar with the structure of the settings directory still comes in handy in certain situations for example when you want to copy jEdit settings between computers The location of the settings directory is system specific it is printed to the activity log Utilities gt Troubleshooting gt Activity Log For example message jEdit Settings directory is home slava jedit Specifying the settings switch on the command line instructs jEdit to store settings in a directory other than the default For example the following command will instruct jEdit to store all settings in the jedit subdirectory of the C drive C jedit gt jedit settings C jedit The nosettings switch will force jEdit to not look for or create a settings directory default settings will be used instead jEdit creates the following files and directories inside the settings directory plugins may add more e abbrevs a plain text file which stores all defined abbreviations See the section called Abbreviations e activity log a plain text file which contains the full activity log See Appendix B The Activity Log e history a plain text file which stores history lists used by history text fields and the Edit Paste Previous command See the section called Transferring Text and Appendix C History Text Fields e jars this directory contains plugins See Chapter 9 Installing and Using Plugi
105. hich has the same effect as invoking Utilities gt Global Options Buffer local properties Entering buffer property value sets the value of the buffer local property named property to value Buffer local properties are documented in the section called Buffer Local Properties For example entering buffer tabSize 4 changes the current buffer s tab size to 4 See the section called Buffer Local Properties for information about buffer local properties Global properties Entering property value sets the value of the global property named property to value This feature is primarily intended to help plugin developers since the properties jEdit uses to store its settings are not currently documented jEdit Basics Command repetition To repeat a command multiple times enter a number in the action bar then invoke the command For example C ENTER 1 4 C d will delete 14 lines C ENTER 9 will insert HHHH in the buffer If you specify a repeat count greater than 20 a confirmation dialog box will be displayed asking if you really want to perform the action This prevents you from hanging jEdit by executing a command too many times 10 Chapter 4 Working With Files Creating New Files File gt New shortcut C n opens a new empty buffer Another way to create a new file is to specify a non existent file name when starting jEdit on the command line A new file will be create
106. hift key Refers to pressing and holding the Cont rol key pressing and releasing O and finally releasing the Control key Cte Ct i Default buttons Refers to holding down Cont rol pressing E pressing J and releasing Control In many dialog boxes the default button it has a heavy outline or a special border depending on the current Swing look and feel can be activated by pressing Enter Similarly pressing Escape will usually close a dialog box Alt key mnemonics Some user interface elements menus menu items buttons have a certain letter in their label underlined Pressing this letter in combination with the Alt key activates the associated user interface widget Note that this functionality is not available on MacOS X with the MacOS Adaptive look and feel See the section called The Appearance Pane for information on changing the look and feel Right mouse button Used in jEdit to show context sensitive menus If you have a one button Macintosh mouse a Control click has the same effect Middle mouse button Used by the quick copy feature see the section called Quick Copy True 3 button mice are rare these days If you have a wheel mouse press down on the wheel without rolling it On a Macintosh with a one button mouse Opt ion click On other platforms without a three button mouse Alt click Chapter 2 Starting jEdit Exactly how jEdit i
107. ield descField uses an empty string for its initial value The second parameter in its constructor sets the width of the text field component expressed as the number of characters of average width When showConfirmDialog prepares the layout of the message box it sets the width wide enough to accommodate the designated with of descField This technique produces a message box and input text fields that are wide enough for your data with one line of code The displayed message box includes a JCheckBox component that determines whether the buffer will be saved to disk immediately after the file header is written To conserve space in the message box we want to display the check box to the right of the label Name of file To do that we create a JPanel object and populate it with the label and the checkbox in a left to right GridLayout The JPanel containing the two components is then added to the beginning of message array e The two visible components created by showConfirmDialog appear at positions 3 and 6 of the message array Only the text is required they are rendered as text labels e There are three invisible components created by showConfirmDialog Each of them involves acall to Box createVerticalStrut The Box class is a sophisticated layout class that gives the user great flexibility in sizing and positioning components Here we use a static method of the Box class that produces a vertical strut This is a transparent componen
108. ilename EBComponent implementation public void handleMessage EBMessage message if message instanceof PropertiesChanged propertiesChanged private void propertiesChanged String propertyFilename jEdit getProperty QuickNotepadPlugin OPTION_PREFIX filepath if defaultFilename equals propertyFilename saveFile toolPanel propertiesChanged defaultFilename propertyFilename clone filename defaultFilename clone readFile 124 Implementing a Simple Plugin Font newFont QuickNotepadOptionPane makeFont if newFont equals textArea getFont textArea setFont newFont textArea invalidate These JComponent methods provide the appropriate points to subscribe and unsubscribe this object to the EditBus public void addNotify super addNotify EditBus addToBus this public void removeNotify saveFile super removeNotify EditBus removeFromBus this This listing refers to a Qui ckNotebookTextArea object It is currently implemented as a JTextArea with word wrap and tab sizes hard coded Placing the object in a separate class will simply future modifications The QuickNotepadToolBar Class There is nothing remarkable about the toolbar panel that is placed inside the QUickNotepad object The constructor shows the continued use of items from the plugin s properties file public class Qui
109. in a single row or column depending on the parameter passed to its constructor This layout object is more flexible than a GridLayout in that variable spacing between elements can be specified easily We put an Empt yBorder in the new panel to set margins for placing the buttons Then we create the buttons using a JBut t on constructor that specifies the button text After setting the size of the OK button to equal the size of the Cancel button we designate the OK button as the default button in the dialog This causes the OK button to be outli ned when the dialog if first displayed Finally we place the buttons side by side with a 6 pixel gap between them for aesthetic reasons and place the completed but tonPanel in the South section of the dialog s content pane Register the Action Listeners Make register this method as an ActionListener for the buttons and text fields ok addActionListener this cancel addActionListener this prefixField addActionListener this suffixField addActionListener this Js In order to specify the action to be taken upon clicking a button or pressing the Enter key we must register an ActionListener for each of the four active components of the dialog the two HistoryTextField components and the two buttons In Java an ActionListener is an interface an abstract specification for a derived class to implement The Act ionListener interface contains a single method to b
110. in s interface The BeanShell code is contained in a file named dockables xml It usually is quite short providing only a single BeanShell expression used to create a visible plugin window The following example from the QuickNotepad plugin illustrates the requirements of the data file lt xml version 1 0 gt lt DOCTYPE DOCKABLES SYSTEM dockables dtd gt lt DOCKABLES gt lt DOCKABLE NAME quicknotepad gt new QuickNotepad view position lt DOCKABLE gt lt DOCKABLES gt 122 Implementing a Simple Plugin In this example the lt DOCKABLE gt element has a single attribute the dockable window s identifier This attribute is used to key a property where the window title is stored see the section called The Property File The contents of the lt DOCKABLE gt element itself is a BeanShell expression that constructs a new QuickNotepad object The view and position are predefined by the plugin API as the view in which the plugin window will reside and the docking position of the plugin A formal description of each element of the dockables xm1 file can be found in the documentation of the DockableWindowManager class The QuickNotepad Class Here is where most of the features of the plugin will be implemented To work with the dockable window API the top level window will be a JPanel The visible components reflect a simple layout Inside the top level panel we will place a
111. ing Windows text files are usually stored as windows 1252 In the Unix world the 8859 1 character encoding has found widespread usage On Windows various other encodings referred to as code pages and identified by number are used to store non English text The corresponding Java encoding name is windows followed by the code page number for example windows 850 Many common cross platform international character sets are also supported KOI8 R for Russian text Big5 and GBK for Chinese and SJIS for Japanese The File System Browser Utilities File System Browser displays the file system browser By default the file system browser is shown in a floating window This window can be docked using the commands in its top left corner popup menu see the section called Window Docking The file system browser can be customized in the Utilities gt Global Options dialog box see the section called The File System Browser Panes Navigating the File System The directory to browse is specified in the Path text field Clicking the mouse in the text field automatically selects its contents allowing a new path to be quickly typed in If a relative path is entered it will be resolved relative to the current path This text field remembers previously entered strings see 14 Working With Files Appendix C History Text Fields The same list of previously browsed directories is also listed in the Utilities gt Recent Directories menu s
112. ing With Files tiere techs eos eye eene eterne itta ve eene eee Deer ree dua 11 Creating Anim 11 Openme Elles et eer Tee E ertet bre EUER terr ee 11 Savine FUES ML 11 Two Stage Sayen ose es D cel stati ETE sede E E 12 Autosave and Crash Recovery 12 hr P LE 12 Line Separators 2 retenue nb tp e e 13 Character ENcOdINES seisis cote eerie eere pet Nee ehe EE Ryu UR 13 Commonly Used Encodings eorr terrere reo Erin prusia Ern 14 The File System Browser pissin eee sem Soave n cseangegareteeencensessceesoetecs 14 Navigating the File System sse 14 TEST OO Bat cee enn terree rte eben de eet EEOSE EA EEEE ORE EES 15 The Commands Menu mirren a EE e eere 15 The Pl gins Menu iie eot etuer ert etsi tiis 16 The Favorites Menu 5 o HERES Ee Erst 16 Keyboard Sliorteuts ote rete oret h oes ete eret AE tet tess e S eode ne 16 Reloading From Disk airport rere e i E E HI em eme eere 16 Multi Threaded I O ot etr Ere teet r S E ERE Rr Deed pes 16 uenia RH 17 Closing Files and Exiting jEdit isss partye ossessi ises eraras Trt tmr Res 17 SD Editing Text iir tege IHE Pere pepe predi 18 Moving The C tet 5 epo p mt RR St Pee PRU 18 Selecting TEX iustior eee Ere REUS Re PIA wens 19 Range Selection 2 oes cte Terre doo ete E reU reete E seks 19 Rectangular Selection 24 5 ieketoee st toe ior eed eee do It e eo Loi eee eE 19 Multiple Selection 2 5 Eee Dt Ee Gaeta 20 Inserting and Deleting
113. ins properties and such have been initialized but before the first view is opened Startup scripts can perform initialization tasks that cannot be handled by command line options or ordinary configuration options such as customizing jEdit s user interface by changing entries in the Java platform s UIManager class 104 Macro Tips and Techniques Startup scripts have an additional feature lacking in ordinary macros that can help you further customize jEdit Variables and methods defined in a startup script are available in all instances of the BeanShell interpreter created in jEdit This allows you to create a personal library of methods and objects that can be accessed at any time during the editing session in another macro the BeanShell shell of the Console plugin or menu items such as Utilities gt BeanShell gt Evaluate BeanShell Expression The startup script routine will run script files in the installation directory first followed by scripts in the user settings directory In each case scripts will be executed in alphabetical order applied without regard to whether the file name contains upper or lower case characters If a startup script throws an exception because for example it attempts to call a method on a null object jEdit will show an error dialog box and move on to the next startup script If script bugs are causing jEdit to crash or hang on startup you can use the nostartupscripts command line option to disable the
114. inside it Another sub section Both modes have distinct advantages and disadvantages indent folding requires no changes to be made to a buffer s text and does a decent job with most program source Explicit folding requires fold markers to be inserted into the text but is more flexible in exactly what to fold away Some plugins might add additional folding modes see Chapter 9 Installing and Using Plugins for information about plugins Folding can be enabled in one of several ways 35 Editing Source Code Ona global or mode specific basis in the Editing pane of the Utilities gt Global Options dialog box See the section called The Editing Pane Inthe current buffer for the duration of the editing session in the Utilities gt Buffer Options dialog box See the section called The Buffer Options Dialog Box Inthe current buffer for future editing sessions by placing the following in the first or last 10 lines of a buffer where mode is either indent explicit or the name of a plugin folding mode folding mode Warning When using indent folding portions of the buffer may become inaccessible if you change the leading indent of the first line of a collapsed fold If you experience this you can use the Expand All Folds command to make the text visible again Collapsing and Expanding Folds The first line of each fold has a triangle drawn next to it in the gu
115. ion and progress meters By default the I O Progress Monitor is shown in a floating window This window can be docked using the commands in its top left corner popup menu see the section called Window Docking I O requests can also be aborted in this window however note that aborting a buffer save can result in data loss Printing File gt Print shortcut C p prints the current buffer File gt Page Setup displays a dialog box for changing your operating system s print settings such as margins page size print quality and so on The print output can be customized in the Printing pane of the Utilities gt Global Options dialog box see the section called The Printing Pane The following settings can be changed The font to use when printing e Ifa header with the file name should be printed on each page e Ifa footer with the page number and current date should be printed on each page e If line numbers should be printed e If the output should be color or black and white e The tab size to use when printing this will usually be less than the text area tab size to conserve space in the printed output Closing Files and Exiting jEdit File gt Close shortcut C w closes the current buffer If it has unsaved changes jEdit will ask if they should be saved first File gt Close All shortcut Cte C w closes all buffers If any buffers have unsaved changes they will be listed in a dialog box where they can be saved o
116. ips and techniques for writing and debugging macros This part of the user s guide was written by John Gellene lt jgellene nyc rr com gt Chapter 13 Macro Basics Introducing BeanShell Here is how BeanShell s author Pat Niemeyer describes his creation BeanShell is a small free embeddable Java source interpreter with object scripting language features written in Java BeanShell executes standard Java statements and expressions in addition to obvious scripting commands and syntax BeanShell supports scripted objects as simple method closures like those in Perl and JavaScript You do not have to know anything about Java to begin writing your own jEdit macros But if you know how to program in Java you already know how to write BeanShell scripts The major strength of using BeanShell with a program written in Java is that it allows the user to customize the program s behavior using the same interfaces designed and used by the program itself BeanShell can turn a well designed application into a powerful extensible toolkit This guide focuses on using BeanShell in macros If you are interested in learning more about BeanShell generally consult the BeanShell web site Information on how to run and organize macros whether included with the jEdit installation or written by you can be found in Chapter 8 Using Macros Single Execution Macros As noted in the section called How jEdit Organizes Macros you can save a BeanS
117. it 4 1 plugins were only loaded on startup jEdit 4 2 plugins can be loaded at any time As a result the start method needs to cope with being called at any time and stop needs to fully clean up after the plugin See the API documentation for the EditPlugin class for details The QuickNotepadPlugin Class The major issues encountered when writing a plugin core class arise from the developer s decisions on what features the plugin will make available These issues have implications for other plugin elements as well e Will the plugin provide for actions that the user can trigger using jEdit s menu items toolbar buttons and keyboard shortcuts e Will the plugin have its own visible interface e Will the plugin have settings that the user can configure e Will the plugin respond to any messages reflecting changes in the host application s state Recall that the plugin core class must extend EditPlugin In QuickNotepad s plugin core class there are no special initialization or shutdown chores to perform so we will not need a start or stop method The resulting plugin core class is lightweight and straightforward to implement public class QuickNotepadPlugin extends EditPlugin public static final String NAME quicknotepad public static final String MENU quicknotepad menu public static final String PROPERTY PREFIX plugin QuickNotepadPlugin 118 Implementing a Simple
118. jEdit 4 2 User s Guide jEdit 4 2 User s Guide Copyright 1999 2004 Slava Pestov Copyright 2001 2002 John Gellene Legal Notice Permission is granted to copy distribute and or modify this document under the terms of the GNU Free Documentation License Version 1 1 or any later version published by the Free Software Foundation with no Invariant Sections Front Cover Texts or Back Cover Texts each as defined in the license A copy of the license can be found in the file COPYING DOC t xt included with jEdit Table of Contents I Using JE Git eI nEBEDOI REMIS 1 De CONVENTIONS 2 5 tret D noes Se rrt rete ret ree Er R Sr SETE 2 2 Starting JEdIt xc tecto tette rt io ed dt E Qoae oet e aot eoe reete ond 3 Command Line Usage x e reet e MO p rrr bel Dg Ue 3 Miscellaneous Options oec ee eepto puted ope Ur espe nz EHE SER Dr eer sek Sep ERSS 4 Configuration Options 0 cece cece cece eece cece eece eens en enne he n enne nenne 4 Edit Servet Options ie oie pte lebte iecit 4 3 Edit BaS1es 2 S eve eR PRU e EROR NES 6 Interface OVervI6W ee er rer EPOR ES K OTTEET OSETE EEES EPRE SE COREE ERTI 6 Switching Buffers E Em 6 M ltiple Views 5 eset d s a EE e e a E e aE REA TE Pe LOS 7 Window Docking rtr e ree Ie mr verre ERE Rer pure er ey Orge e 7 The Status Bat org eher ER E ERR PRI Mere EE Ir RR sone 8 Th Acton Bat uincere erster eI RERO E ES DOS E eR te Pe I ERR CER ses 9 4 Work
119. lding indentSize The width in characters of one indent Must be an integer greater than 0 See the section called Tabbing and Indentation maxLineLen The maximum line length and wrap column position Inserting text beyond this column will automatically insert a line break at the appropriate position See the section called Inserting and Deleting Text mode The default edit mode for the buffer See the section called Edit Modes noTabs If set to true soft tabs multiple space characters will be used instead of real tabs See the section called Tabbing and Indentation noWordSep A list of non alphanumeric characters that are not to be treated as word separators Global default is tabSize The tab width Must be an integer greater than 0 See the section called Tabbing and Indentation wordBreakChars Characters in addition to spaces and tabs at which lines may be split when word wrapping See the section called Inserting and Deleting Text wrap The word wrap mode one of none soft or hard See the section called Wrapping Long Lines The Global Options Dialog Box Utilities gt Global Options displays the global options dialog box The dialog box is divided into several panes each pane containing a set of related options Use the list on the left of the dialog box to switch between panes Only panes created by jEdit are describe
120. lding down A1t while clicking a fold expansion triangle in the gutter will hide all lines the buffer except those contained in the clicked fold Folding gt Narrow Buffer to Fold shortcut Cte n n hides all lines the buffer except those in the fold containing the caret Folding gt Narrow Buffer to Selection shortcut Cte n s hides all lines the buffer except those in the selection Folding gt Expand All Folds shortcut C e x shows lines that were hidden as a result of narrowing 37 Chapter 7 Customizing jEdit The Buffer Options Dialog Box Utilities gt Buffer Options displays a dialog box for changing editor settings on a per buffer basis Changes made in this dialog box are not retained after the buffer is closed The following settings can be changed here e The line separator see the section called Line Separators e The character encoding see the section called Character Encodings Ifthe file should be GZipped on disk see the section called Opening Files The edit mode see the section called Edit Modes The fold mode see the section called Folding e The wrap mode and margin see the section called Wrapping Long Lines e The tab width see the section called Tabbing and Indentation The indent width e If soft tabs should be used see the section called Tabbing and Indentation Buffer Local Properties Buffer local properties provide an alternate way to cha
121. line V r n jEdit can read and write files in all three formats The line separator used by the in memory representation of file contents is always the newline character When a file is being loaded the line separator used in the file on disk is stored in a per buffer property and all line endings are converted to newline characters for the in memory representation When the buffer is consequently saved the value of the property replaces newline characters when the buffer is saved to disk There are several ways to change a buffer s line separator e In the Utilities gt Buffer Options dialog box See the section called The Buffer Options Dialog Box e By clicking the line separator indicator in the status bar See the section called The Status Bar e From the keyboard if a keyboard shortcut has been assigned to the Toggle Line Separator command in the Shortcuts pane of the Utilities gt Global Options dialog box By default this command does not have a keyboard shortcut By default new files are saved with your operating system s native line separator This can be changed in the General pane of the Utilities Global Options dialog box see the section called The General Pane Note that changing this setting has no effect on existing files Character Encodings A character encoding is a mapping from a set of characters to their on disk representation jEdit can use any encoding supported by the Java platform Buffers in
122. lipboard gt Paste Deleted shortcut C e C y is not really a register command it displays a dialog box listing the 20 most recently deleted text strings Edit gt More Clipboard gt View Registers displays a dialog box for viewing register contents including the clipboard and the quick copy 25 Editing Text Markers A marker is a pointer to a specific location within a buffer which may or may not have a single character shortcut associated with it Markers are persistent they are saved to filename marks where filename is the name of the buffer The dot prefix makes the markers file hidden on Unix systems Marker saving can be disabled in the General pane of the Utilities gt Global Options dialog box see the section called The General Pane Markers gt Add Remove Marker shortcut C e C m adds a marker without a shortcut pointing to the current line If a marker is already set on the current line the marker is removed instead If text is selected markers are added to the first and last line of each selection Markers are listed in the Markers menu selecting a marker from this menu will move the caret to its location Markers gt Go to Previous Marker shortcut Cte C COMMA goes to the marker immediately before the caret position Markers gt Go to Next Marker shortcut C e C PERIOD goes to the marker immediately after the caret position Markers gt Remove All Markers removes all markers set in the current buf
123. listing the completions To insert a completion from the list either select it using the UP and DOWN keys and press ENTER press a digit to insert one of the first ten completions 1 is the first completion 9 is the 9th 0 is the 10th or click the desired completion with the mouse To close the popup without inserting a completion press ESCAPE Typing while the popup is visible will automatically update the popup and narrow the set of completions as necessary Edit gt Word Count displays a dialog box with the number of characters words and lines in the current buffer What s a Word The default behavior of the C LEFT C RIGHT C BACKSPACE and C DELETE commands is to stop both at the beginning and the end of each word However this can be changed by remapping these keystrokes to alternative actions whose names end with Eat Whitespace in the Shortcuts pane of the Utilities gt Global Options dialog box see the section called The Shortcuts Pane 21 Editing Text Working With Lines An entire line can be selected by triple clicking with the mouse or using the Edit gt More Selection gt Select Line command shortcut Cte 1 A selection that begins and ends on line boundaries can be created by triple clicking and dragging Edit gt Go to Line shortcut C 1 prompts for a line number and moves the caret there Edit gt More Selection gt Select Line Range shortcut Cte C 1 prompts for
124. ll do nothing as in the following example 107 Macro Tips and Techniques invoke method args In addition to the implicit interface definitions described above BeanShell permits full blown classes to be defined Indeed almost any Java class definition should work in BeanShell class Cons Long live LISP Object car Object cdr rplaca Object car this car car rplacd Object cdr this cdr cdr Debugging Macros Here are a few techniques that can prove helpful in debugging macros Identifying Exceptions An exception is a condition reflecting an error or other unusual result of program execution that requires interruption of normal program flow and some kind of special handling Java has a rich and extensible collection of exception classes which represent such conditions jEdit catches exceptions thrown by BeanShell scripts and displays them in a dialog box In addition the full traceback is written to the activity log see Appendix B The Activity Log for more information about the activity log There are two broad categories of errors that will result in exceptions e Interpreter errors which may arise from typing mistakes like mismatched brackets or missing semicolons or from BeanShell s failure to find a class corresponding to a particular variable Interpreter errors are usually accompanied by the line number in the script along with the cause of the error e Execution errors
125. ls containing an exponent DIGIT RE Ox xdigit l digit e digit 1LdDfF Regular expression syntax is described in Appendix E Regular Expressions Rule Ordering Requirements You might encounter this very common pitfall when writing your own modes 72 Mode Definition Syntax Since jEdit checks buffer text against parser rules in the order they appear in the ruleset more specific rules must be placed before generalized ones otherwise the generalized rules will catch everything This is best demonstrated with an example The following is incorrect rule ordering lt SPAN TYPE MARKUP gt lt BEGIN gt lt BEGIN gt lt END gt lt END gt lt SPAN gt lt BEGIN gt lt BEGIN gt lt END gt lt E lt SPAN gt lt SPAN TYPE KEYWORD1 gt If you write the above in a rule set any occurrence of even things like DEFINE etc will be highlighted using the first rule because it will be the first to match This is most likely not the intended behavior The problem can be solved by placing the more specific rule before the general one lt BEGIN gt lt BEGIN gt lt END gt lt E lt SPAN gt lt SPAN TYPE KEYWORD1 gt lt SPAN TYPE MARKUP gt lt BEGIN gt lt BEGIN gt lt END gt lt END gt lt SPAN gt Now if the buffer contains the text SPECIAL the rules
126. lugins can be selected by holding down Cont rol and click Remove This will display a confirmation dialog box first To view plugin documentation select a plugin and click Help Note that plugin documentation can also be accessed by invoking Help gt jEdit Help Plugins gt Plugin Options displays a dialog box for changing plugin settings Installing and Updating Plugins Plugins can be installed in two ways manually and from the plugin manager In most cases plugins should be installed from the plugin manager It is easier and more convenient To install plugins manually go to http plugins jedit org in a web browser and follow the directions on that page To install plugins from the plugin manager make sure you are connected to the Internet and click the Install tab in the plugin manager window The plugin manager will then download information about available plugins from the jEdit web site and present a list of plugins compatible with your jEdit release Click on a plugin in the list to see some information about it To select plugins for installation click the check box next to their names in the list The Total size field shows the total size of all plugins chosen for installation along with any plugins that will be automatically downloaded in order to fulfill dependencies Once you have specified plugins to install click Install to begin the download process By default the plugin manager does not download plugin source c
127. m for that editing session Another important difference between startup scripts and ordinary macros is that startup scripts cannot use the pre defined variables view textArea editPane and buffer This is because they are executed before the initial view is created If you are writing a method in a startup script and wish to use one of the above variables pass parameters of the appropriate type to the method so that a macro calling them after startup can supply the appropriate values For example a startup script could include a method void doSomethingWithView View v String s so that during the editing session another macro can call the method using doSomethingWithView view something Reloading startup scripts without restarting It is actually possible to reload startup scripts or load other scripts without restarting jEdit using a BeanShell statement like the following BeanShell runScript view path null false For path you can substitute any string or a method call such as buffer getPath Running Scripts from the Command Line The run command line switch specifies a BeanShell script to run on startup jedit run test bsh Note that just like with startup scripts the view textArea editPane and buffer variables are not defined If another instance is already running the script will be run in that instance and you will be able to use the jEdit getLastView method to obtain a view
128. memory are always stored in UTF 16 encoding which means each character is mapped to an integer between 0 and 65535 UTF 16 is the native encoding supported by Java and has a large enough range of characters to support most human languages When a buffer is loaded it is converted from its on disk representation to UTF 16 using a specified encoding The default encoding used to load files for which no other encoding is specified can be set in the General pane of the Utilities Global Options dialog box see the section called The General Pane Unless you change this setting it will be your operating system s native encoding for example MacRoman on the MacOS windows 1252 on Windows and 1380 8859 1 on Unix An encoding can be explicitly set when opening a file in the file system browser s Commands gt Encoding menu Note that there is no general way to auto detect the encoding used by a file however in a few cases it is possible 13 Working With Files e UTF 16 and UTF 8Y files are auto detected because they begin with a certain fixed character sequence Note that plain UTF 8 does not mandate a specific header and thus cannot be auto detected unless the file in question is an XML file e Encodings used in XML files with an XML PI like the following are auto detected lt xml version 1 0 encoding UTF 8 gt The encoding that will be used to save the current buffer is shown in the status bar and can be changed in th
129. mode is active see the section called The Status Bar Various jEdit commands behave differently with multiple selections Commands that copy text place the contents of each selection separated by line breaks in the specified register Commands that insert or paste text replace each selection with the entire text that is being inserted Commands that filter text such as Spaces to Tabs Range Comment Replace in Selection and so on behave as if each block was selected independently and the command invoked on each in turn Line based commands such as Shift Indent Left Shift Indent Right and Line Comment operate on each line that contains at least one selection e Caret movement commands that would normally deactivate the selection such as the arrow keys while Shift is not being held down move the caret leaving the selection as is e Some older plugins may not support multiple selection at all Edit gt More Selection gt Select None shortcut ESCAPE deactivates the selection containing the caret if there is one Otherwise it deactivates all active selections Edit gt More Selection gt Invert Selection shortcut Cte C i selects a set of text chunks such that all text that was formerly part of a selection is now unselected and all text that wasn t is selected Note Deactivating multiple selection mode while multiple blocks of text are selected will leave the selections in place but you will not be a
130. moving all over the keyboard A 3 A41 Move caret to previous next character Acti Atk Move caret up down one line Atq Ata Move caret up down one screenful A z First non whitespace character of line beginning of line first visible line repeated presses A x Last non whitespace character of line end of line last visible line repeated presses 52 Appendix B The Activity Log The activity log is very useful for troubleshooting problems and helps when developing plugins Utilities gt Troubleshooting gt Activity Log displays the last 500 lines of the activity log By default the activity log is shown in a floating window This window can be docked using the commands in its top left corner popup menu see the section called Window Docking The complete log can be found in the activity log file inside the jEdit settings directory the path of which is shown inside the activity log window jEdit writes the following information to the activity log Information about your Java implementation version operating system architecture etc All error messages and runtime exceptions most errors are shown in dialog boxes as well but the activity log usually contains more detailed and technical information e All sorts of debugging information that can be helpful when tracking down bugs e Information about loaded plugins While jEdit is running the log file on disk may n
131. much simpler syntax The following character sequences have special meaning within a glob pattern e matches any one character e matches any number of characters glob Matches anything that does not match glob a b c matches any one of a bor c abc matches any character in the set a bor c abc matches any character not in the set a b or c a z matches any character in the range a to z inclusive A leading or trailing dash will be interpreted literally In addition to the above a number of character class expressions may be used as well alnum matches any alphanumeric character alpha matches any alphabetical character blank matches a space or horizontal tab cntrl matches a control character digit matches a decimal digit graph matches a non space non control character Lower matches a lowercase letter print sameas graph but also space and tab punct matches a punctuation character space matches any whitespace character including newlines upper matches an uppercase letter xdigit matches a valid hexadecimal digit Here are some examples of glob patterns e all files e java all files whose names end with java e ch all files whose names end with either c or h 55 Glob Patterns e all files whose names do not start with
132. must be specified It must be set to the first character that the regular expression matches This rules out using regular expressions which can match more than one character at the start position The regular expression match cannot span more than one line either Any text matched by groups in the BI EGIN regular expression is substituted in the END string See below for an example of where this is useful Regular expression syntax is described in Appendix E Regular Expressions Here is a SPAN REGEXP rule that highlights read ins in shell scripts SPAN Bl REGEXP HASH CHAR EGIN gt lt CDATA lt lt lt END gt 1 lt END gt lt SPAN_REGEXP gt Here is a SPAN lt t1 is followed by a word break lt SPAN_R lt BE lt lt SPA Z b o The EOL SPAN Tag An EOL SPANis similar to a SPAN except that highlighting stops at the end of the line and no end sequence needs to be specified The text to match is specified between the opening and closing e c DY token types e AT A WHITESPACE END If set to TRUI E LITERAL space gt lt BEGIN gt TYPE LITERAL1 DELEGAT space alnum _ REGEXP rule that highlights constructs placed between 4 t 1 and gt as long as the EGEXP TYPE K
133. n one line APN At Scroll up down one page Text Editing For details see the section called Undo and Redo the section called Inserting and Deleting Text the section called Working With Words the section called Working With Lines and the section called Working With Paragraphs CZ Undo Cte Ctz Redo BACK_SPACE DELETE Delete character before after caret C BACK_SPACE C DELETE Delete word before after caret C d Cte d Delete line paragraph CS BACK_SPACE CS DELETE Delete from caret to beginning end of line Cte r Remove trailing whitespace from the current line or all selected lines Cty Join lines C b Complete word Cte f Format paragraph or selection Clipboard and Registers For details see the section called Transferring Text C x or S DELETE Cut selected text to clipboard C c or C INSERT Copy selected text to clipboard C C u Append selected text to clipboard removing it from the buffer e C a Append selected text to clipboard leaving it in the buffer C v or Sc INSERT Paste clipboard contents C p Vertically paste clipboard contents Ctr Ctx key Cut selected text to register key C r Cte key Copy selected text to register key C r Ctu key Append selected text to register key removing it from the
134. ne class provides a shortcut Here is its prototype public static Object showInputDialog Component parentComponent Object message String title int messageType Icon icon Object selectionValues Object initialSelectionValue This method creates a message box containing a drop down list of the options specified in the method s parameters along with OK and Cancel buttons Compared to showConfirmDialog this method lacks an opt ionType parameter and has three additional parameters an icon to display in the dialog which can be set to nu11 an array of selectionValues objects and a reference to one of the options as the initialSelectionValue to be displayed In addition instead of returning an int representing the user s action showInputDialog returns the Object corresponding to the user s selection or nu11 if the selection is canceled 102 Macro Tips and Techniques The following macro fragment illustrates the use of this method fragment illustrating use of showInputDialog options new Object 5 options 0 JLabel options 1 JTextField options 2 JCheckBox options 3 HistoryTextField options 4 y other Ns result JOptionPane showInputDialog view Choose component class Select class for input component JOptionPane QUESTION MESSAGE null options options 0 The return value result will contain either the St ring object representing the s
135. nge editor settings on a per buffer basis While changes made in the Buffer Options dialog box are lost after the buffer is closed buffer local properties take effect each time the file is opened because they are embedded in the file itself When jEdit loads a file it checks the first and last 10 lines for colon enclosed name value pairs For example placing the following in a buffer changes the indent width to 4 characters enables soft tabs and activates the Perl edit mode indentSize 4 noTabs true mode perl Adding buffer local properties to a buffer takes effect after the next time the buffer is saved The following table describes each buffer local property in detail Property name Description collapseFolds Folds with a level of this or higher will be collapsed when the buffer is opened If set to zero all folds will be expanded initially See the section called Folding deepIndent When set to true multiple line expressions delimited by parentheses are aligned like so retVal x int horizontalOffset Chunk offsetToX info chunks 38 Customizing jEdit Property name Description offset With this setting disabled the text would look like so retVal x int horizontalOffset Chunk offsetToX info chunks offset 90 66s folding The fold mode one of none indent explicit or the name of a plugin folding mode See the section called Fo
136. ns e matches the preceding expression or the null string e matches the null string or any number of repetitions of the preceding expression e matches one or more repetitions of the preceding expression e m matches exactly m repetitions of the one character expression e m n matches between m and n repetitions of the preceding expression inclusive e m matches m or more repetitions of the preceding expression Stingy Minimal Matching If a repeating operator above is immediately followed by a the repeating operator will stop at the smallest number of repetitions that can complete the rest of the match 59 Appendix F Macros Included With jEdit jEdit comes with a large number of sample macros that perform a variety of tasks The following index provides short descriptions of each macro in some cases accompanied by usage notes In addition to the macros included with jEdit a very large collection of user contributed macros is available in the Downloads section of the community jedit org web site There are detailed descriptions for each macro as well as a search facility Clipboard Macros These macros copy or cut text to the clipboard Copy Lines Containing bsh Copies all lines from the current buffer containing a user supplied string to the clipboard Cut Lines Containing bsh Cuts all lines from the current buffer containing a user supplied string to the clipboard Copy Selection o
137. ns e jars cache this directory contains plugin cache files which decrease the time to start jEdit They are automatically updated when plugins are installed or updated e killring xml stores recently deleted text See the section called Transferring Text macros this directory contains macros See Chapter 8 Using Macros modes this directory contains custom edit modes See Part II Writing Edit Modes e perspective xml an XML file that stores the list of open buffers and views used to maintain editor state between sessions e PluginManager download this directory is usually empty It only contains files while the plugin manager is downloading a plugin For information about the plugin manager see Chapter 9 Installing and Using Plugins 42 Customizing jEdit printspec a binary file that stores printing settings when running under Java 2 version 1 4 properties a plain text file that stores the majority of jEdit s settings recent xml an XML file which stores the list of recently opened files jEdit remembers the caret position and character encoding of each recent file and automatically restores those values when one of the files is opened registers xml an XML file that stores register contents See the section called General Register Commands for more information about registers server a plain text file that only exists while jEdit is running The edit server s port number and authorizati
138. nt are also extracted from properties using a static method of the option pane class The save method extracts data from the user input components and assigns them to the plugin s properties The implementation is straightforward public void save jEdit setProperty QuickNotepadPlugin OPTION PREFIX filepath pathName getText Font font font getFont Edit se f Edit se f Edit se Property QuickNotepadPlugin OPTION_PREFIX nt _font getFamily Property QuickNotepadPlugin OPTION_PREFIX ntsize String valueOf font getSize Property QuickNotepadPlugin OPTION PREFIX fontstyle String valueOf font getStyle Edit setProperty QuickNotepadPlugin OPTION PREFIX show filepath String valueOf showPath isSelected C UI CJ todctcodcod UMC UJ The class has only two other methods one to display a file chooser dialog in response to user action and the other to construct a Font object from the plugin s font properties They do not require discussion here 127 Implementing a Simple Plugin Plugin Documentation While not required by the plugin API a help file is an essential element of any plugin written for public release A single web page is often all that is required There are no specific requirements on layout but because of the design of jEdit s help viewer the use of frames should be avoided Topics that would b
139. o be undone If you undo too many changes Edit gt Redo shortcut C e C z can restore the changes again For example if some text was inserted Undo will remove it from the buffer Redo will insert it again By default the last 100 edits is retained older edits cannot be undone The maximum number of undos can be changed in the Editing pane of the Utilities gt Global Options dialog box see the section called The Editing Pane Working With Words C LEFT and C RIGHT move the caret a word at a time Holding down Shift in addition to the above extends the selection a word at a time A single word can be selected by double clicking with the mouse or using the Edit More Selection gt Select Word command shortcut C e w A selection that begins and ends on word boundaries can be created by double clicking and dragging C BACKSPACE and C DELETE delete the word before or after the caret respectively Edit Complete Word shortcut C b locates possible completions for the word at the caret first by looking in the current edit mode s syntax highlighting keyword list and then in the current buffer for words that begin with the word at the caret This serves as a very basic code completion feature If there is only one completion it will be inserted into the buffer immediately If multiple completions were found the longest common prefix is inserted into the buffer and a popup is shown below the caret position
140. o expand to System out println so to insert System out printIn in a Java buffer you only need to type sout followed by C An abbreviation can either be global in which case it can be used in all edit modes or specific to a single mode Abbreviations can be edited in the Abbreviations pane of the Utilities gt Global Options dialog box see the section called The Abbreviations Pane The Java VHDL XML and XSL edit modes include some pre defined abbreviations you might find useful Other modes do not have any abbreviations defined by default Edit gt Expand Abbreviation keyboard shortcut C attempts to expand the abbreviation named by the word before the caret If no expansion could be found it will offer to define one Automatic abbreviation expansion can be enabled in the Abbreviations pane of the Utilities Global Options dialog box If enabled pressing the space bar after entering an abbreviation will automatically expand it If automatic expansion is enabled a space can be inserted without expanding the word before the caret by pressing Cont rol E V Space Positional Parameters Positional parameters are an advanced feature that make abbreviations much more useful The best way to describe them is with an example 34 Editing Source Code Java mode defines an abbreviation F that is set to expand to the following for int 1 0 1 lt 2 1 Expanding F j array length will inser
141. o input at all In this section we outline some other techniques for obtaining input that will help you write macros quickly Getting a Single Line of Text As mentioned earlier in the section called Helpful Methods in the Macros Class the method Macros input offers a convenient way to obtain a single line of text input Here is an example that inserts a pair of HTML markup tags specified by the user Insert_Tag bsh void insertTag caret textArea getCaretPosition tag Macros input view Enter name of tag if tag null tag length 0 return text textArea getSelectedText if text null text W sb new StringBuffer sb append append tag append sb append text sb append append tag append textArea setSelectedText sb toString if text length 0 textArea setCaretPosition caret tag length 2 insertTag end Insert_Tag bsh Here the call to Macros input seeks the name of the markup tag This method sets the message box title to a fixed string Macro input but the specific message Enter name of tag provides all the information necessary The return value t ag must be tested to see if it is null This would occur if the user presses the Cancel button or closes the dialog window displayed by Macros input Getting Multiple Data Items If more than one item of input is needed a successi
142. od calls various methods to load and initialize plugins Additionally plugins using the new jEdit 4 2 plugin API can be loaded and unloaded at any time This is a great help when developing your own plugins there is no need to restart the editor after making changes see the section called Reloading the Plugin Note that plugins using the older jEdit 4 1 API are still only loaded on editor startup and unloaded on editor exit The jEdit 4 1 API is deprecated and will not be described in this guide Plugins are loaded from files with the jar filename extension located in the jars subdirectories of the jEdit installation and user settings directories see the section called The jEdit Settings Directory For each JAR archive file it finds jEdit scans its entries and performs the following tasks e Adds to a collection maintained by jEdit a new object of type P luginJAR This is a data structure holding the name of the JAR archive file a reference to the JARC1assLoader and a collection of plugins found in the archive file Loads any properties defined in files ending with the extension props that are contained in the archive See the section called The Property File e Reads action definitions from any file named act ions xm1 in the archive the file need not be at the top level See the section called The Action Catalog e Parses and loads the contents of any file named dockables xm1 in the archive the file ne
143. ode and installs the downloaded plugins in the jars subdirectory of the user specific settings directory These settings can be changed in Plugin Manager pane of the Utilities gt Global Options dialog box see the section called The Plugin Manager Pane The Update tab of the plugin manager is very similar to the Install tab It lists plugins for which updated versions are available It will also offer to delete any obsolete plugins Proxy Servers and Firewalls If you are connected to the Internet through an HTTP proxy or SOCKS firewall you will need to specify 46 Installing and Using Plugins the relevant details in the Proxy Servers pane of the Utilities gt Global Options dialog box see the section called The Proxy Servers Pane 47 Appendix A Keyboard Shortcuts This appendix documents the default set of keyboard shortcuts They can be customized to suit your taste in the Shortcuts pane of the Utilities gt Global Options dialog box see the section called The Global Options Dialog Box Files For details see the section called Switching Buffers the section called Multiple Views and Chapter 4 Working With Files C New file CF Open file C Close buffer C C w Close all buffers C s Save buffer C Cts Save all buffers C p Print buffer C PAGE_UP Go to previous buffer C PAGE_DOWN Go to next buffer Cc Go to recent buff
144. ode so while jEdit retains file permissions the owner and group of the file are reset and if it is a hard link the link is broken The two stage save feature can be disabled in the General pane of the Utilities gt Global Options dialog box see the section called The General Pane Autosave and Crash Recovery The autosave feature protects your work from computer crashes and such Every 30 seconds all buffers with unsaved changes are written out to their respective file names enclosed in hash characters For example program c will be autosaved to program c Saving a buffer using one of the commands in the previous section automatically deletes the autosave file so they will only ever be visible in the unlikely event of a jEdit or operating system crash If an autosave file is found while a buffer is being loaded jEdit will offer to recover the autosaved data The autosave interval can be changed in the Autosave and Backup pane of the Utilities gt Global Options dialog box see the section called The Autosave and Backup Pane Backups The backup feature can be used to roll back to the previous version of a file after changes were made When a buffer is saved for the first time after being opened its original contents are backed up under a different file name The behavior of the backup feature is specified in the Autosave and Backup pane of the Utilities gt Global Options dialog box
145. odes for jEdit 4 1 4 2 In jEdit 4 1 the mode file grammar has been cleaned up somewhat As a result some edit modes written for jEdit 4 0 and earlier need to be updated Defining WHITI activity logs e The KEYWORDS tag no longer accepts an IGNORE CASE attribute Set the IGNORE CASE attribute of the lt RULI I ESPACE gt rules is no longer necessary and doing so will print warnings to the ES tag instead e The END tag of the SPAN rule used to be optional in which case any occurrence of the start string would cause the remainder of the buffer to be highlighted with the span In jEdit 4 1 the END tag can no longer be omitted however a SEQ tag with a DELEGATE attribute can be used to achieve the same effect as endless span Defining S non alphanumeric character not appearing in a keyword definition or the ruleset s NO WORD SI EO TYP E NULL gt rules for word separators is no longer necessary Now any Eri tg attribute is considered a word separator 82 Part Ill Writing Macros This part of the user s guide covers writing macros for jEdit First we will tell you a little about BeanShell jEdit s macro scripting language Next we will walk through a few simple macros We then present and analyze a dialog based macro to illustrate additional macro writing techniques Finally we discuss several t
146. ods You could write it this way import java text DateFormat Date d new Date DateFormat df DateFormat getDateInstance String result df format d Taking the pieces in order e A Java Date object is created using the new keyword The empty parenthesis after Date signify a call on the constructor method of Date having no parameters here a Date is created representing the current date and time e DateFormat getDateInstance isa static method that creates and returns a DateFormat object As the name implies DateFormat is a Java class that takes Date objects and produces readable text The method getDateInstance returns a DateFormat object that parses and formats dates It will use the default locale or text format specified in the user s Java installation e Finally DateFormat format is called on the new DateFormat object using the Date object as a parameter The result is a St ring containing the date in the default locale Note that the Date class is contained in the java util package so an explicit import statement is not required However DateFormat is part of the java text package which is not automatically imported so an explicit import statement must be used 90 Macro Basics e The third example shows three items of note e getLineCount is a method in jEdit s JEditTextArea class It returns an int representing the number of lines in the current text buffer We call it on textArea the
147. og creates an empty content pane for itself as during its construction However to control the dialog s appearance as much as possible we will separately create our own content pane and attach it to the JDialog We do this by creating a JPanel object A JPanel is a lightweight container for other components that can be set to a given size and color It also contains a layout scheme for arranging the size and position of its components Here we are constructing a JPanel as a content pane with a BorderLayout We puta Empt yBorder inside it to serve as a margin between the edge of the window and the components inside We then attach the JPanel as the dialog s content pane replacing the dialog s home grown version A BorderLayout is one of the simpler layout schemes available for container objects like JPanel A BorderLayout divides the container into five sections North South East West and Center Components are added to the layout using the container s add method specifying the component to be added and the section to which it is assigned Building a component like our dialog window involves building a set of nested containers and specifying the location of each of their member components We have taken the first step by creating a JPanel as the dialog s content pane Create the Text Fields add the text fields fieldPanel new JPanel new GridLayout 4 1 0 6 prefixField new HistoryTextField macro add prefi
148. ompares the buffer s path name with the elements of the classpath being used by the jEdit session An error message will be displayed if no suitable package name is found This macro will not work if jEdit is being run as a JAR file without specifying a classpath in that case the classpath seen by the macro consists solely of the JAR file Java File Save bsh Abstract Acts as a wrapper script to the Save As action If the buffer is a new file it scans the first 250 lines for a Java class or interface declaration On finding one it extracts the appropriate filename to be used in the Save As dialog Make Get and Set Methods bsh 63 Macros Included With jEdit Creates get XXX or set XXX methods that can be pasted into the buffer text This macro presents a dialog that will grab the names of instance variables from the caret line of the current buffer and paste a corresponding get XXX or set XXX method to one of two text areas in the dialog The text can be edited in the dialog and then pasted into the current buffer using the Insert buttons If the caret is set to a line containing something other than an instance variable the text grabbing routine is likely to generate nonsense As explained in the notes accompanying the source code the macro uses a global variable which can be set to configure the macro to work with either Java or C code When set for use with C code the macro will also write in comm
149. on key is stored here See Chapter 2 Starting jEdit settings backup this directory contains numbered backups of all automatically written settings files 43 Chapter 8 Using Macros Macros in jEdit are short scripts written in a scripting language called BeanShell They provide an easy way to automate repetitive keyboard and menu procedures as well as access to the objects and methods created by jEdit Macros also provide a powerful facility for customizing jEdit and automating complex text processing and programming tasks This section describes how to record and run macros A detailed guide on writing macros appears later see Part III Writing Macros Other scripting languages A number of jEdit plugins provide support for writing scripts in alternative programming languages like Python and Prolog Consult the documentation for the appropriate plugins for more information Recording Macros The simplest use of macros is to record a series of key strokes and menu commands as a BeanShell script and play them back later While this doesn t let you take advantage of the full power of BeanShell it is still a great time saver and can even be used to prototype more complicated macros Macros gt Record Macro shortcut C m C r prompts for a macro name and begins recording While recording is in progress the string Macro recording is displayed in the status bar jEdit records the following e Key strokes Menu i
150. on of calls to Macros input isa possible but awkward approach because it would not be possible to correct early input after the corresponding message box is dismissed Where more is required but a full dialog layout is either unnecessary or too much work the Java method JOptionPane showConfirmDialog is available The version to use has the following prototype public static int showConfirmDialog Component parentComponent 100 Macro Tips and Techniques Object message String title int optionType int messageType The usefulness of this method arises from the fact that the message parameter can be an object of any Java class since all classes are derived from Ob ject or any array of objects The following example shows how this feature can be used excerpt from Write_File_Header bsh title Write file header currentName buffer getName nameField new JTextField currentName authorField new JTextField Your name here descField new JTextField 25 namePanel new JPanel new GridLayout 1 2 nameLabel new JLabel Name of file SwingConstants LEFT saveField new JCheckBox Save file when done buffer isNewFile namePanel add nameLabel namePanel add saveField message new Object 9 message 0 namePanel message 1 nameField message 2 Box createVerticalStrut 10 message 3
151. ontained in the specified directory whose names match the glob will be searched The directory to search in can either be entered in the Directory text field or chosen in a file selector dialog box by clicking the Choose button next to the field If the Search subdirectories check box is selected all subdirectories of the specified directory will also be searched Keep in mind that searching through directories containing many files can take a long time The Directory and Filter text fields remember previously entered strings see Appendix C History Text Fields for details When the search and replace dialog box is opened the directory and file name filter fields are set to their previous values They can be set to match the current buffer s directory and file name extension by clicking Synchronize Note that clicking the All Buffers or Directory radio buttons also selects the HyperSearch check box since that is what you would want most of the time However the HyperSearch check box can be unchecked for stepping through search results in multiple files one at a time Two convenience commands are provided for performing multiple file searches Search gt Search in Open Buffers shortcut Cte C b displays the search dialog box and selects the All buffers button Search gt Search in Directory shortcut Cte C d displays the search dialog box and selects the Directory button The Search Bar The search bar feature provides a convenient wa
152. ooking at program structure In the default configuration pressing ENTER will create a new line with the appropriate amount of indent automatically and pressing TAB at the beginning of or inside the leading whitespace of a line will insert the appropriate amount of indentation Pressing it again will insert a tab character The behavior of the ENTER and TAB keys can be configured in the Shortcuts pane of the Utilities gt Global Options dialog box just as with any other key The ENTER key can be bound to one of the following or indeed any other command or macro 32 Editing Source Code Insert Newline Insert Newline and Indent which is the default The TAB can be bound to one of the following or again any other command or macro Insert Tab Insert Tab or Indent which is the default Indent Selected Lines See the section called The Shortcuts Pane for details Auto indent behavior is mode specific In most edit modes the indent of the previous line is simply copied over However in C like languages C C Java JavaScript curly brackets and language statements are taken into account and indent is added and removed as necessary Edit gt Source gt Indent Selected Lines shortcut C i indents all selected lines or the current line if there is no selection To insert a literal tab or newline without performing indentation prefix the tab or newline with C e v For exampl
153. orts bsh This extend bsh This object Creates a new BeanShell This scripted object that is a child of the parameter object void importObject Object object Import an object into this namespace This is somewhat similar to Java 1 5 static class imports except you can import the methods and fields of a Java object instance into a BeanShell namespace for example Map map new HashMap importObject map put foo bar print get foo bar r r e bsh This object void Creates a new BeanShell This scripted object which can hold data members You can use this to create an object for storing miscellaneous crufties like so crufties object crufties foo hello world crufties counter 5 setNameSpace bsh Namespace namespace Set the namespace of the current scope to namespace 112 BeanShell Commands bsh This super String scopename Returns a reference to the BeanShell This object representing the enclosing method scope specified by scopename This method work similar to the super keyword but can refer to enclosing scope at higher levels in a hierarchy of scopes void unset String name Removes the variable named by name from the current interpreter namespace This has the effect of undefining the variable Other Commands e void debug void Toggles BeanShell s internal debug reporting to the output stream of the current process getSourceFileInfo void
154. ot always accurately reflect what has been logged due to buffering being done for performance reasons To ensure the file on disk is up to date invoke the Utilities gt Troubleshooting gt Update Activity Log on Disk command The log file is also automatically updated on disk when jEdit exits 53 Appendix C History Text Fields The text fields in the search and replace dialog box and the file system browser remember the last 20 entered strings by default The number of strings to remember can be changed in the Appearance pane of the Utilities gt Global Options dialog box see the section called The Appearance Pane Pressing UP recalls previous strings Pressing DOWN after recalling previous strings recalls later strings Pressing S UP or S DOWN will search backwards or forwards respectively for strings beginning with the text already entered in the text field Clicking the triangle to the right of the text field or clicking with the right mouse button anywhere else will display a pop up menu of all previously entered strings selecting one will input it into the text field Holding down Shift while clicking will display a menu of all previously entered strings that begin with the text already entered 54 Appendix D Glob Patterns jEdit uses glob patterns similar to those in the various Unix shells to implement file name filters in the file system browser Glob patterns resemble regular expressions somewhat but have a
155. ould allow the notepad to be displayed or hidden with a single mouse click or keypress if a keyboard shortcut were defined The contents of the notepad could be saved at program exit or if earlier deactivation of the plugin and retrieved at program startup or plugin activation We will keep the capabilities of this plugin modest but a few other features would be worthwhile The user should be able to write the contents of the notepad to storage on demand It should also be possible to choose the name and location of the file that will be used to hold the notepad text This would allow the user to load other files into the notepad display The path of the notepad file should be displayed in the plugin window but will give the user the option to hide the file name Finally there should be an action by which a single click or keypress would cause the contents of the notepad to be written to the new text buffer for further processing The full source code for QuickNotepad is contained in jEdit s source code distribution We will provide excerpts in this discussion where it is helpful to illustrate specific points You are invited to obtain the source code for further study or to use as a starting point for your own plugin How Plugins are Loaded We will discuss the implementation of the QuickNotepad plugin along with the jEdit APIs it makes use of But first we describe how plugins are loaded As part of its startup routine jEdit s main meth
156. owing in one of the first or last 10 lines of the buffer where mode is either none soft or hard and column is the desired wrap margin wrap mode maxLineLen column Soft Wrap In soft wrap mode lines are automatically wrapped when displayed on screen Newlines are not inserted at the wrap positions and the wrapping is automatically updated when text is inserted or removed If end of line markers are enabled in the Text Area pane of the Utilities gt Global Options dialog box a 66 99 colon is painted at the end of wrapped lines See the section called The Text Area Pane Hard Wrap In hard wrap mode inserting text at the end of a line will automatically break the line if it extends beyond the wrap margin Inserting or removing text in the middle of a line has no effect however text can be re wrapped using the Edit gt Text gt Format Paragraph command See the section called Working With Paragraphs Hard wrap is implemented using character offsets not screen positions so it might not behave like you expect if a proportional width font is being used The text area font can be changed in the Text Area pane of the Utilities gt Global Options dialog box Scrolling If you have a mouse with a scroll wheel and are running Java 2 version 1 4 you can use the wheel to scroll up and down in the text area Various modifier keys change the action of the wheel Shift scrolls an entire page at a time
157. pace of every BeanShell script Because of this the script output of a recorded macro does not contain import statements For the same reason most BeanShell scripts you write will not require import statements Java requires import statement to be located at the beginning of a source file BeanShell allows you to place import statements anywhere in a script including inside a block of statements The import statement will cover all names used following the statement in the enclosing block If you try to use a class that is not imported without its fully qualified name the BeanShell interpreter will complain with an error message relating to the offending line of code Here is the full list of packages automatically imported by jEdit ava awt c GIL SVANE SASE ava util ava io ava lang avax swing avax swing eve sp jedi sp jedi sp jedi Sp jedi Sp jedi 3S9 grexeht Sp jedi Sp jedi Sp jedi Y ct browser SOUE IESE o Gaal alae ils LO msg options pluginmgr er iar ar Xm Gr deret mp eu puc fer dg FS Gene mr gue eue et ET En ER Eee TQ ar ps Qe TES EE TES ETE 86 Macro Basics c Die atiane Search Syntax J Set ieee Predefined Variables in BeanShell The following variables are always available for use in BeanShell scripts buffer a Buffer object represents the contents of the currently visible open text file e view A View represents the curren
158. pathName new JTextField jEdit getProperty 126 Implementing a Simple Plugin QuickNotepadPlugin OPTION_PREFIX filepath JButton pickPath new JButton jEdit getProperty QuickNotepadPlugin OPTION_PREFIX choose file pickPath addActionListener this JPanel pathPanel new JPanel new BorderLayout 0 0 pathPanel add pathName BorderLayout CENTER pathPanel add pickPath BorderLayout EAST addComponent jEdit getProperty QuickNotepadPlugin OPTION_PREFIX file pathPanel font new FontSelector makeFont addComponent jEdit getProperty QuickNotepadPlugin OPTION PREFIX choose font font Here we adopt the vertical arrangement offered by use of the addComponent method with one embellishment We want the first row of the option pane to contain a text field with the current notepad file path and a button that will trigger a file chooser dialog when pressed To place both of them on the same line along with an identifying label for the file option we create a JPanel to contain both components and pass the configured panel to addComponent The init method uses properties from the plugin s property file to provide the names of label for the components placed in the option pane It also uses a property whose name begins with PROPERTY PREFIX as a persistent data item the path of the current notepad file The elements of the notepad s fo
159. pre defined current JEditTextArea object The use of the operator which can be chained as here appends objects and string literals to return a single concatenated St ring 91 Chapter 14 A Dialog Based Macro Now we will look at a more complicated macro which will demonstrate some useful techniques and BeanShell features Use of the Macro Our new example adds prefix and suffix text to a series of selected lines This macro can be used to reduce typing for a series of text items that must be preceded and following by identical text In Java for example if we are interested in making a series of calls to StringBuffer append to construct a lengthy formatted string we could type the parameter for each call on successive lines as follows profileString 1 secretThing toString name address addressSupp city state province country Our macro would ask for input for the common prefix and suffix to be applied to each line in this case the prefix is ourStringBuffer append and the suffix is After selecting these lines and running the macro the resulting text would look like this ourStringBuffer appe ourStringBuffer app ourStringBuffer appe name ourStringBuffer appe address nd profileString 1 nd nd nd ourStringBuffer append addressSupp nd nd nd secretThing toString ourStringBuffer appe city ourStringBuffer appe state province ourStringBuffer appe country
160. pter multiple views can be opened at once and views can be split into multiple panes View gt New View creates a new view View gt New Plain View creates a new view but without any tool bars or docked windows This can be used to open a small window for taking notes and so on View gt Close View closes the current view If only one view is open closing it will exit jEdit unless background mode is on see Chapter 2 Starting jEdit for information about starting jEdit in background mode View gt Split Horizontally shortcut C 2 splits the view into two text areas placed above each other View gt Split Vertically shortcut C 3 splits the view into two text areas placed next to each other View gt Unsplit Current shortcut C 0 removes the split containing the current text area only View gt Unsplit All shortcut C 1 removes all splits from the view When view is split editing commands operate on the text area that has keyboard focus To give a text area keyboard focus click in it with the mouse or use the following commands View gt Go to Previous Text Area shortcut A PAGE_UP shifts keyboard focus to the previous text area View gt Go to Next Text Area shortcut AX PAGE DOWN shifts keyboard focus to the next text area Window Docking Various jEdit and plugin windows can be docked into the view for convenience Dockable windows have a popup button in their top left corner Clicking this button displays a menu
161. r Line bsh If no text is selected the current line is copied to the clipboard otherwise the selected text is copied to the clipboard Some editors have this has the default copy behavior To achieve the same effect in jEdit bind this macro to C c in the Shortcuts pane of the Utilities Global Options dialog box Cut Selection or Line bsh If no text is selected the current line is cut to the clipboard otherwise the selected text is cut to the clipboard Some editors have this has the default cut behavior To achieve the same effect in jEdit bind this macro to C x in the Shortcuts pane of the Utilities Global Options dialog box Copy Visible Lines bsh Copies the visible lines from the current buffer to the Clipboard Lines that are not visible becuase they are folded are not copied Editing Macros These macros automate various text editing tasks Emacs Next Line bsh Moves the cursor to the next line centering the current line in the middle of the text area if the cursor is at the bottom of the text area Emacs Previous Line bsh Moves the cursor to the previous line centering the current line in the middle of the text area if the cursor is at the top of the text area Go to Column bsh 60 Macros Included With jEdit Prompts the user for a column position on the current line then moves the caret there Greedy_Backspace bsh If buffer is using soft tabs this macro will backspace to the previous tab s
162. r code is indented as follows with braces on their own lines public void someMethod if isOK 33 Editing Source Code doSomething Invoking Edit gt Source gt Go to Matching Bracket shortcut C or clicking the scope indicator in the gutter moves the caret to the matching bracket Edit gt Source gt Select Code Block shortcut C selects all text between the closest two brackets surrounding the caret Holding down Control while clicking the scope indicator in the gutter or a bracket in the text area will select all text between the two matching brackets Edit gt Source gt Go to Previous Bracket shortcut Cte C moves the caret to the previous opening bracket Edit gt Source gt Go to Next Bracket shortcut Cte C moves the caret to the next closing bracket Bracket highlighting in the text area and bracket scope display in the gutter can be customized in the Text Area and Gutter panes of the Utilities gt Global Options dialog box see the section called The Global Options Dialog Box Tip jEdit s bracket matching algorithm only checks syntax tokens with the same type as the original bracket so for example unmatched brackets inside string literals and comments will be skipped when matching brackets that are part of program syntax Abbreviations Using abbreviations reduces the time spent typing long but commonly used strings For example in Java mode the abbreviation sout is defined t
163. r discarded In the dialog box multiple buffers to operate on at once can be selected by clicking on them in the list while holding down Cont rol After all buffers have been closed a new untitled buffer is opened File gt Exit shortcut C q will completely exit jEdit prompting if unsaved buffers should be saved first 17 Chapter 5 Editing Text Moving The Caret The simplest way to move the caret is to click the mouse at the desired location in the text area The caret can also be moved using the keyboard The LEFT RIGHT UP and DOWN keys move the caret in the respective direction and the PAGE_UP and PAGE_DOWN keys move the caret up and down one screenful respectively When pressed once the HOME key moves the caret to the first non whitespace character of the current screen line Pressing it a second time moves the caret to the beginning of the current buffer line Pressing it a third time moves the caret to the first visible line The END key behaves in a similar manner going to the last non whitespace character of the current screen line the end of the current buffer line and finally to the last visible line If soft wrap is disabled a screen line is the same as a buffer line If soft wrap is enabled a screen line is a section of a newline delimited buffer line that fits within the wrap margin width See the section called Wrapping Long Lines C HOME and C END move the caret to t
164. riables in Unix shell scripts CLASSPATH SIFS etc MARK FOLLOWING TYPE KEYWORD2 2S MARK FOLLOWING The SEQ Tag The S1 EO rule which must be placed inside a RULES tag highlights fixed sequences of text The text to highlight is specified between opening and closing SEO tags The following attributes are supported TYPI of token types A Al A OIN E START If set to TRUI beginning of a line E the token type to highlight the sequence with See the section called Token Types for a list E the sequence will only be highlighted if it occurs at the WHITESPACE END If set to TRUE the sequence will only be highlighted if it is the first non whitespace text in the line WORD START If set to TRU beginning of a word D EL EGAT E the sequence will only be highlighted if it occurs at the E if this attribute is specified all text after the sequence will be highlighted using this ruleset To delegate to a ruleset defined in the current mode just specify its name To delegate to a ruleset defined in another mode specify a name of the form mode ruleset Note that the first unnamed ruleset in a mode is called MAIN The following rules highlight a few Java operators S EO TYP E OPERATOR gt lt SEQ gt TI Mode Definition Syntax SEQ TYPE OPERATOR
165. ros message view tracing Execution of the macro is halted until the message dialog box is closed When you have finished debugging the macro you should delete or comment out the debugging calls to Macros message in your final source code 109 Chapter 16 BeanShell Commands BeanShell includes a set of commands subroutines that can be called from any script or macro The following is a summary of those commands which may be useful within jEdit Note Java classes in plugins cannot make use of BeanShell commands directly However these commands can be called from BeanShell code that is part of a plugin for example the snippets in actions xml or any BeanShell scripts shipped with the plugin and loaded on startup Output Commands void cat String filename Writes the contents of filename to the activity log void javap String Object Class target Writes the public fields and methods of the specified class to the output stream of the current process Requires Java 2 version 1 3 or greater e void print arg Writes the string value of the argument to the activity log or if run from the Console plugin to the current output window If arg is an array print runs itself recursively on the array s elements File Management Commands void ed String dirname Changes the working directory of the BeanShell interpreter to di rname e void ep String fromFile String toFile Copy romFileto toFile
166. ry Text Fields for details If text was selected in the text area and the selection does not span a line break the selected text becomes the default search string If the selection spans a line break the Search in Selection and HyperSearch buttons will be 26 Editing Text pre selected and the search string field will be initially blank See the section called HyperSearch for information about the HyperSearch feature Selecting the Ignore case check box makes the search case insensitive for example searching for Hello will match hello HELLO and HeLlO Selecting the Regular expressions check box allows a regular expression to be used in the search string Regular expressions can match inexact sequences of text that optionally span more than one line Regular expression syntax is described in Appendix E Regular Expressions The Backward and Forward buttons specify the search direction Note that regular expressions can only be used when searching in a forward direction Clicking Find will locate the next occurrence of the search string or previous occurrence if searching backwards If the Keep dialog check box is selected the dialog box will remain open after the search string has been located otherwise it will close If no occurrences could be found and the Auto wrap check box is selected the search will automatically restart from the beginning of the buffer or the end if searching back
167. s it covers Now For Something Useful Here is a macro that inserts the path of the current buffer in the text 89 Macro Basics String newText buffer getPath textArea setSelectedText newText Unlike in our first macro example here we are calling class methods on particular objects First we call getPath on the current Buffer object to get the full path of the text file currently being edited Next we call setSelectedText on the current text display component specifying the text to be inserted as a parameter In precise terms the set SelectedText method substitutes the contents of the St ring parameter for a range of selected text that includes the current caret position If no text is selected at the caret position the effect of this operation is simply to insert the new text at that position Here s a few alternatives to the full file path that you could use to insert various useful things the file name without full path String newText buffer getName today s date import java text DateFormat String newText DateFormat getDateInstance format new Date a line count for the current buffer String newText This file contains textArea getLineCount lines Here are brief comments on each e In the first the call to getName invokes another method of the Buffer class The syntax of the second example chains the results of several meth
168. s started depends on the operating system For example on Unix you can run jedit at the command line or select jEdit from a menu on Windows you can double click on the jEdit icon or select it from the Start menu If jEdit is started while another copy is already running control is transferred to the running copy and a second instance is not loaded This saves time and memory if jEdit is started multiple times Communication between instances of jEdit is implemented using TCP IP sockets the initial instance is known as the server and subsequent invocations are clients If you find yourself launching and exiting jEdit a lot the startup time can get a bit bothersome If the background command line switch is specified jEdit will continue running and waiting for client requests even after all editor windows are closed When run in background mode you can open and close jEdit any number of times only having to wait for it to start the first time The downside of this is increased memory usage When running on MacOS X the background command line switch is active by default so that jEdit conforms to the platform convention that programs should stay open until the Quit command is explicitly invoked by the user even if all windows are closed To disable background mode on MacOS X use the nobackground switch For more information about command line switches that control the server feature see the section called Command Line Usage
169. serting and Deleting Text Line separator see the section called Line Separators e A Java heap memory usage indicator that shows used and total heap memory in megabytes Double clicking this indicator opens the Utilities Troubleshooting Memory Status dialog box The visibility of each of the above items can be controlled in the Status Bar pane of the Utilities gt Global Options dialog box see the section called The Status Bar Pane The Action Bar The action bar allows almost any editor feature to be accessed from the keyboard Utilities gt Action Bar shortcut C ENTER displays the action bar at the bottom of the view and gives it keyboard focus The action bar remembers previously entered strings see Appendix C History Text Fields for details To use the action bar input a command and press Enter The following commands are supported Action invocations Each menu item and tool bar button is bound to an action To find out the name of an action invoke the menu item or click the tool bar button and look in the action bar s history If a substring or an action name is entered pressing Tab shows a popup listing matching actions An action can be selected using the Up and Down arrow keys or by entering more characters of its name Pressing Enter with an incomplete substring invokes the action that would be first in the completion popup s list For example entering 1 0 will match g1obal options w
170. sh Creates a new buffer with installation and error information extracted from the activity log The macro extracts initial messages written to the activity log describing the user s operating system JDK jEdit version and installed plugins It then appends the last set of error messages written to the activity log The new text buffer can be saved and attached to an email message or a bug report made on SourceForge Run Script bsh Runs script using interpreter based upon buffer s editing mode by default determined using file extension You must have the appropriate interpreter such as Perl Python or Windows Script Host installed on your system Show Threads bsh Displays in a tree format all running Java threads of the current Java Virtual Machine Property Macros These macros produce lists or tables containing properties used by the Java platform or jEdit itself Insert Buffer Properties bsh Inserts buffer local properties into the current buffer If the buffer s mode has a line comment defined or comment start and end defined the inserted properties will be commented out 65 Macros Included With jEdit e jEdit Properties bsh Writes an unsorted list of jEdit properties in a new buffer Look and Feel Properties bsh Writes an unsorted list of the names of Java Look and Feel properties in a new buffer System Properties bsh Writes an unsorted list of all Java system properties in a new buffer Text Ma
171. shortcuts Pressing a letter key will scroll the table to the first entry beginning with that letter A further option is provided to write the shortcut assignments in a text buffer for printing as a reference Notes in the source code listing point out some display options that are configured by modifying global variables Evaluate Buffer in BeanShell bsh 64 Macros Included With jEdit Evaluates contents of current buffer as a BeanShell script and opens a new buffer to receive any text output This is a quick way to test a macro script even before its text is saved to a file Opening a new buffer for output is a precaution to prevent the macro from inadvertently erasing or overwriting itself BeanShell scripts that operate on the contents of the current buffer will not work meaningfully when tested using this macro Hex Convert bsh Converts byte characters to their hex equivalent and vice versa HyperSearch Results to Buffer bsh Writes HyperSeach results to a new buffer Include Guard bsh Intended for C C header files this macro inserts a preprocessor directive in the current buffer to ensure that the header is included only once per compilation unit To use the macro first place the caret at the beginning of the header file before any uncommented text The macro will return to this position upon completion The defined term that triggers the include guard is taken from the buffer s name Make Bug Report b
172. summary views Plugins may provide a range of options that the user can modify to alter their configuration If a plugin provides configuration options in accordance with the plugin API jEdit will make them available in the Global Options dialog box While it is not required plugins are encouraged to provide documentation As noted many of these features are optional it is possible to write a plugin that does not provide actions configuration options or dockable windows The majority of plugins however provide most of these services 115 Introducing the Plugin API Plugins and different jEdit versions As jEdit continues to evolve and improve elements of the plugin API may change with a new jEdit release On occasion an API change will break code used by plugins although efforts are made to maintain or deprecate plugin related code on a transitional basis While the majority of plugins are unaffected by most changes and will continue working it is a good idea to monitor the jEdit change log the mailing lists and community jedit org for API changes so that you can update your plugin if necessary 116 Chapter 18 Implementing a Simple Plugin There are many applications for the leading operating systems that provide a scratch pad or sticky note facility for the desktop display A similar type of facility operating within the jEdit display would be a convenience The use of dockable windows w
173. supplied by the user in an input dialog Open Selection bsh Opens the file named by the current buffer s selected text Toggle ReadOnly bsh Toggles a local file s read only flag Uses platform specific commands so it only works on Windows Unix and MacOS X User Interface Macros Description Decrease Font Size bsh Decreases the font size in the gutter and text area by 1 point 62 Macros Included With jEdit Increase Font Size bsh Increases the font size in the gutter and text area by 1 point Open Context Menu bsh Opens the text area context menu just below and to the right of the caret Toggle Bottom Docking Area bsh Expands or collapses the bottom docking area depending on it s current state Toggle Left Docking Area bsh Expands or collapses the left docking area depending on it s current state Toggle Right Docking Area bsh Expands or collapses the right docking area depending on it s current state Toggle Top Docking Area bsh Expands or collapses the top docking area depending on it s current state Java Code Macros These macros handle text formatting and generation tasks that are particularly useful in writing Java code Create Constructor bsh Inserts constructor for the class at the current caret position Get Class Name bsh Inserts a Java class name based upon the buffer s file name Get Package Name bsh Inserts a plausible Java package name for the current buffer The macro c
174. t Fold shortcut A DOWN moves the caret to the fold immediately after the caret position Miscellaneous Folding Commands Folding gt Add Explicit Fold shortcut C e a surrounds the selection with and V If the 36 Editing Source Code current buffer s edit mode defines comment strings see the section called Commenting Out Code the explicit fold markers will automatically be commented out as well Folding gt Select Fold shortcut C e s selects all lines within the fold containing the caret Control clicking a fold expansion triangle in the gutter has the same effect Folding gt Expand Folds With Level shortcut Cte ENTER key reads the next character entered at the keyboard and expands folds in the buffer with a fold level less than that specified while collapsing all others Sometimes it is desirable to have files open with folds initially collapsed This can be configured as follows e Ona global or mode specific basis in the Editing pane of the Utilities Global Options dialog box See the section called The Editing Pane Inthe current buffer for future editing sessions by placing the following in the first or last 10 lines of a buffer where 1evel is the desired fold level collapseFolds level Narrowing The narrowing feature temporarily narrows the display of a buffer to a specified region Text outside the region is not shown but is still present in the buffer Ho
175. t and end string lements of the SPAN tag The following attributes TYPE The token type to highlight the span with See the section called Token Types for a list of token types e AT LINE START If set to TRUE the span will only be highlighted if the start sequence occurs at the beginning of a line AT WHITESPACE END If set to TRUI the first non whitespace text in the line GJ e AT WORD START If set to TRU the beginning of a word GJ the span will only be highlighted if the start sequence is the span will only be highlighted if the start sequence occurs at e DELEGATE text inside the span will be highlighted with the specified ruleset To delegate to a ruleset defined in the current mode just specify its name To delegate to a ruleset defined in another mode specify a name of the form mode ruleset Note that the first unnamed ruleset in a mode is called MAIN GJ EXCLUDE_MATCH If set to TRUI text between them will the start and end sequences will not be highlighted only the NO ESCAPE If set to TRUE the ruleset s escape character will have no effect before the span s end string Otherwise the presence of the escape character will cause that occurrence of the end string to be ignored NO LINE BREAK If set to TRUE the span will not cross line breaks NO WORD BREAK
176. t the following text into the buffer for int j 0 j lt array length j Expansions can contain up to nine positional parameters Note that a trailing hash character must be entered when expanding an abbreviation with parameters If you do not specify the correct number of positional parameters when expanding an abbreviation any missing parameters will be blank in the expansion and extra parameters will be ignored A status bar message will be shown stating the required number of parameters Folding Program source code and other structured text files can be thought of as containing a hierarchy of sections which themselves might contain sub sections The folding feature lets you selectively hide and show these sections replacing hidden ones with a single line that serves as an overview of that section Folding is disabled by default To enable it you must choose one of the available folding modes Indent mode creates folds based on a line s leading whitespace the more leading whitespace a block of text has the further down it is in the hierarchy For example This is a section This is a sub section This is another sub section This is a sub sub section Another top level section Explicit mode folds away blocks of text surrounded with and For example The first line of a fold When this fold is collapsed only the above line will be visible A sub section With text
177. t top level editor window extending Java s JF rame class that contains the various visible components of the program including the text area menu bar toolbar and any docked windows This variable has the same value as the return value of jEdit getActiveView e editPane an EditPane object contains a text area and buffer switcher A view can be split to display edit panes Among other things the EditPane class contains methods for selecting the buffer to edit Most of the time your macros will manipulate the buffer or the textArea Sometimes you will need to use view as a parameter in a method call You will probably only need to use editPane if your macros work with split views This variable has the same value as the return value of view getEditPane e textArea a JEditTextArea is the visible component that displays the current buffer This variable has the same value as the return value of editPane getTextArea e wm a DockableWindowManager is the visible component that manages dockable windows in the current view This class is discussed in detail in Part IV Writing Plugins This object is useful for writing macros that interface with open or close plugin windows This variable has the same value the return value of view getDockableWindowManager e scriptPath set to the full path of the script currently being executed e scriptPath set to the full path of the script currently being executed 87
178. t whose width expands to fill its parent component in this case the message box The single parameter indicates the height of the strut in pixels The last call to createVerticalStrut separates the description text field from the OK and Cancel buttons that are automatically added by showConfirmDialog e Finally the call to showConfirmDialog uses defined constants for the option type and the message type The constants are the same as those used with the Macros confirm method see the section called Helpful Methods in the Macros Class The option type signifies the use of OK and Cancel buttons The QUERY MESSAGE message type causes the message box to display a question mark icon The return value of the method is tested against the value OK OPTION If the return value is something else because the Cancel button was pressed or because the message box window was closed without a button press a nu11 value is returned to a calling function signaling that the user canceled macro execution If the return value is OK OPTION each of the input components can yield their contents for further processing by calls to JTextField getText or in the case of the check box JCheckBox isSelected Selecting Input From a List Another useful way to get user input for a macro is to use a combo box containing a number of pre set options If this is the only input required one of the versions of showInputDialog inthe JOptionPa
179. tag for Java mode lt PROPS gt lt PROPERTY NAME commentStart VALUE gt lt PROPERTY NAME commentEnd VALUE gt lt PROPERTY NAME lineComment VALUE gt lt PROPERTY NAME wordBreakChars VALUE amp 1t amp gt amp amp gt Auto indent lt PROPERTY NAME indentOpenBrackets VALUE gt lt PROPERTY NAME indentCloseBrackets VALUE gt lt PROPERTY NAME indentNextLine VALUE s if while s else s else stif s for s 71 lt set this to true if you want to use GNU coding style gt lt PROPERTY NAME doubleBracketIndent VALUE false lt PROPERTY NAME lineUpClosingBracket VALUE true gt lt PROPS gt 71 Mode Definition Syntax The RULES Tag RULES tags must be placed inside the MODE tag Each RULES tag defines a ruleset A ruleset consists of a number of parser rules with each parser rule specifying how to highlight a specific syntax token There must be at least one ruleset in each edit mode There can also be more than one with different rulesets being used to highlight different parts of a buffer for example in HTML mode one rule set highlights HTML tags and another highlights inline JavaScript For information about using more than one ruleset see the section called The SPAN Tag The RULES tag supports the following attributes all of
180. tem commands Tool bar clicks e All search and replace operations except incremental search Mouse clicks in the text area are not recorded use text selection commands or arrow keys instead Macros gt Stop Recording shortcut C m C s stops recording It also switches to the buffer containing the recorded macro giving you a chance to check over the recorded commands and make any necessary changes When you are happy with the macro save the buffer and it will appear in the Macros menu To discard the macro close the buffer without saving it The file name extension bsh is automatically appended to the macro name and all spaces are converted to underscore characters in order to make the macro name a valid file name These two operations are reversed when macros are displayed in the Macros menu see the section called How jEdit Organizes Macros for details If a complicated operation only needs to be repeated a few times using the temporary macro feature is quicker than saving a new macro file Macros gt Record Temporary Macro shortcut C m C m begins recording to a buffer named Temporary Macro bsh Once recording of a temporary macro is complete jEdit does not display the buffer containing the recorded commands but the name Temporary Macro bsh willbe visible on any list of open buffers By switching to that buffer you can view the commands edit them and save them if you wish to a permanent macro file Whether or not you look at or
181. text into a rectangular selection repeats the text going down as many times as necessary and shifts the selection to the right This makes it behave like a tall caret Rectangles can be deleted copied pasted and operated on using ordinary editing commands If necessary rectangular selections are automatically filled in with whitespace to maintain alignment Rectangular selections can extend beyond the end of a line into virtual space Furthermore if keyboard rectangular selection mode is on or if the Cont rol key is being held down clicking beyond the end of a line will insert the appropriate amount of whitespace in order to position the cursor at the clicked location Note Rectangular selections are implemented using character offsets not absolute screen positions 19 Editing Text so they might not behave as you might expect if a proportional width font is being used or if soft wrap is enabled The text area font can be changed in the Text Area pane of the Utilities gt Global Options dialog box For information about soft wrap see the section called Wrapping Long Lines Multiple Selection Edit gt More Selection gt Multiple Selection keyboard shortcut C turns multiple selection mode on and off In multiple selection mode multiple fragments of text can be selected and operated on simultaneously and the caret can be moved independently of the selection The status bar indicates if multiple selection
182. tic expressions contained in curly braces with the result of evaluating the expression search for the following regular expression VE Lace EN Replacing it with the following BeanShell snippet eval 1 These examples only scratch the surface the possibilities are endless HyperSearch If the HyperSearch check box in the search and replace dialog box is selected clicking Find lists all occurrences of the search string instead of locating the next match By default HyperSearch results are shown in a floating window This window can be docked using the commands in its top left corner popup menu see the section called Window Docking If the Multiple results check box is selected in the results window past search results are retained Running searches can be stopped in the Utilities Troubleshooting 2I O Progress Monitor dialog box 28 Editing Text Multiple File Search Search and replace commands can be performed over an arbitrary set of files in one step The set of files to search is selected with a set of buttons in the search dialog box If the Current buffer button is selected only the current buffer is searched This is the default behavior If the All buffers button is selected all open buffers whose names match the glob pattern entered in the Filter text field will be searched See Appendix D Glob Patterns for more information about glob patterns If the Directory radio button is selected all files c
183. tically imported must be identified by a full qualified name or be the subject of an import statement Create the Dialog create dialog object title Add prefix and suffix to selected lines dialog new JDialog view title false content new JPanel new BorderLayout content setBorder new EmptyBorder 12 12 12 12 dialog setContentPane content To get input for the macro we need a dialog that provides for input of the prefix and suffix strings an OK button to perform text insertion and a Cancel button in case we change our mind We have decided to make the dialog window non modal This will allow us to move around in the text buffer to find things we may need including text to cut and paste while the macro is running and the dialog is visible The Java object we need is a Dialog object from the Swing package To construct one we use the new keyword and call a constructor function The constructor we use takes three parameters the owner of the new dialog the title to be displayed in the dialog frame and a boolean parameter t rue or false that specifies whether the dialog will be modal or non modal We define the variable title using a string literal then use it immediately in the JDialog constructor 94 A Dialog Based Macro A JDialog object is a window containing a single object called a content pane The content pane in turn contains the various visible components of the dialog A JDial
184. ting 4 1 plugins jEdit 4 2 plugins are distinguished from jEdit 4 1 plugins by the presence of the plugin name activate property If this property is set the plugin is treated like a jEdit 4 2 plugin Usually this property should be set to defer See the API documentation for the EditPlugin class for details The Action Catalog Actions define procedures that can be bound to a menu item a toolbar button or a keyboard shortcut Actions are short scripts written in BeanShell jEdit s macro scripting language These scripts either direct the action themselves delegate to a method in one of the plugin s classes that encapsulates the action or do a little of both The scripts are usually short elaborate action protocols are usually contained in compiled code rather than an interpreted macro script to speed execution Actions are defined by creating an XML file entitled act ions xm1 and placing it in the plugin JAR file The actions xml file from the QuickNotepad plugin looks as follows lt xml version 1 0 gt 121 Implementing a Simple Plugin lt DOCTYPE ACTIONS SYSTEM actions dtd gt lt ACTIONS gt lt ACTION NAME quicknotepad choose file gt lt CODE gt wm getDockable QuickNotepadPlugin NAME chooseFile lt CODE gt lt ACTION gt lt ACTION NAME quicknotepad save file gt lt CODE gt wm getDockable QuickNotepadPlugin NAME saveFile lt CODE gt lt ACTION gt
185. tokens can be changed in the Syntax Highlighting pane of the Utilities gt Global Options dialog box see the section called The Syntax Highlighting Pane Tabbing and Indentation jEdit makes a distinction between the tab width which is is used when displaying hard tab characters and the indent width which is used when a level of indent is to be added or removed for example by mode specific auto indent routines Both can be changed in one of several ways e Ona global or mode specific basis in the Editing pane of the the Utilities gt Global Options dialog box See the section called The Editing Pane e Inthe current buffer for the duration of the editing session in the Utilities Buffer Options dialog box See the section called The Buffer Options Dialog Box Inthecurrent buffer for future editing sessions by placing the following in one of the first or last 10 31 Editing Source Code lines of the buffer where n is the desired tab width and mis the desired indent width tabSize n indentSize m Edit gt Indent gt Shift Indent Left shortcut S TAB or A LEFT adds one level of indent to each selected line or the current line if there is no selection Edit gt Indent gt Shift Indent Right shortcut A4 RIGHT removes one level of indent from each selected line or the current line if there is no selection Pressing Tab while a multi line selection is active has the same effect Edit gt Indent gt Remove
186. top if all characters between the caret and the tab stop are spaces In all other cases a single character is removed e Greedy_Delete bsh If a buffer is using soft tabs this macro will delete tabSize number of spaces if all the characters between the caret and the next tab stop are spaces In all other cases a single character is deleted Greedy Left bsh If a buffer is using soft tabs this macro will move the caret tabSize spaces to the left if all the characters between the caret and the previous tab stop are all spaces In all other cases the caret is moved a single character to the left Greedy Right bsh If a buffer is using soft tabs this macro will move the caret tabSize spaces to the right if all the characters between the caret and the next tab stop are all spaces In all other cases the caret is moved a single character to the right Keywords to Upper Case bsh Converts all keywords in the current buffer to upper case Mode Switcher bsh Displays a modal dialog with the current buffer s mode in a text field allowing one to change the mode by typing in its name ENTER selects the current mode if the text is not a valid mode the dialog still dismisses but a warning is logged to the activity log ESACPE closes the dialog with no further action TAB attempts to auto complete the mode name Pressing TAB repeatedly cycles through the possible completions SHIFT TAB cycles through the completions in reverse
187. tter see the section called Interface Overview for more information about the gutter The triangle points toward the line when the fold is collapsed and downward when the fold is expanded Clicking the triangle collapses and expands the fold To expand all sub folds as well hold down the Shift while clicking The first line of a collapsed fold is drawn with a background color that depends on the fold level and the number of lines in the fold is shown to the right of the line s text Folds can also be collapsed and expanded using menu item commands and keyboard shortcuts Folding Collapse Fold shortcut A BACK_SPACE collapses the fold containing the caret Folding gt Expand Fold One Level shortcut A ENTER expands the fold containing the caret Nested folds will remain collapsed and the caret will be positioned on the first nested fold if any Folding gt Expand Fold Fully shortcut AS ENTER expands the fold containing the caret also expanding any nested folds Folding Collapse All Folds shortcut C e c collapses all folds in the buffer Folding Expand All Folds shortcut C e x expands all folds in the buffer Navigating Around With Folds Folding gt Go to Parent Fold shortcut C e u moves the caret to the fold containing the one at the caret position Folding gt Go to Previous Fold shortcut A UP moves the caret to the fold immediately before the caret position Folding gt Go to Nex
188. two line numbers and selects all text between them Edit gt Text gt Delete Line shortcut C d deletes the current line Edit gt Text gt Delete to Start Of Line shortcut CS BACK_SPACE deletes all text from the start of the current line to the caret 4 Edit gt Text gt Delete to End Of Line shortcut CS DELE the current line E deletes all text from the caret to the end of Edit gt Text gt Join Lines shortcut C j removes any whitespace from the start of the next line and joins it with the current line The caret is moved to the position where the two lines were joined For example if you invoke Join Lines with the caret on the first line of the following Java code new Widget Foo createDefaultFoo It will be changed to new Widget Foo createDefaultFoo Working With Paragraphs As far as jEdit is concerned paragraphs are delimited by double newlines This is also how TeX defines a paragraph Note that jEdit doesn t parse HTML files for lt P gt tags nor does it support paragraphs delimited only by a leading indent C UP and C DOWN move the caret to the previous and next paragraph respectively Holding down Shift in addition to the above extends the selection a paragraph at a time Edit gt More Selection gt Select Paragraph shortcut C e p selects the paragraph containing the caret Edit gt Text gt Format Paragraph shortcut C e f splits and joins lines in the current selection to
189. uickNotepad extends JPanel implements EBComponent private String filename private String defaultFilename private View view private boolean floating private QuickNotepadTextArea textArea private QuickNotepadToolPanel toolPanel Constructor public QuickNotepad View view String position super new BorderLayout this view view this floating position equals DockableWindowManager FLOATING 123 Implementing a Simple Plugin this filename jEdit getProperty QuickNotepadPlugin OPTION_PREFIX filepath if this filename null this filename length 0 this filename new String jEdit getSettingsDirectory File separator gn txt Edit setProperty QuickNotepadPlugin OPTION_PREFIX filepath this filename Ld this defaultFilename new String this filename this toolPanel new QuickNotepadToolPanel this add BorderLayout NORTH this toolPanel if floating this setPreferredSize new Dimension 500 250 textArea new QuickNotepadTextArea textArea setFont QuickNotepadOptionPane makeFont textArea addKeyListener new KeyHandler textArea addAncestorListener new AncestorHandler JScrollPane pane new JScrollPane textArea add BorderLayout CENTER pane readFile Attribute methods for toolBar display public String getFilename return f
190. ve a three button mouse then either Alt click on Windows and Unix or Opt ion click on MacOS X The quick copy feature enables the following behavior 24 Editing Text Clicking the middle mouse button in the text area inserts the most recently selected text at the clicked location If you only have a two button mouse you can click the left mouse button while holding down A1t instead of middle clicking Dragging with the middle mouse button creates a selection without moving the caret As soon as the mouse button is released the selected text is inserted at the caret position and the selection is deactivated A message is shown in the status bar while text is being selected to remind you that this is not an ordinary selection Holding down Shift while clicking the middle mouse button will duplicate text between the caret and the clicked location Holding down Control while clicking the middle mouse button on a bracket will insert all text in that bracket s scope at the caret position The most recently selected text is stored in the register If jEdit is being run under Java 2 version 1 4 on Unix you will be able to transfer text with other X Windows applications using the quick copy feature On other platforms and Java versions the contents of the quick copy register are only accessible from within jEdit General Register Commands These commands require more keystrokes than the two methods shown above but they c
191. venience Java has a rich set of classes defined as part of the Java platform Like all Java applications jEdit is organized as a set of classes that are themselves derived from the Java platform s classes We will refer to Java classes and jEdit classes to make this distinction Some of jEdit s classes such as those dealing with regular expressions and XML are derived from or make use of classes in other open source Java packages Except for BeanShell itself we won t be discussing them in this guide In our one line script the static method Macros message has two parameters because that is the 85 Macro Basics way the method is defined in the Macros class You must specify both parameters when you call the function The first parameter view is a variable naming the current active View object Information about pre defined variables can be found in the section called Predefined Variables in BeanShell The second parameter which appears to be quoted text is a string literal a sequence of characters of fixed length and content Behind the scenes BeanShell and Java take this string literal and use it to create a St ring object Normally if you want to create an object in Java or BeanShell you must construct the object using the new keyword and a constructor method that is part of the object s class We ll show an example of that later However both Java and BeanShell let you use a string literal anytime a method s parameter
192. wards If Auto wrap is not selected a confirmation dialog box is shown before restarting the search Search gt Find Next shortcut C g locates the next occurrence of the most recent search string without displaying the search and replace dialog box Search gt Find Previous shortcut C h locates the previous occurrence of the most recent search string without displaying the search and replace dialog box Replacing Text The replace string text field of the search dialog remembers previously entered strings see Appendix C History Text Fields for details Clicking Replace amp Find will perform a replacement in the current selection and locate the next occurrence of the search string Clicking Replace All will replace all occurrences of the search string with the replacement string in the current search scope which is either the selection the current buffer or a set of buffers as specified in the search and replace dialog box Occurrences of the search string can be replaced with either a replacement string or the return value of a BeanShell script snippet Two radio buttons in the search and replace dialog box select between the two replacement modes which are described in detail below Text Replace If the Text button is selected the search string is simply replaced with the replacement string If regular expressions are enabled positional parameters 0 1 2 and so on can be used to insert the contents of matched sube
193. we assign a new GridLayout with the indicated parameters four rows one column zero spacing between columns a meaningless element of a grid with only one column but nevertheless a required parameter and spacing of six pixels between rows The spacing between rows spreads out the four grid elements After the components the panel and the layout are specified the components are added to 1eldPanel top to bottom one grid cell at a time Finally the complete ieldPanel is added to the dialog s content pane to occupy the Center section of the content pane 95 A Dialog Based Macro Create the Buttons add the buttons buttonPanel new JPanel button BoxLayout X AXIS ttonPanel setBorder new ttonPanel add Box createGlue ok new JButton OK cancel new JButton Ca ok setPreferredSize canc bu bu ncel EmptyBorder Panel setLayout new BoxLayout buttonPanel 12 50 0 50 rredSiz l getPref dialog button butto butto butto conte Panel add ok Panel add Box crea Panel add cancel Panel add Box crea t add buttonPanel teGlue South n n n n To create the dialog s buttons we follow repeat the teHorizonta 0 getRootPane setDefaultButton ok lStrut 60 nested container pattern we used in creating the text fields First we create a new nested panel This time we use a BoxLayout that places components either
194. which are optional SET the name of this ruleset All rulesets other than the first must have a name IGNORE CASE if set to FALSE matches will be case sensitive Otherwise case will not matter Default is TRUE e NO WORD SEP any non alphanumeric character not in this list is treated as a word separator for the purposes of syntax highlighting DEFAULT the token type for text which doesn t match any specific rule Default is NULL See the section called Token Types for a list of token types HIGHLIGHT DIGITS DIGIT RE see below for information about these two attributes Here is an example RULES tag RULES IGNORE CASE FALSE HIGHLIGHT DIGITS 2 TRUE parser rules go here RULES Highlighting Numbers If the HIGHLIGHT DIGITS attribute is set to TRUE jEdit will attempt to highlight numbers in this ruleset Any word consisting entirely of digits 0 9 will be highlighted with the DIGIT token type A word that contains other letters in addition to digits will be highlighted with the DIGIT token type only if it matches the regular expression specified in the DIGIT RE attribute If this attribute is not specified it will not be highlighted Here is an example DIGIT RE regular expression that highlights Java style numeric literals normal numbers hexadecimals prefixed with 0x numbers suffixed with various type indicators and floating point litera
195. which result from runtime exceptions thrown by the Java platform when macro code is executed Some exceptions thrown by the Java platform can often seem cryptic Nevertheless examining the contents of the activity log may reveals clues as to the cause of the error Using the Activity Log as a Tracing Tool Sometimes exception tracebacks will say what kind of error occurred but not where it arose in the script In those cases you can insert calls that log messages to the activity log in your macro If the logged messages appear when the macro is run it means that up to that point the macro is fine but if an exception is logged first it means the logging call is located after the cause of the error 108 Macro Tips and Techniques To write a message to the activity log use the following method of the Log class public static void log int urgency Object source Object message See the documentation for the Log class for information about the method s parameters The following code sends a typical debugging message to the activity log Log log Log DEBUG BeanShell class counter counter The corresponding activity log entry might read as follows debug BeanShell counter 15 Using message dialog boxes as a tracing tool If you would prefer not having to deal with the activity log you can use the Macros message method as a tracing tool Just insert calls like the following in the macro code Mac
196. x prefixLabel new JLabel Prefix to add suffixField new HistoryTextField macro add suffix suffixLabel new JLabel Suffix to add fieldPanel add prefixLabel fieldPanel add prefixField fieldPanel add suffixLabel fieldPanel add suffixField content add fieldPanel Center Next we shall create a smaller panel containing two fields for entering the prefix and suffix text and two labels identifying the input fields For the text fields we will use jEdit s HistoryTextField class It is derived from the Java Swing class JTextField This class offers the enhancement of a stored list of prior values used as text input When the component has input focus the up and down keys scroll through the prior values for the variable To create the HistoryTextField objects we use a constructor method that takes a single parameter the name of the tag under which history values will be stored Here we choose names that are not likely to conflict with existing jEdit history items The labels that accompany the text fields are JLabe1 objects from the Java Swing package The constructor we use for both labels takes the label text as a single String parameter We wish to arrange these four components from top to bottom one after the other To achieve that we use a JPanel container object named ieldPanel that will be nested inside the dialog s content pane that we have already created In the constructor for ieldPanel
197. xpressions in the replacement string see Appendix E Regular Expressions for more information If the search is case insensitive jEdit attempts to modify the case of the replacement string to match that of the particular instance of the search string being replaced For example searching for label and replacing it with text will perform the following replacements e String label would become String text e setLabel would become setText e DEFAULT LABEL would become DEFAULT_TEXT 27 Editing Text BeanShell Replace In BeanShell replacement mode the search string is replaced with the return value of a BeanShell snippet The following predefined variables can be referenced in the snippet e _0 the text to be replaced e _1 _ 9 if regular expressions are enabled these contain the values of matched subexpressions BeanShell syntax and features are covered in great detail in Part IIT Writing Macros but here are some examples To replace each occurrence of Windows with Linux and each occurrence of Linux with Windows search for the following regular expression Windows Linux Replacing it with the following BeanShell snippet _l equals Windows Linux Windows To convert all HTML tags to lower case search for the following regular expression lt S Replacing it with the following BeanShell snippet 0 toLowerCase To replace arithme
198. y notepad to buffer Next the plugin s menu is defined See the section called The QuickNotepadPlugin Class 120 Implementing a Simple Plugin application menu items quicknotepad menu label QuickNotepad quicknotepad menu quicknotepad quicknotepad choose file quicknotepad save file quicknotepad copy to buffer We have created a small toolbar as a component of QuickNotepad so file names for the button icons follow plugin toolbar buttons quicknotepad choose file icon Open png quicknotepad save file icon Save png quicknotepad copy to buffer icon Edit png The menu item labels corresponding to these icons will also serve as tooltip text Finally the properties file set forth the labels and settings used by the option pane Option pane labels options quicknotepad label QuickNotepad options quicknotepad file File options quicknotepad choose file Choos options quicknotepad choose file title Choose a notepad file options quicknotepad choose font Font options quicknotepad show filepath title Display notepad file path Q Q Q Q G Gee Gi oC AANA A A Q Initial default font settings options quicknotepad show filepath tru options quicknotepad font Monospaced K K Q Q options quicknotepad fontstyle 0 options quicknotepad fontsize 14 Q u u u u Q Setting not defined but supplied for completeness options quicknotepad filepath Upda
199. y to search in the current buffer without opening the search dialog box The search bar does not support replacement or multiple file search Previously entered strings can be recalled in the search bar with the Up and Down arrow keys see Appendix C History Text Fields By default the search bar remains hidden until one of the quick search commands described below is invoked however you can choose to have it always visible in the View pane of the Utilities gt Global Options dialog box see the section called The View Pane Search gt Incremental Search Bar shortcut C COMMA displays the search bar if necessary and gives it keyboard focus If this command is invoked while there is a selection the selection is placed in the search string field Search gt Incremental Search for Word shortcut A COMMA behaves like the above command except it places the word at the caret in the search string field Unless the HyperSearch check box is selected the search bar will perform an incremental search In incremental search mode the first occurrence of the search string is located in the current buffer as it is being typed Pressing ENTER and S ENTER searches for the next and previous occurrence respectively Once the desired occurrence has been located pressing ESCAPE returns keyboard focus to 29 Editing Text E will also the text area Unless the search bar is set to be always visible see above
Download Pdf Manuals
Related Search
Related Contents
Yarn Pet™ - Nancy`s Knit Knacks Case Logic 16" Lightweight Upright Roller FLP45-120/240GA Manuel technique Stiebel Eltron SHC 2.5 Installation Guide gestion et entretien Samsung CE108MDF-B User Manual OWNER MANUAL - Hardin Marine 取扱説明書(PDF: 0 MB) Bedienungsanleitung Operating Instructions Copyright © All rights reserved.
Failed to retrieve file