This document explains how to use abbreviations with JED.

Overview ========

Abbreviations are possible only when `abbrev' mode is enabled. It can be toggled on and off on a buffer by buffer basis using the `abbrev_mode' command. If it is on, the word `abbrev' will appear on the status line.

Each buffer can have its own abbreviation table or use the ``Global'' abbreviation table. If a table has not been defined for a given buffer, the ``Global'' table will be used. Typically, abbreviation tables are mode dependent and are usually assigned to the buffer when a mode is selected.

An abbreviation table consists of abbreviations as well as a definition of characters that are allowed to appear in an abbreviation. By default, the characters that comprise a word are used. However, this is not always what is desired. For example, one might like to use abbreviations like `' for `

'inTeXmode.Forthistohappen, thecharactershouldbeincludedinthedefinitionofaword.Theexamplesbelowshouldshedmorelightonthisconcept.

UsingAbbreviations = = = = = = = = = = = = = = = = = = =

Onceabbreviationshavebeenloadedintotheeditor(themechanismisexplainedbelow), theycanbeusedonlyifabbrevmodeisturnedon.Thismodecanbeturnedonoroffbypressing`ESCX'andentering`abbrevmode'attheprompt.Itcanalsobeturnedoninamodehook.

Afterenteringanabbreviationintothebuffer, theabbreviationwillbeexpandedifthenextcharacterinsertedintothebufferimmediatelyafterthepositionoftheabbreviationisNOTamemberofthesetofcharactersthatisallowedinanabbreviation.ThentheeditorscansbackwardacrossthetextuntilitfindsacharacterthatisNOTpartofthesetofspecialcharacters.Finallyitattemptstoexpandtheresultingabbreviation.

Forexample, consideranabbreviationforTeXmodeandassumethat, whentheabbreviationtablewascreated, thecharacters`,́`a - z',`A - Z', and`0 - 9'werespecifiedasthespecialsetofcharactersthatmaybeusedinanabbreviation.Thismeansthat`$\displaystyle \be{^\prime}$isavalidabbreviationbut`@be'isnotsince`@'isnotpartoftheaboveset.Supposethat`$\displaystyle \be{^\prime}$istheabbreviationfor`

(2)
'and`$\displaystyle \be{^\prime}$isenteredonalineas

Thisisanequation.$\displaystyle \be$

Atthispointnothinghappens.However, ifaSPACEisinserted, theeditorwillrealizethatthespaceisnotpartofthespecialabbreviationcharactersetandscanbackuntilanothercharacterNOTinthesetisfound.Inthiscase, itwillfinda`.'.Fromthisinformation, itlooksup`$\displaystyle \be{^\prime}$inthetable, finds`

(3)
'andexpandsthelinetolooklike :

Thisisanequation.

(4)

However, ifthelinehadlookedlike :

Thisisanequation$\displaystyle \be$

theexpansionwouldhavefailedbecausetheeditorwouldhavescannedbacktothespacecharacterbetween`an'and`equation'andtriedtoexpand`equation$\displaystyle \be{^\prime}$.

Althoughthissoundscomplex, itistrivialinpractice.

TheAbbreviationFile = = = = = = = = = = = = = = = = = = = = = =

AnabbreviationfileissimplyafilethatcontainstheapproriteS - Langfunctioncallstocreateabbreviationtablesandassignabbreviationstothetables.ItisloadedlikeanyotherS - Langfile, via`evalfile'.Simplyturningabbreviationsonvia`abbrevmode'issufficienttocauseJEDtoloadthefile.

Thevariable`AbbrevFile'maybeusedtospecifythenameoftheabbreviationfile.Ifthisvariableisundefined, thefilenamedefaultsto`abbrevs.sl'onnon - Unixsystemsand`.abbrevs.sl'onUnix.ItisassumedtoresideintheHOMEdirectory.Tospecifyadifferentname, e.g.,`/usr/lib/jed /abbrev.sl', put

variableAbbrevFile = "/usr/lib/jed /abbrev.sl";

intheJEDstartupfile.

HereisasimplefilethatissufficienttocreateaglobalabbreviationtableandalocaltableforTeXmode :

createabbrevtable("Global","");defineabbrev("Global","adn","and");defineabbrev("Global","amy","amy.tch.harvard.edu");

createabbrevtable("TeX","
A - Za - z0 - 9");defineabbrev("TeX","
be","
beginequation");defineabbrev("TeX","
ee","
endequation");

Notethat`createabbrevtable'takes2parameters.Thefirstparameterissimplythenameofthetabletobecreatedandthesecondparameterrepresentsthelistofcharactersthatareallowedtobeinanabbreviation.Ifthesecondparameteristheemptystring, JED'sworddefinitionwillbeused.AlsonotethatthebackslashcharactermustbetypedtwiceforS - Langtointerpretitproperlyasabackslashcharacter.

The`defineabbrev'functiontakes3parameters : thenameofthetable, theabbreviation, andtheexpansionfortheabbreviation.

Thereisreallynothingspecialaboutanabbreviationfile.ThecodethatappearsinitcanalsoappearintheJEDstartupfile.

Usuallytheabbreviationmodeisenabledinahook.Forexample, toenableabbreviationsforTeXmode, useamodehookoftheform :

definetexmodehook()setabbrevmode(1);

Thisway, whenTeXmodeisenabled, theabbreviationfilewillbeautomaticallyloadedifnotalreadyloadedandabbrevmodewillbeturnedon.

CreatingAbbreviations = = = = = = = = = = = = = = = = = = = = = =

Therearetwowaystocreateabbreviations :

1.Simplycreateanabbreviationfilebyhand.2.Usethe`defineabbreviation'functioncall.

Herethelattermethodisexplained.

The`defineabbreviation'functionusestheabbreviationtableassociatedwiththecurrentbuffer.Ifthereisnoneexplicitlyassociatedwiththebuffer, theGlobaltablewillbeused.Ifthetabledoesnotexist, itwillbecreated.Thisfunctionwillpromptforanabbreviation.Itmayormaynotpromptforanexpansion.Ifaregionisdefinedwhen`defineabbreviation'iscalled, theregionwillbetakenastheexpansion.Thisisusefuliftheexpansionconsistsofofmorethanoneword.Ifaregionisnotdefined, theexpansionwillconsistofthepreviouswordasdefinedbythetable.Onlyifthatfailswilltheuserbepromptedforanexpansion, e.g., thiscouldhappenifthePointisatthebeginningofaline.

Notethatsimplyusing`defineabbreviation'byitselfdoesnotsavetheabbreviationforfutureuse.Tosavetheabbreviationstotheabbreviationfile, usethefunction`saveabbrevs'.Thatis, press`ESCX'andenter`saveabbrevs'attheprompt.Theeditorwillthenpromptforafilename.SimplyhittingRETURNatthepromptmeansthatthe`AbbrevFile'definitionwillbeused.Enteradifferentfilenametosavethemelsewhere.Notethatenteringanewfilenamewillnotchangethevalueof`AbbrevFile'.Also, thisfunctionsavesALLcurrentlydefinedabbreviationtables.

(1)