I guess you realise the braces surrounding the statements following the case option are redundant unless you're declaring variables and want to limit their scope ??
Here's a macro that un-indents the case blocks for you. unindent_case_block does one, the _all version does the whole of the current buffer. To use it, save the code to a file and load it using the load module command on the macro menu. It should be fairly obvious what the code is doing so you can tweak it if there are special cases it doesn't handle.
Graeme
#include "slick.sh"
#pragma option(strictsemicolons,on)
#pragma option(strict,on)
#pragma option(autodecl,off)
#pragma option(strictparens,on)
static _str do_unindent_case_block()
{
typeless p, p2;
_deselect();
// search for keywords 'case' or 'default'
if (search('case|default','RIH?CK,,'))
return 'Done';
_save_pos2(p);
int pl = p_line;
int pc = p_col;
// find a colon
if (search(':','IH?C3,,'))
return 'Missing colon. Line ' :+ p_line;
if (p_line != pl)
return 'Misplaced colon. Line ' :+ p_line;
right();
// search for first non whitespace, not in comment, not forward slash
if (search('[ \n\r\t]*\c[^ \n\r\t\/]','IRH?,XC,'))
return 'Syntax error at line ' :+ p_line;
int pc2 = p_col;
// if first non whitespace is not { or not indented then skip
if (get_text() != '{' || p_line == pl || p_col <= pc)
return 'Skip';
// remember the col/line of the opening brace
int plb = p_line;
int pcb = p_col;
_save_pos2(p);
if (find_matching_paren(true))
return 'Error - no matching paren. Line ' :+ p_line;
_deselect();
_save_pos2(p2);
if (p_col != pc2) {
pl = p_line;
_restore_pos2(p);
return 'Mis-aligned brace at line ' :+ pl;
}
// guard against missing brace, search backwards for opening brace
if (search('{','IH-?C1,XC,')) {
_restore_pos2(p);
return 'Lost opening brace!!';
}
if (p_line != plb || p_col != pcb) {
_restore_pos2(p);
return 'Brace matching failed';
}
_restore_pos2(p2);
_select_line();
_restore_pos2(p);
_select_line();
unindent_selection();
_deselect();
_restore_pos2(p2);
_end_line();
return '';
}
_command void unindent_case_block(boolean all = false, boolean from_cursor = false) name_info(','VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL)
{
typeless p;
int k = 0;
if (!all) {
message(do_unindent_case_block());
return;
}
if (!from_cursor)
top();
while (++k < 60000) {
_save_pos2(p);
_str res = do_unindent_case_block();
switch (res) {
case '' :
// un_indenting occurred so repeat in case it was doubly indented
_restore_pos2(p);
continue;
case 'Skip' :
continue;
case 'Done' :
return;
}
_message_box(res);
return;
}
_message_box('Done 60000 ??????????????????????');
}
_command void unindent_case_block_all(boolean from_cursor = false) name_info(','VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL)
{
typeless p;
_save_pos2(p);
unindent_case_block(true, from_cursor);
_restore_pos2(p);
}