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
    7 Essential JavaScript Functions

    I remember the early days of JavaScript where you needed a simple function for just about everything because the browser vendors implemented features differently, and not just edge features, basic features, like addEventListener and attachEvent.  Times have changed but there are still a few functions each developer should...

  • By
    Facebook Open Graph META Tags

    It's no secret that Facebook has become a major traffic driver for all types of websites.  Nowadays even large corporations steer consumers toward their Facebook pages instead of the corporate websites directly.  And of course there are Facebook "Like" and "Recommend" widgets on every website.  One...

Incredible Demos

  • By
    Image Reflection with jQuery and MooTools

    One subtle detail that can make a big difference on any web design is the use of image reflections. Using them too often can become obnoxious but using reflections on large, "masthead" images is a classy enhancement. Unfortunately creating image reflections within your...

  • By
    CSS Ellipsis Beginning of String

    I was incredibly happy when CSS text-overflow: ellipsis (married with fixed width and overflow: hidden was introduced to the CSS spec and browsers; the feature allowed us to stop trying to marry JavaScript width calculation with string width calculation and truncation.  CSS ellipsis was also very friendly to...

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!