InputReplace Plugin for jEdit

 

 

1. Overview

2. Download

3. Defining the Replacement Table and User Functions

3.1. Replacement Table

3.2. User Functions

3.3. Reloading

4. Plugin Operation

 

 

   1.  Overview

The InputReplace plugin provides a facility for expanding input character sequences into replacement text, similar to abbreviations but without the requirement of expanding a whole word at a time. It is useful for inserting characters not found in your keyboard layout, such as turning e' into é or c/ into ¢.

The primary advantage over jEdit's built-in abbreviations is that these replacements can be used within words, rather than just with whole words.

This allows you to define, say, a single replacement e' → é and use it to quickly enter both café and débutante. To enter café, you would type cafe' and activate "Input Replace at Caret" after the whole word; to enter débutante, you would type de', activate "Input Replace at Caret", and then finish typing the word.

You can, of course, define whole words as input and replacement text, as with abbreviations (though without any positional parameters).

I recommend binding "Input Replace at Caret" to an easy key-combination, since you'll need to activate it often, if you write a lot of accented text.

One can also define BeanShell functions to perform more complicated replacements, for instance turning characters into codepoints and vice-versa:

  "(É)U-"    → "0xC9"
  "(0xC9)U+" → "É"

or converting numbers to and from hex:

  "(5314)0x"    → 0x14c2
  "(0xBE415)0x" → 779285

Such things can accomplished with other plugins or macros, but using the InputReplace framework to write custom transformations lets you assign simple names to those transformations—like "U+" and "0x" above—and also write the BeanShell code without dealing with the jEdit API (each transformation is a simple String→String function).

 

   2.  Download

The easiest way to get the InputReplace plugin is to use jEdit's Plugin Manager (once the plugin is released). You can also manually download the jar for this plugin from:

             [Download JAR from GitHub]

 

   3.  Defining the Replacement Table and User Functions

When you first install the plugin, a default replacement table will be set up, as well as a few BeanShell functions that you can use in your replacements. The table and user functions can be edited by the "Edit Replacement Table" and "Edit User Functions" actions in the Plugins menu.

 

 3.1.  Replacement Table

The format of the replacement table is given in the table text file itself, but is copied here for reference:

# This file maps input strings to character compositions, like a simple

# input method. Only non-whitespace characters may be used for the input

# string (the replacement text may contain whitespace). The format of the

# table is a series of lines, where the input strings appear at the start

# of each line, followed by whitespace, and then the output string. Lines

# that are JUST a hash mark, or that begin with a hash AND a space, are

# comments (since abbreviations are at minimum two characters long, this

# doesn't affect the table at all). Lines that are all whitespace are

# ignored.

#

# Instead of a replacement string, you can use a special notation,

# U+HHHH or U+10HHHH to represent a Unicode character expressed in hex.

#

# You can also use a special form as the replacement string, which is

#      (<function name>)FUNC

# which will use BeanShell to evaluation <function name>, passing in as

# an argument the text in the document contained between '(' and ')'.

# Actually, the parentheses can be any characters, and the document text

# will be scanned to find the opening and closing delimeters. Example:

#   FB    |foobar|FUNC

# will match the document form |analyze|FB, and call foobar("analyze")

 

Looking at the default replacement table will give you a good idea of its use: [View on GitHub]

 

 3.2.  User Functions

The BeanShell script installed with the plugin provides examples of how your own functions would be structured: each function takes one parameter, a String representing the input, and returns a transformed String. You then reference it in the replacement table using the "(<function name>)FUNC" syntax.

The default user function script can be seen here: [View on GitHub]

 

 3.3.  Reloading

When you change the replacement table or user-function script, you'll need to use the "Reload Table and Functions" action to have the plugin load your changes.

 

   4.  Plugin Operation

The way that the "Input Replace at Caret" action works is primarily what differentiates this plugin from abbreviations. Instead of examining the previous word, it operates on non-whitespace characters in this fashion:

   1.  Set the point to max-length characters before the caret. max-length is settable in Plugin Options, and defaults to 8.

   2.  Check if the text between the point and the caret has an entry in the replacement table; if so, perform the replacement and we're done.

   3.  Otherwise, if there are still more than 2 characters between the point and caret, advance the point one character and try again. (The minimum length of a replacement entry is 2 characters)

 

 

Jesse Pavel
jpavel@alum.mit.edu
September, 2018