home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
fish
/
text
/
editors
/
uedit-stuff
/
abbrev
< prev
next >
Wrap
Text File
|
1991-01-10
|
10KB
|
208 lines
WORD ABBREV MODE FOR UEDIT
This here is a set of commands that implements what Emacs users call "word
abbrev mode". What it does is it looks at all the words you type in, and if
any of them is on its list of abbreviations, it replaces it with something
else that it's an abbreviation for. For instance, you can set it up so that
whenever you type the word "gork", it automatically turns into "Good Old
Raisins and Kumquats" as soon as you press the space bar or a punctuation
character. This is useful to save typing. It is especially useful when
programming in Modula-2, to ease the burden of typing stuff like
"IMPLEMENTATION MODULE" over and over. It can also be used to automatically
capitalize standard identifiers when you type them in lowercase. The
commands are:
A-x: Turns the abbreviation expander on or off.
SA-x: Add an abbreviation (and what it expands to) to the list.
SAC-x: Remove an abbreviation from the list.
L-x: Load a set of word abbreviations from a file.
R-x: Save the word abbreviation list in a file.
The command lAmiga-x which loads the list from a file prompts you to tell it
whether to add the file to the existing list or to replace the old list with
the file. The rAmiga-x command prompts for a file name. SAC-x asks for the
abbreviation and removes it and its expanded form, or says "Not found" if
what you typed isn't on the list. SA-x prompts first for the abbreviation
and then for what it expands to. A-x tells you whether it turned it on or
off. If your abbreviations include normal words, as is often the case when
writing in Modula-2 (like, if you want "then" to automatically capitalize),
you will probably end up switching it on and off frequently (like, to type a
string or comment with "then" in it). Maybe someday I'll get it to be able
to tell when it's in a string or comment.
To see the list, examine buffer 79. If you are using buf79 for something
else in your config, you'll have to replace all instances of "buf79" in these
commands with something else. The format of the file saved by R-x is simple:
each line consists of the expanded string followed by a colon followed by the
abbreviation. The variable n48 is used to tell whether it's on; this
likewise needs to be changed if you're already using it. Also check for
conflicts with the choice of keys I've made.
THE ABBREVIATION MUST CONSIST ONLY OF LETTERS with no digits or punctuation
characters or whitespace in order to work. The abbreviation is case
sensitive if you have Search Caps set. The text that replaces the
abbreviation gets word-wrapped and so on just as if you had typed it.
I put off writing this for a long time because I expected it to have a
substantial cost in the performance of Uedit. Fortunately, I was overly
pessimistic. But some slight slowdown of typein is noticeable.
IF YOU ARE USING A PREKEY, you need to add one line to it to make Word Abbrev
Mode work: runKey(virtual-=). Put it at the beginning, in most cases. In
any case, put it where it can hear all the stuff actually typed in by the
user. If you are not using a preKey yet, then you have to use this one:
Operate the Word Abbrev Mode engine
<preKey: runKey(virtual-=) >
Here is an example of combining word abbrev mode with an existing preKey.
The preKey given here is similar to the one I use, as seen in the file Indent:
Record recent inputs in n10..n18, and do Word Abbrev mode
.. <prekey:
equatenum(n32, 0) .. for my combined idle save and auto traffic
runkey(virtual-=) .. word abbrev mode engine
if (eqnum(macronum, normal-buttondown)) return .. forget mouseclicks
if (eqnum(macronum, normal-buttonup)) return .. ditto
.. if (not eqnum(inputchar, 0)) return .. optionally forget text
if (genum(11, n10)) equatenum(n10, 18) .. RANGE
else decnum(n10) .. (actually I use n10..n26 nowadays)
equatenum(n[n10], macronum)
>
NOTE that the version given here uses userGlobalA as a flag to tell whether
the mode is active or not. If you would rather use something else, such as
userGlobalB or an n-variable (no checked menu in that case) or something
local to each buffer such as the favorite flag, change the references to
userGlobalA in the first line of the virtual-= command, and in alt-x.
NOW HERE ARE THE COMMANDS:
Expand the last word typed in if found in buf79 to unabbreviated form
<virtual-=: if (eqnum(userGlobalA, 0)) return .. is mode active?
if (eqnum(inputchar, 16)) return .. delete
... WHY THE HECK does the delete key produce inputchar value 16?!?
if (eqnum(inputchar, 8)) return .. backspace
if (eqnum(inputchar, 0)) { .. non-typein, abandon word
equatenum(n47, 0)
return
}
equatenum(n5, inputchar)
.... if (genum("9", n5)) .. if allow digits in abbrev
.... add(n5, n5, 17)
if (genum(n5, "a"))
sub(n5, n5, 32)
if (gtnum(n5, "Z"))
equatenum(n5, 0)
if (genum(n5, "A")) { .. true if alphanumeric
equatenum(n47, 1)
return
}
if (eqnum(n47, 0)) return
.. if we get to this point, then we have a finished word to check.
getsearch(buf49)
freebuf(buf50)
equateloc(curfile, mouseloc, locb) .. could use swapLoc?
equateloc(curfile, locb, atcursor)
movecursor(curfile, sword)
equateloc(curfile, loca, atcursor)
insertrgn(buf50, sfile, curfile, loc)
movecursor(buf50, sfile)
insertchar(buf50, ":") .. use colon as divider
movecursor(buf50, efile)
insertchar(buf50, eline)
setsearch(buf50)
movecursor(buf79, sfile)
if (search(buf79, shilite, ehilite, 1)) {
equateloc(buf79, einvert, atcursor)
movecursor(buf79, sline)
equateloc(buf79, sinvert, atcursor)
clearrgn(curfile, loc)
.. insertrgn(curfile, atcursor, buf79, invert) .. crude
equateloc(buf79, atcursor, sinvert)
while (gtloc(buf79, einvert, atcursor)) {
copychar(buf79, n54)
typechar(n54)
incloc(buf79, atcursor)
}
} else
equateloc(curfile, atcursor, locb)
equateloc(curfile, locb, mouseloc)
setsearch(buf49)
equatenum(n47, 0)
>
Toggle activation of word-abbrev mode
<alt-x: if (eqnum(userGlobalA, 0)) {
equatenum(userGlobalA, 1)
putmsg("Turning ON Word-Abbrev Mode")
} else {
equatenum(userGlobalA, 0)
putmsg("turning off word-abbrev")
} >
Add an abbreviation to the word-abbrev list
<shftalt-x: putmsg("Word to be expanded?")
freebuf(buf51)
if (inputstring(buf51)) {
putmsg("What should it expand to?")
freebuf(buf50)
if (inputstring(buf50)) {
movecursor(buf79, sfile)
insertchar(buf79, eline)
insertrgn(buf79, sfile, buf51, all)
movecursor(buf79, sfile)
insertchar(buf79, ":") .. use colon for divider
insertrgn(buf79, sfile, buf50, all)
}
}
>
Remove an abbreviation from the word-abbrev list
<shftaltctl-x: putmsg("Abbreviation to remove?")
freebuf(buf51)
if (inputstring(buf51)) {
movecursor(buf51, efile)
insertchar(buf51, eline)
getsearch(buf49)
setsearch(buf51)
movecursor(buf79, sfile)
if (search(buf79, shilite, ehilite, 1)) {
movecursor(buf79, sline)
clearrgn(buf79, line)
clearchar(buf79)
putmsg("Removed.")
} else putmsg("Not found.")
}
>
Load a word-abbrev list from a file
<lamiga-x: putmsg("File to load into the word-abbrev list?")
freebuf(buf52)
if (inputstring(buf52)) {
if (askyesno("Remove existing abbrevs first?"))
freebuf(buf79)
if (not insertfile(buf79, sfile, buf52))
putmsg("Couldn't open file.")
}
>
Save the word-abbrev list in a file
<ramiga-x: putmsg("File to save the word-abbrev list in?")
freebuf(buf52)
if (inputstring(buf52)) {
setfilename(buf79, buf52)
if (not savefile(buf79))
putmsg("Save failed!") .. unlikely even if it does fail
}
>
Word Abbrev Mode for Uedit is by Paul Kienitz,
6430 San Pablo ave.
Oakland, CA 94608
and is in the public domain.