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
    CSS Filters

    CSS filter support recently landed within WebKit nightlies. CSS filters provide a method for modifying the rendering of a basic DOM element, image, or video. CSS filters allow for blurring, warping, and modifying the color intensity of elements. Let's have...

  • By
    Vibration API

    Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user.  One of those simple APIs the Vibration API.  The Vibration API allows developers to direct the device, using JavaScript, to vibrate in...

Incredible Demos

  • By
    FileReader API

    As broadband speed continues to get faster, the web continues to be more media-centric.  Sometimes that can be good (Netflix, other streaming services), sometimes that can be bad (wanting to read a news article but it has an accompanying useless video with it).  And every social service does...

  • By
    Introducing MooTools HeatMap

    It's often interesting to think about where on a given element, whether it be the page, an image, or a static DIV, your users are clicking.  With that curiosity in mind, I've created HeatMap: a MooTools class that allows you to detect, load, save, and...

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!