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
    39 Shirts &#8211; Leaving Mozilla

    In 2001 I had just graduated from a small town high school and headed off to a small town college. I found myself in the quaint computer lab where the substandard computers featured two browsers: Internet Explorer and Mozilla. It was this lab where I fell...

Incredible Demos

  • By
    Scroll IFRAMEs on iOS

    For the longest time, developers were frustrated by elements with overflow not being scrollable within the page of iOS Safari.  For my blog it was particularly frustrating because I display my demos in sandboxed IFRAMEs on top of the article itself, so as to not affect my site's...

  • By
    RealTime Stock Quotes with MooTools Request.Stocks and YQL

    It goes without saying but MooTools' inheritance pattern allows for creation of small, simple classes that possess immense power.  One example of that power is a class that inherits from Request, Request.JSON, and Request.JSONP:  Request.Stocks.  Created by Enrique Erne, this great MooTools class acts as...

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!