From 86acbbbcddeb999ebac90f06d2163bb726aaeead Mon Sep 17 00:00:00 2001 From: Luke Ceddia Date: Mon, 14 Dec 2015 11:19:26 +1100 Subject: [PATCH] Indent code in SUBs and FUNCTIONs by one level, with the option to turn on/off. Adds option IDE_IndentSUBs to the config file. Credit to Fellippe Heitor for doing the research and writing on the bulk of this commit. --- source/global/IDEsettings.bas | 14 ++++++++++++++ source/ide/ide_global.bas | 2 +- source/ide/ide_methods.bas | 19 ++++++++++++++++--- source/qb64.bas | 12 +++++++++++- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/source/global/IDEsettings.bas b/source/global/IDEsettings.bas index d30b9073b..e9aa117bc 100644 --- a/source/global/IDEsettings.bas +++ b/source/global/IDEsettings.bas @@ -179,6 +179,20 @@ IF LoadedIDESettings = 0 THEN end if END IF + result = ReadConfigSetting("IDE_IndentSUBs", value$) + ideindentsubs = VAL(value$) + IF UCASE$(value$) = "TRUE" OR ideindentsubs <> 0 THEN + ideindentsubs = 1 + elseif result = 0 then + WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_IndentSUBs", "FALSE" + ideindentsubs = 0 + ELSEIF UCASE$(value$) <> "FALSE" AND value$ <> "0" THEN + WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_IndentSUBs", "TRUE" + ideindentsubs = 1 + else + ideindentsubs = 0 + end if + result = ReadConfigSetting("IDE_IndentSize", value$) ideautoindentsize = VAL(value$) if ideautoindentsize < 1 OR ideautoindentsize > 64 then diff --git a/source/ide/ide_global.bas b/source/ide/ide_global.bas index c7139ce5e..6e1ac3ab2 100644 --- a/source/ide/ide_global.bas +++ b/source/ide/ide_global.bas @@ -189,7 +189,7 @@ DIM SHARED menus AS INTEGER DIM SHARED menubar$ DIM SHARED ideundocombo, ideundocombochr, idenoundo, idemergeundo DIM SHARED idealthighlight, ideentermenu -DIM SHARED ideautolayout, ideautoindent, ideautoindentsize, idebackupsize +DIM SHARED ideautolayout, ideautoindent, ideautoindentsize, ideindentsubs, idebackupsize DIM SHARED idewx, idewy, idecustomfont, idecustomfontfile$, idecustomfontheight, idecustomfonthandle DIM SHARED iderunmode 'IDE MODULE SECTION END: shared data & definitions diff --git a/source/ide/ide_methods.bas b/source/ide/ide_methods.bas index 46a8f8aa9..18bb6a64f 100644 --- a/source/ide/ide_methods.bas +++ b/source/ide/ide_methods.bas @@ -7490,6 +7490,12 @@ o(i).nam = idenewtxt("#Spacing") o(i).txt = idenewtxt(a2$) o(i).v1 = LEN(a2$) +i = i + 1 +o(i).typ = 4 +o(i).y = 6 +o(i).nam = idenewtxt("Indent #SUBs and FUNCTIONs") +o(i).sel = ideindentsubs + i = i + 1 o(i).typ = 3 o(i).y = 7 @@ -7584,8 +7590,8 @@ DO 'main loop END IF idetxt(o(3).txt) = a$ - IF K$ = CHR$(27) OR (focus = 5 AND info <> 0) THEN EXIT FUNCTION - IF K$ = CHR$(13) OR (focus = 4 AND info <> 0) THEN + IF K$ = CHR$(27) OR (focus = 6 AND info <> 0) THEN EXIT FUNCTION + IF K$ = CHR$(13) OR (focus = 5 AND info <> 0) THEN 'save changes v% = o(1).sel: IF v% <> 0 THEN v% = 1 'ideautolayout @@ -7602,6 +7608,9 @@ DO 'main loop IF ideautoindent <> 0 THEN idelayoutbox = 1 END IF + v% = o(4).sel: IF v% <> 0 THEN v% = 1 'ideindentsubs + IF ideindentsubs <> v% THEN ideindentsubs = v%: idelayoutbox = 1 + if ideautolayout then WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoFormat", "TRUE" else @@ -7613,7 +7622,11 @@ else WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_AutoIndent", "FALSE" end if WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_IndentSize", str$(ideautoindentsize) - +if ideindentsubs then + WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_IndentSUBs", "TRUE" +else + WriteConfigSetting "'[IDE DISPLAY SETTINGS]", "IDE_IndentSUBs", "FALSE" +end if EXIT FUNCTION END IF diff --git a/source/qb64.bas b/source/qb64.bas index 365066857..49a34b784 100644 --- a/source/qb64.bas +++ b/source/qb64.bas @@ -4384,6 +4384,11 @@ DO GOTO errmes END IF + if ideindentsubs then + controllevel = controllevel + 1 + controltype(controllevel) = 32 + end if + subfunc = RTRIM$(id.callname) 'SUB_..." subfuncn = subfuncn + 1 subfuncid = targetid @@ -4851,7 +4856,7 @@ DO IF LEN(subfunc) = 0 THEN a$ = "END " + secondelement$ + " without " + secondelement$: GOTO errmes 'check for open controls (copy #3) - IF controllevel <> 0 AND controltype(controllevel) <> 6 THEN 'It's OK for subs to be inside $IF blocks + IF controllevel <> 0 AND controltype(controllevel) <> 6 AND controltype(controllevel) <> 32 THEN 'It's OK for subs to be inside $IF blocks x = controltype(controllevel) IF x = 1 THEN a$ = "IF without END IF" IF x = 2 THEN a$ = "FOR without NEXT" @@ -4862,6 +4867,11 @@ DO GOTO errmes END IF + IF controltype(controllevel) = 32 and ideindentsubs THEN + controltype(controllevel) = 0 + controllevel = controllevel - 1 + END IF + l$ = firstelement$ + sp + secondelement$ layoutdone = 1: IF LEN(layout$) THEN layout$ = layout$ + sp + l$ ELSE layout$ = l$