compile if not defined('SMALL') -- being compiled as a stand-alone module
defmain
uparg = upcase(arg(1))
if uparg=0 | uparg='OFF' then
'expand'
elseif uparg=1 | uparg='ON' | uparg='' then
'fold'
else
gold2=' '
do i=1 to length(GOLD)
gold2 = gold2 substr(GOLD, i, 1)
enddo
call winmessagebox('Fold', 'Place cursor on one of:'\n gold2\n'then enter FOLD to fold text. Place cursor inside folded text and enter FOLD OFF to expand it.', 16384+48) -- MOVEABLE + MB_INFORMATION
endif
compile endif
const
COLOR_CLASS = 1
BOOKMARK_CLASS = 13
STYLE_CLASS = 14
FONT_CLASS = 16
FIND_NEXT_ATTR_SUBOP = 1
FIND_PREV_ATTR_SUBOP = 2
FIND_MATCH_ATTR_SUBOP = 3
DELETE_ATTR_SUBOP = 16
defc fold =
call psave_pos(savepos)
n=1
c=substr(textline(.line),.col,1)
GETSEARCH search_command -- Save user's search command.
k=pos(c,GOLD) -- '(){}[]<>'
if not k then sayerror 'Not a balanceable character.'; return; endif
fstline=.line; fstcol=.col
search = substr(GOLD,(k+1)%2*2-1,2)
if k//2 then direction='+F'; else direction='-R'; endif
if search='[]' then search='\[\]'; endif
compile if EVERSION >= '5.60'
if search='()' then search='\(\)'; endif
'xcom L /['search']/ex'direction -- Use extended grep; much faster.
compile else
'xcom L /['search']/eg'direction
compile endif
loop
repeatfind
if rc then leave; endif
if substr(textline(.line), .col, 1) = c then n=n+1; else n=n-1; endif
if n=0 then leave; endif
endloop
if rc=sayerror('String not found') then
sayerror 'Unbalanced token.'
else
sayerror 1
endif
SETSEARCH search_command -- Restores user's command so Ctrl-F works.
lstline = .line; lstcol = .col
if not rc then
getfileid fid
fontid=registerfont('Courier', 1, 0)
call attribute_on(4) -- Mixed fonts flag
if not (k//2) then -- adjust the order
parse value fstline lstline fstcol lstcol with lstline fstline lstcol fstcol
endif
fstcol = fstcol + 1 -- Want to display the brace, paren, etc.