# 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.

## C/C++ macros

These macros are useful for C/C++ programming.

- `Include_Guard.bsh`

  Inserts conditional preprocessor directives around a header file, to prevent it from being included multiple times.

  The name of the generated preprocessor macro is based on the buffer's name.

- `Toggle_Header_Source`

  Toggles between the header and the implementation file. Works for .c, .cxx, and .cpp extensions.

## 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_or_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> 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> 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.

- `Paste_Indent.bsh`

  Pastes the content of the clipboard and indents it.

## Editing Macros

These macros automate various text editing tasks.

- `Duplicate_Lines_Above.bsh`

  Duplicates current/selected line(s) upward.

- `Duplicate_Lines_Below.bsh`

  Duplicates current/selected line(s) downward.

- `Emacs_Ctrl-K.bsh`

  Cuts and appends text, from the cursor to the end of the line, into the copy buffer.

- `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`

  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 stop, if all characters between the caret and the tab stop are spaces. In all other cases a single character is removed.

- `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.

- `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.

- `Open_Line_Above.bsh`

  Adds a new blank line before the current/selected line(s).

- `Open_Line_Below.bsh`

  Adds a new blank line after the current/selected line(s).

- `Toggle_Fold.bsh`

  Toggles visibility of current fold.

  This is especially useful for fold toggling via keyboard.

## File Management Macros

These macros automate the opening and closing of files.

- `Browse_Buffer_Directory.bsh`

  Opens a the current buffer's directory in the file system browser.

- `Browse_Directory.bsh`

  Opens a directory supplied by the user in the file system browser.

- `Buffer_Switcher.bsh`

  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.

- `Duplicate_Buffer.bsh`

  Duplicates the current buffer into a new one.

- `Delete_Current.bsh`

  Deletes the current buffer's file on disk, but doesn't close the buffer.

- `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 supplied by the user in an input dialog.

- `Open_Selection.bsh`

  Opens the file named by the current buffer's selected text.

- `Send_Buffer_To_Next_Split.bsh`

  If bufferset scope is set to EditPane, the current buffer is added to the next Editpane's bufferset.

- `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.

- `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.

- `Reset_TextArea.bsh`

  Performs a split and an unsplit of the current TextArea. Useful for those occasions when your textarea is corrupt (painting the incorrect characters on the screen).

- `Splitpane_Grow.bsh`

  When inside a split EditPane, this macro moves the splitter away from the cursor, effectively increasing the size of the currently active split pane.

- `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 compares 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`

  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`

  Creates `getXXX()` or `setXXX()` 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 `getXXX()` or `setXXX()` 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 commented text) definitions of `getXXX()` or `setXXX()` 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.

- `Buffer_to_HyperSearch_Results.bsh`

  Reads HyperSearch results from a buffer that was previously created by the HyperSearch_Results_to_Buffer macro and possibly filtered manually, and imports them into the HyperSearch Results dockable.

- `Debug_BufferSets.bsh`

  Display int and hex values for the character at the caret, in the status bar.

- `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 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`

  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.

  This buffer can be re-imported to the HyperSearch Results dockable by the Buffer_to_HyperSearch_Results macro.

- `Make_Bug_Report.bsh`

  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.

- `Create_Plugin_Announcement.bsh`

  Creates an announcement for the Plugin Central Submission Tracker based on the plugins *.props and description.html files.

- `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.

- `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 Macros

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 #.

- `Compose_Tag.bsh`

  The selection is taken as tag name and replaced with a full xml tag.

- `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.

- `Line_Filter.bsh`

  Filters lines of the current buffer due to a provided regular expression. The resulting set of lines can be either removed from the buffer or written to a new buffer.

  The filter works on a multiline selection (if there is one) otherwise on the whole buffer. The resulting set of lines includes those lines that either match or not match the regular expression.

- `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()` as a means of obtaining user input. See .

- `Reverse_Lines.bsh`

  Reverses the selected lines or the entire buffer if no lines are selected. Does not support Rectangular Selections.

- `Single_Space_Buffer.bsh`

  Removes every second line, if they are all blank.