Jan 99 Tips
Volume Number: 15
Issue Number: 1
Column Tag: Tips & Tidbits
Jan 99 Tips
by Jeff Clites <online@mactech.com>
Autocompletion in MPW
One very useful feature of many Unix shells is that you only need to type the beginning
of a command, hit tab, and it fills in the complete command. I was really missing this
on MPW, especially with long command names such as UnobsoleteNameRevisions.
So here's a script that attempts to provide this feature in MPW, as well as possible.
Bind it to Command-Tab (or whatever you want), then type "nam", hit Command-Tab,
and watch it fill in "NameRevisions" for you.
Note: if nothing is selected, it will try to complete the last word on the current line. If
you want to complete a word in the middle of a line, you'll have to select it.
If ":" is in your {Commands} variable, it will also consider all files in the current
directory, as I have found no way to figure out whether a file is an MPW script or not.
Actually, this may even be useful.
# get the current selection
Set CurrentSelection "'Catenate "{Active}".§'
If "{CurrentSelection}" ==
# select the entire line we're on
Find !0 "{Active}
# put the insertion point at the beginning of this line
Find ”§:”§ "{Active}
# remember line number, so we can restore it later
Set CurrentLine 'Position -l "{Active}"'
# select the last word on this line
Find /[ [Missing image]/ "{Active}" || (Beep; Exit 0)
# if it isn't really on our current line, exit
If 'Position -l "{Active}"' != {CurrentLine}
Find {CurrentLine} "{Active}
Beep
Exit 0
End
Set CurrentSelection "'Catenate "{Active}".§'
# strip spaces from the end, if any
If "{CurrentSelection}" =~ /([
[Missing image]
/
Set CurrentSelection "{®1}
End
# can this happen at this point?
If "{CurrentSelection}" ==
Beep
Exit 0
End
End
# a list of matching command names
Set CommandList
# the number of matches found
Set Matches 0
# first see if it's one of the built-in commands
# (we really have to list them all here, sigh...)
For i In [Missing image]nu AddPane Adjust Alert Alias Align AuthorInfo [Missing image]Begin Break Browser Catenate CheckIn CheckOut [Missing image]OutDir Clear Close Confirm Continue Copy Cut Date [Missing image]e DeleteMenu DeleteNames DeletePane [Missing image]eRevisions Directory Duplicate [Missing image]cateN
SetKey Shift [Missing image]election ShowWindows Shutdown SizeWindow [Missing image]Windows Target TickCount TileWindows Unalias Undo [Missing image]ort UnlockNameRevisions Unmark Unmount [Missing image]ntProject UnobsoleteNameRevisions [Missing image]oleteProjectorFile Unset UnsetKey [Missing image]eProjectorDat
Evaluate Matches += 1
End
End
For Folder in 'Which'
# append all matching names to our list of command names
Evaluate Matches += 1
End
End
End
# no matching names found
# if more than one name was found, present a list
# to choose from
# if only one name was found, it has a space at the
# beginning; strip it. And remove any unnecessary
# quoting.
# replace the selection with the found (or chosen) name
stk@snafu.de