Work Efficiently with jEdit Macros

By  on  

As I've mentioned in the past, my text editor of choice is jEdit. jEdit is an all purpose text editor with numerous features that allow you to code more efficiently. One of those features is the jEdit macro. jEdit comes bundled with dozens of macros for editing Java, text files, and so on. You may also record your own macros. Here are a few macros I use to make writing my posts faster.

Macro: "Format Article"

SearchAndReplace.setSearchString("strong>");
SearchAndReplace.setReplaceString("h2>");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(false);
SearchAndReplace.setRegexp(false);
SearchAndReplace.setSearchFileSet(new CurrentBufferSet());
SearchAndReplace.replaceAll(view);
textArea.goToStartOfWhiteSpace(true);
SearchAndReplace.setSearchString("-- code --");
SearchAndReplace.setReplaceString("<pre class=\"\">-- code --</pre>");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(false);
SearchAndReplace.setRegexp(false);
SearchAndReplace.setSearchFileSet(new CurrentBufferSet());
SearchAndReplace.replaceAll(view);
Registers.copy(textArea,'$');
SearchAndReplace.setSearchString("-- view demo --");
SearchAndReplace.setReplaceString("<div class=\"actions\">\n<a href=\"https://davidwalsh.name/demo/zebra-class-2.php\" class=\"demo\">View Demo</a>\n<div class=\"clear\"></div>\n</div>");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(false);
SearchAndReplace.setRegexp(false);
SearchAndReplace.setSearchFileSet(new CurrentBufferSet());
SearchAndReplace.replaceAll(view);

Since I've disabled WordPress' auto_p function, I need to write a fair amount of each article's XHTML myself. Luckily I recorded a macro that:

  • replaces all <strong> tags with <h2> tags
  • replaces any "-- code --" string with a <pre> tag for syntax highlighting
  • replaces any "-- view demo --" string with a series of div tags that I use for each article's "View Demo" area

Macro: "HTML Entities"

SearchAndReplace.setSearchString("<");
SearchAndReplace.setReplaceString("&lt;");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(false);
SearchAndReplace.setRegexp(false);
SearchAndReplace.replace(view);
SearchAndReplace.setSearchString(">");
SearchAndReplace.setReplaceString("&gt;");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(false);
SearchAndReplace.setRegexp(false);
SearchAndReplace.replace(view);

This macro simply replaces ">" and "<" with their respective HTML entities.

Of course, the above macros are fairly simple but save me a ton of time doing redundant tasks. The power to create these utility macros is just another reason I love spending so much time in jEdit.

Recent Features

  • By
    Create a CSS Cube

    CSS cubes really showcase what CSS has become over the years, evolving from simple color and dimension directives to a language capable of creating deep, creative visuals.  Add animation and you've got something really neat.  Unfortunately each CSS cube tutorial I've read is a bit...

  • By
    CSS Gradients

    With CSS border-radius, I showed you how CSS can bridge the gap between design and development by adding rounded corners to elements.  CSS gradients are another step in that direction.  Now that CSS gradients are supported in Internet Explorer 8+, Firefox, Safari, and Chrome...

Incredible Demos

  • By
    MooTools&#8217; AutoCompleter Plugin

    One of the famous MooTools plugins is Harald Kirschner's AutoCompleter plugin. AutoCompleter takes a term input by the user and searches for matches -- an obviously help to the user. Here's how to make the most of Harald's great plugin. The XHTML All we...

  • By
    MooTools Documentation Search Favelet

    I'm going to share something with you that will blow your mind: I don't have the MooTools documentation memorized. I just don't. I visit the MooTools docs frequently to figure out the order of parameters of More classes and how best to use...

Discussion

  1. Macros, macro recording and the beanshell are big features that help you write stuff faster with jEdit. It’s neat to get an idea of all of how use use jEdit.

  2. Martin

    Hey,
    Do you get Mootools “Intellisense” in jEdit?
    /Martin

  3. @Martin: That is currently not available.

  4. The jedit forums are full of spam, so I thought I would try you. objective move s selcted file either from Nautilus or lets say the current buffer in JEDIT and copy it to a desitintion I want. Other macros lanugaues would let you do something like this
    cp %e smb:\\mypc\folder where %e is the current file / buffer. I skimmed the doc and could not find anything.

    tanks, gj (almost ready to abandon windows

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!