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

Incredible Demos

  • By
    dat.gui:  Exceptional JavaScript Interface Controller

    We all love trusted JavaScript frameworks like MooTools, jQuery, and Dojo, but there's a big push toward using focused micro-frameworks for smaller purposes. Of course, there are positives and negatives to using them.  Positives include smaller JS footprint (especially good for mobile) and less cruft, negatives...

  • By
    9 Mind-Blowing Canvas Demos

    The <canvas> element has been a revelation for the visual experts among our ranks.  Canvas provides the means for incredible and efficient animations with the added bonus of no Flash; these developers can flash their awesome JavaScript skills instead.  Here are nine unbelievable canvas demos that...

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!