home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 1
/
GoldFishApril1994_CD2.img
/
d4xx
/
d429
/
uedit-stuff
/
indent
< prev
next >
Wrap
Text File
|
1991-01-10
|
18KB
|
474 lines
++++++++++++++++++++++++++++
*** Indent-related Uedit functions by Paul Kienitz
++++++++++++++++++++++++++++
Move cursor to first non-whitespace on current line
.. Ue 2.4 version: <ctl-[:
if (not is(curfile, sline)) movecursor(curfile, sline)
label (2)
if (not is(curfile, space))
if (not is(curfile, 9)) ..tab
goto label (1)
movecursor(curfile, echar)
goto label (2)
label (1)
loctocol(curfile, n50, atcursor)
> reports column in n50
Move cursor to first non-whitespace on current line
<ctl-[: if (not is(curfile, sline))
movecursor(curfile, sline)
while (is(curfile, space) | is(curfile, 9))
movecursor(curfile, echar)
loctocol(curfile, n50, atcursor)
> reports column in n50
Indent with alt-] if cursor in leading whitespace, else insert tab
<normal-tab: equateloc(curfile, locA, atcursor)
label (37)
if (is(curfile, sline))
goto label (21)
else movecursor(curfile, schar)
if (not is(curfile, whitespace))
goto label (96)
goto label (37)
label (96) .. we are in the line's text, just insert tab
equateloc(curfile, atcursor, locA)
typechar(9)
return
label (21) .. we are in the leading indent, run alt-]
runkey(alt-])
>
When using this version of normal-tab, I like to define shft-tab to simply
insert two tab characters, just cause that might take four presses of normal-
tab when using this ... just <shft-tab: typechar(9) typechar(9) >
Un-indent with alt-[ if in leading whitespace, else delete last char
..<normal-bs: if (is(curfile, sline)) {
if (eqloc(curfile, atcursor, spage))
vscroll(atcursor) .. bug workaround
if (movecursor(curfile, schar))
clearchar(curfile)
return
}
equateloc(curfile, locA, atcursor)
while (movecursor(curfile, schar)) {
if (not is(curfile, whitespace)) { .. we're in mid-line
movecursor(curfile, locA)
movecursor(curfile, schar)
clearchar(curfile)
return
}
if (is(curfile, sline)) { .. we are in the leading indent
runkey(alt-[)
return
}
}
> Grrrr. This is too slow to use, unless you use the UEK version.
And it should single-backspace sometimes?
Set indent size for alt-] and alt-[
<shftAlt-]: putmsg(
"How many spaces should alt-] indent? (1 to 9, or 0 means 10)")
getchar(n54)
sub(n54, n54, "0")
if (gtnum(n54, 9)) goto label (1)
if (gtnum(0, n54)) goto label (1)
if (eqnum(0, n54)) equatenum(n54, 10) .. 0 means 10
.. instead: putmsg("How many lines should alt-] indent?")
.. if (not inputNum(n54)) goto label (1)
equatenum(n44, n54)
putmsg(" ")
return
label (1)
putmsg("Not a number")
>
Un-indent line according to indentation of lines above
<lamiga-[:
equateloc(curfile, locA, atcursor)
runkey(ctl-[)
..if (eqnum(n50, 1)) { equateloc(curfile, atcursor, locA) return }
equatenum(n51, n50)
do (n52, 1, 6) { .. <- set limit of how many lines to look at here
if (not movecursor(curfile, upline))
goto label (57)
runkey(ctl-[) .. find indent level of near previous line
if (gtnum(n51, n50)) .. aha, this is less indented than us
if (gtnum(n50, 1)) { .. but not completely unindented
equatenum(n54, n50) .. so this is the indent
goto label (69) .. to use for our line
}
}
label (57) .. vvv default value @@
if (genum(0, n44)) equatenum(n44, 4) .. no guidance from above
if (gtnum(n51, n44)) sub(n54, n51, n44) .. lines, so mimic alt-[
else equatenum(n54, 1)
label (69)
movecursor(curfile, locA) .. get cursor back to original line
runkey(virtual-[)
>
**** THIS NEEDS something to make normal-tab and normal-bs work primitively
in the case where indentation matches the tab table (e.g. 8 spaces 0 lines).
Indent line to align after next whitespace in line above
<lamiga-]: equateloc(curfile, locA, atcursor)
runkey(ctl-[)
equatenum(n51, n50)
if (not movecursor(curfile, upline))
goto label (42)
while (is(curfile, blankline))
if (not movecursor(curfile, upline))
goto label (42)
runkey(ctl-[)
while (genum(n51, n50) & not is(curfile, eline)) {
while (not is(curfile, whitespace))
movecursor(curfile, echar)
while (not is(curfile, eline) & is(curfile, whitespace))
movecursor(curfile, echar)
loctocol(curfile, n50, atcursor)
}
movecursor(curfile, locA)
equatenum(n54, n50)
runkey(virtual-[)
return
label (42)
movecursor(curfile, locA)
returnFalse
>
Un-indent cursor line by one space
<altctl-[: equatenum(n1, n44)
equatenum(n44, 1)
runkey(alt-[)
equatenum(n44, n1)
>
Un-indent this line one step, where step size is set by shftAlt-]
<alt-[: equateloc(curfile, locA, atcursor)
runkey(ctl-[)
if (genum(0, n44)) equatenum(n44, 4) .. default @@
if (gtnum(n50, n44)) sub(n54, n50, n44)
else equatenum(n54, 1)
runkey(virtual-[)
>
Indent this line one step, where step size is set by shftAlt-]
<alt-]: equateloc(curfile, locA, atcursor)
runkey(ctl-[)
if (genum(0, n44)) equatenum(n44, 4) .. default @@
add(n54, n50, n44)
runkey(virtual-[)
>
Indent cursor line by one space
<altctl-]: equatenum(n1, n44)
equatenum(n44, 1)
runkey(alt-])
equatenum(n44, n1)
>
Indent cursor line to column specified in n54, leave cursor at locA
<virtual-[: if (not is(curfile, sline)) movecursor(curfile, sline)
getlocal(curfile, n52, leftmargin)
setlocal(curfile, leftmargin, n54)
.... God dammit, the manual says that nonzero leftmargin causes autoindent
.... to be ignored. But in my version autoindent false causes leftmargin
.... to be ignored! Grrr:
if (not getflag(curfile, autoindent)) {
add(n52, n52, 100000)
flipflag(curfile, autoindent)
}
typechar(eline) .. cause indent to leftmargin (n54)
movecursor(curfile, upline)
clearchar(curfile)
if (genum(n52, 100000)) {
sub(n52, n52, 100000)
flipflag(curfile, autoindent)
}
setlocal(curfile, leftmargin, n52) .. restore old margin
.. SUPER BOGUS BUG WORKAROUND:
if (getflag(curfile, mapchars)) {
flipflag(curfile, mapchars)
typechar(0) .. snaps it back to reality!
flipflag(curfile, mapchars)
} else
typechar(0)
movecursor(curfile, locA)
if (is(curfile, sline)) runkey(ctl-[)
> This is kinda slow, but I don't see any better way -- UEK version is faster
Make C brackets { } with indent (set indent size with SA-])
<shftalt-[: if (movecursor(curfile, schar)) {
if (not is(curfile, whitespace)) {
movecursor(curfile, echar)
insertchar(curfile, " ")
} else movecursor(curfile, echar)
}
insertchar(curfile, "{")
typechar(eline)
if (not is(curfile, eline)) movecursor(curfile, eline)
typechar(eline)
insertchar(curfile, "}")
if (eqloc(curfile, atcursor, efile)) { .. new feech
insertchar(curfile, eline)
movecursor(curfile, schar)
}
movecursor(curfile, upline)
runkey(alt-])
if (not is(curfile, eline)) movecursor(curfile, eline)
> ....could use something to undo this if you hit it by accident
Un-indent the hilite region one step (set step size with SA-])
<alt-l: if (geloc(curfile, shilite, ehilite)) returnfalse
moveCursor(curFile,sHilite)
movecursor(curfile, echar) .. don't do line that ends with shilite
if (not is(curFile,sLine)) moveCursor(curFile,sLine)
while (gtloc(curfile, ehilite, atcursor)) { .. don't do line that
runkey(alt-[) .. starts with ehilite
if (not movecursor(curfile, downline))
equateloc(curfile, atcursor, ehilite) .. cheap escape hatch
}
>
Un-indent the hilite region by one space
<altctl-l: equatenum(n1, n44)
equatenum(n44, 1)
runkey(alt-l)
equatenum(n44, n1)
>
Indent the hilite region one step (set step size with SA-])
<alt-r: if (geloc(curfile, shilite, ehilite)) returnfalse
moveCursor(curFile,sHilite)
movecursor(curfile, echar) .. don't do line that ends with shilite
if (not is(curFile,sLine)) moveCursor(curFile,sLine)
while (gtloc(curfile, ehilite, atcursor)) { .. don't do line that
runkey(alt-]) .. starts with ehilite
if (not is(curFile,sLine)) moveCursor(curFile,sLine)
if (not movecursor(curfile, downline))
equateloc(curfile, atcursor, ehilite) .. cheap escape hatch
}
>
Indent the hilite region by one space
<altctl-r: equatenum(n1, n44)
equatenum(n44, 1)
runkey(alt-r)
equatenum(n44, n1)
>
Ask how many spaces to indent the hilite region
<shftaltctl-r: putmsg(
"Indent hilite region how many spaces? (negative for un-indent)")
equatenum(n1, n44)
equatenum(n44, 0)
if (inputnum(n44))
if (gtnum(n44, 0))
runkey(alt-r)
else if (gtnum(0, n44)) {
sub(n44, 0, n44)
runkey(alt-l)
} else
putmsg("Invalid number")
equatenum(n44, n1)
>
+++++++++++++++++
*** miscellaneous
Umlaut next vowel or insert one of these: © ½ ¼ ¡ ¿ « » ß × ÷ ± ° Ñ ñ
<alt-/: putmsg("c=© 2=½ 4=¼ 1=¡ q=¿ ,=« .=» b=ß x=× v=÷ p=± d=° n=ñ vöwël=ümläüt")
getchar(n54)
putmsg(" ")
freebuf(buf54)
insertrgn(buf54, sfile, .. array for looking up conversions:
" !\"#$%'()*+«-»/0¡½3¼56789:;<=>?@ÄBCDËFGHÏJKLMÑÖPQRSTÜVWXYZ[\\]^_`äß©°ëfghïjklmñö±¿rstü÷w×ÿz{|}~ ", all) .. "
sub(n54, n54, 32)
indextoloc(buf54, atcursor, n54)
copychar(buf54, n53)
typechar(n53)
>
We could use a Spanish version with accents instead of umlauts
Go to start of hilite
<shft-kp1: movecursor(curfile, shilite) >
Go to end of hilite
<shft-kp3: movecursor(curfile, ehilite) >
Go to start of invert
<shftctl-kp1: movecursor(curfile, sinvert) >
Go to end of invert
<shftctl-kp3: movecursor(curfile, einvert) >
Reset color permutation to 2103 if you hit alt-help by mistake.
<lamiga-help: setlocal(curfile, color, 0x93) >
For programmers: Toggle number under cursor between hex/decimal
<ctl-x: movecursor(curfile, eword)
movecursor(curfile, schar)
equatenum(n54, 0)
copychar(curfile, n53)
if (eqnum(n53, "l")) equatenum(n53, "L")
if (eqnum(n53, "L")) {
insertchar(curfile, " ")
movecursor(curfile, schar)
equatenum(n54, 1)
}
if (not is(curfile, sword)) movecursor(curfile, sword)
if (hexDecimal(curFile)) {
movecursor(curfile, eword)
movecursor(curfile, schar) .. compensate
if (is(curfile, "X")) clearchar(curfile) .. for bug
else movecursor(curfile, echar)
} else movecursor(curfile, eword)
if (eqnum(n54, 1)) {
clearchar(curfile)
movecursor(curfile, echar)
}
> it's way newnimproved
Convert whole word under the cursor to all lower case
<ctl-l: movecursor(curfile, eword)
movecursor(curfile, sword)
while (not is(curfile, eword)) {
tolower(curfile)
movecursor(curfile, echar)
}
>
Convert whole word under the cursor to all upper case
<ctl-u: movecursor(curfile, eword)
movecursor(curfile, sword)
while (not is(curfile, eword)) {
toupper(curfile)
movecursor(curfile, echar)
}
>
Convert this/next letter to uppercase, and rest of word to lowercase
<ctl-c: while (not is(curfile, alpha)) movecursor(curfile, echar)
toupper(curfile)
movecursor(curfile, echar)
if (is(curfile, uppercase))
while (not is(curfile, eword)) {
tolower(curfile)
movecursor(curfile, echar)
}
else if (not is(curfile, eword)) movecursor(curfile, eword)
> leaves rest of word alone unless letter after first is uppercase
Transpose characters
<alt-t: copychar(curfile, n53)
movecursor(curfile, schar)
copychar(curfile, n54)
swapchar(curfile, n53)
movecursor(curfile, echar)
swapchar(curfile, n54)
movecursor(curfile, echar)
>
Let's try for transpose words someday?
Record recent inputs in n10..n18
..<prekey: 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)
equatenum(n[n10], macronum)
>
actually I set it to record the last sixteen inputs in my own version -- my
own prekey also has the line equatenum(n32, 0) to make my combined-save-on-
idle-and-rexx-auto-traffic idle key work, and runkey(virtual-=) to make my
word abbrev mode work.
Display recent inputs, except normal-mouseclicks
<alt-q: freebuf(buf52)
insertrgn(buf52, efile, "1 2 3 4 5 6 7 8 9 0 - = \ ?14? kp0 q w e
r t y u i o p [ ] ?28? kp1 kp2 kp3 a s d f g h j k l ; ' ?43? ?44? kp4
kp5 kp6 ?48? z x c v b n m , . / ?59? kpDot kp7 kp8 kp9 space bs tab
kpEnter return esc del menuDown menuUp middleDown kpMinus middleUp upArrow
downArrow rightArrow leftArrow f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 kpLParen
kpRParen kpSlash kpStar kpPlus help buttonDown buttonUp gadget1 gadget2
gadget3 gadget4 closebox ` ?104? ", all)
movecursor(buf52, sfile)
while (movecursor(buf52, echar))
if (is(buf52, space)) swapchar(buf52, eline)
freebuf(buf51)
insertrgn(buf51, efile, "0 normal shft alt shftAlt ctl shftCtl
altCtl shftAltCtl lAmiga rAmiga virtual", all)
freebuf(buf54)
insertrgn(buf54, efile, "===== Your last eight inputs, newest first:
", all)
do (n53, 0, 7) { .. <<< RANGE ^^^
div(n54, n[n10], 104)
movecursor(buf51, sfile)
do (n52, 0, n54) movecursor(buf51, eword)
movecursor(buf51, echar)
insertrgn(buf54, atcursor, buf51, word)
insertchar(buf54, "-")
mod(n54, n[n10], 104)
linetoloc(buf52, atcursor, n54)
insertrgn(buf54, efile, buf52, line)
insertchar(buf54, eline)
if (genum(n10, 18)) equatenum(n10, 11) .. RANGE
else incnum(n10)
}
equatenum(n53, curfile)
editbuf(buf54)
putmsg("press any key")
getkey(n54)
putmsg(" ")
editbuf(buf[n53])
freebuf(buf54)
freebuf(buf52)
freebuf(buf51)
>
Find next usage of an n-variable
<alt-.: getsearch(buf54)
setsearch("n")
while (search(curfile, sinvert, einvert, 1)) {
equateloc(curfile, atcursor, einvert)
if (is(curfile, digit)) goto label (2)
if (is(curfile, "[")) goto label (2)
}
putmsg("Search failed")
label (2)
setsearch(buf54)
> Well, I had a use for it once... would work better with grep I guess
Report size of file in chars and lines, and current position
<ctl-1: loctoindex(curfile, n54, atcursor)
sub(n54, n54, 1)
freebuf(buf54)
insertrgn(buf54, efile, "Char ", all)
toword(buf54, n54)
insertrgn(buf54, efile, " of ", all)
filesize(curfile, n53)
toword(buf54, n53)
insertrgn(buf54, efile, " = ", all)
mul(n54, n54, 100)
div(n54, n54, n53)
toword(buf54, n54)
insertrgn(buf54, efile, "% line ", all)
loctoline(curfile, n54, atcursor)
toword(buf54, n54)
insertrgn(buf54, efile, " of ", all)
loctoline(curfile, n54, efile)
toword(buf54, n54)
putmsg(buf54)
> replaces ctl-1 in config!m
Save this file with an icon, future file saves without
<lamiga-f2: if (not getflag(curfile, icons)) flipflag(curfile, icons)
savefile(curfile)
delay(10) .. not infinitely reliable
flipflag(curfile, icons)
>