compile if not defined('SMALL') -- being compiled as a stand-alone module
defmain
uparg = upcase(arg(1))
if uparg=0 | uparg='OFF' then
'unfold'
elseif uparg=1 | uparg='ON' | uparg='' then
'fold'
else
gold2=' '
do i=1 to length(GOLD)
gold2 = gold2 substr(GOLD, i, 1)
enddo
compile if EVERSION >= '5.60'
call winmessagebox('Fold', 'Place cursor on one of:'\n gold2\n'or a #if, #elif, #else, #endif, or COMPILE (followed by IF, ELSEIF, ELSE or ENDIF), then enter FOLD to fold text. Place cursor inside folded text and enter FOLD OFF to expand it.',
16384+48) -- MOVEABLE + MB_INFORMATION
compile else
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
compile endif
endif
compile if EVERSION >= 6
EA_comment "CUSTEPM's FOLD command, for code folding and unfolding."
compile 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)
compile if EVERSION >= '5.50'
case = 'e'
id = ''
force_search = 0
compile endif
n=1
c=substr(textline(.line),.col,1)
GETSEARCH search_command -- Save user's search command.
k=pos(c,GOLD) -- '(){}[]<>'
if k then
search = substr(GOLD,(k+1)%2*2-1,2)
compile if EVERSION >= '5.60'
incr = 0
compile endif
else
compile if EVERSION >= '5.60'
if find_token(startcol, endcol) then
getline line
id = substr(line, startcol, (endcol-startcol)+1)
endif
if wordpos(id, C_TOKS) then
k = (id<>'#endif') -- Search forwards if not #endif
if k then -- move to beginning
.col = startcol
c = 'i'
search = '#(if((n?def)|):w|endif|else|elif)'
else -- move to end, so first Locate will hit this instance.
.col = endcol
c = 'e'
search = '#(if((n?def)|):w|endif)'
endif
incr = 1
force_search = substr(id, 3, 1)='l' -- #else or #elif
elseif lowcase(id)='compile' &
wordpos(lowcase(word(substr(line, endcol+1), 1)), 'if endif else elseif') then
case = 'c' -- Case insensitive
k = (lowcase(word(substr(line, endcol+1), 1))<>'endif')
if k then -- move to beginning
.col = startcol
c = 'i'
search = 'compile:w((end|else|)if|else)'
else -- move to end, so first Locate will hit this instance.