home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Beijing Paradise BBS Backup
/
PARADISE.ISO
/
software
/
BBSDOORW
/
AUROR21A.ZIP
/
TEMPLATE.AML
< prev
next >
Wrap
Text File
|
1995-09-01
|
5KB
|
186 lines
/* ------------------------------------------------------------------ */
/* Macro: TEMPLATE.AML */
/* Written by: nuText Systems */
/* */
/* Description: This macro adds a 'Template Editing' capability to */
/* Aurora which is based on the extension of the file */
/* you are editing. Template editing allows you include */
/* commonly-used blocks of code or text (called */
/* 'templates') with just a few keystrokes. */
/* */
/* Note: This macro requires the data file TEMPLATE.DAT, */
/* which contains user-modifiable templates. */
/* See TEMPLATE.DAT for further instructions. */
/* */
/* Usage: Select this macro from the Macro List (on the Macro */
/* menu), or run it from the macro picklist <shift f12> */
/* ------------------------------------------------------------------ */
include bootpath "define.aml"
// check for a previous install
obj = lookup "templobj" "prf"
if obj then
if (okbox "TEMPLATE.AML is already installed. Remove it?") == 'Ok' then
destroyobject obj
unsetx "templobj" "prf"
msgbox "TEMPLATE.DAT removed."
end
return
else
setxobj "templobj" (getcurrobj) "prf"
end
// keep this object resident
stayresident
// template expansion only in edit windows
object edit
// template data file name
templatefile = getbootpath + "MACRO\\TEMPLATE.DAT"
// template expansion key
// (change this key definition to suit your own preferences)
key <ctrl f3>
// get the template keyword and start column
pushcursor
if find _CSet "~lr" then
right
else
col 1
end
startcol = getcol
word = getword
popcursor
// if no template keyword is found, then return
if not word then
display
say "No template keyword" 'b'
return
end
// get the current buffer id
buffer = getcurrbuf
// build the template key
tempkey = "^{" + word + '[.a-zA-Z]*' + (locase (getext (getbufname))) +
"}|{" + word + ".$} |$"
undobegin
// load the template file
if loadbuf templatefile then
// look for the template key
if find tempkey 'xi*' then
// look for explicitly specified number of lines, if any
length = find '[0-9]#' 'xl'
if length then
lines = gettext (getcol) length
// no explicit lines specified -- look for the next blank line
else
top = getrow
pushcursor
if find '^$' 'x' then
lines = getrow - top - 1
else
lines = getlines - top
end
popcursor
end
// delete the original word in the text
delchar (sizeof word) startcol '' buffer
oldmark = usemark 'T'
// insert the first template line horizontally
down
markcolumn 1 (getlinelen)
copyblock 'T' buffer startcol
// insert the following lines vertically, and shift right if needed
if lines > 1 then
down
markline '' getrow + lines - 2
copyblock 'T' buffer
if startcol > 1 then
shiftblock startcol - 1
end
end
// destroy the template buffer
destroybuf
//gotobuf buffer
markline (getrow) getrow + lines - 1
// expand embedded macro expressions, if any
pushcursor
loop
length = find "\\\\\\{.+\\}" "xb*"
if not length
break
end
// get the macro expression
begcolumn = getcol
expression = gettext begcolumn + 2 length - 3
// delete the expression in the copied text
delchar length
// evaluate the expression
value = eval expression
// (expression may have changed the current buffer)
gotobuf buffer
// insert the value of the expression into the text
// or indicate a compilation error
error = geterror 'c'
if error then
errorstr = "Template expression error: " + (errormsg error)
break
else
instext value
right (sizeof value)
end
end
popcursor
// move to the cursor position specified in the template (if any)
replace "\\c" ' ' "gbi*"
destroymark
usemark oldmark
else
errorstr = "Template '" + word + "' not found"
destroybuf
end
else
errorstr = "Can't open " + templatefile
end
undoend
// display any error messages
if errorstr then
display
say errorstr 'b'
end
end
// installation message
if (okbox "TEMPLATE.AML is now installed.\nOpen " +
templatefile + " for further instructions?") == 'Ok' then
queue "open" templatefile
end