Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: What would you say is the most-used way of indenting case labels



Phil Pennock wrote:
> % function foo { case $1 in (a) print alpha; print second; print third;;
> 	(b) print beta;; (*) print omega;;esac }
> 
> % whence -f foo
> foo () {
>         case $1 in
>                 (a) print alpha
>                         print second
>                         print third ;;
>                 (b) print beta ;;
>                 (*) print omega ;;
>         esac
> }

Time for some audience participation.  Do you prefer the following
style?

foo () {
        case $1 in
                (a) print alpha
                print second
                print third
                ;;
                (b) print beta
                ;;
                (*) print omega
                ;;
        esac
}

Vote now.  Lines are open.

Index: Src/text.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/text.c,v
retrieving revision 1.16
diff -u -r1.16 text.c
--- Src/text.c	10 Jan 2006 16:57:06 -0000	1.16
+++ Src/text.c	11 Aug 2006 19:33:59 -0000
@@ -530,14 +530,14 @@
 		    taddstr(ecgetstr(state, EC_NODUP, NULL));
 		    state->pc++;
 		    taddstr(") ");
-		    tindent++;
 		    n = tpush(code, 0);
 		    n->u._case.end = end;
 		    n->pop = (state->pc - 2 + WC_CASE_SKIP(code) >= end);
 		}
 	    } else if (state->pc < s->u._case.end) {
-		tindent--;
-		taddstr(WC_CASE_TYPE(code) == WC_CASE_OR ? " ;;" : ";&");
+		if (tnewlins)
+		    taddnl();
+		taddstr(WC_CASE_TYPE(code) == WC_CASE_OR ? ";;" : ";&");
 		if (tnewlins)
 		    taddnl();
 		else
@@ -547,13 +547,13 @@
 		taddstr(ecgetstr(state, EC_NODUP, NULL));
 		state->pc++;
 		taddstr(") ");
-		tindent++;
 		s->code = code;
 		s->pop = ((state->pc - 2 + WC_CASE_SKIP(code)) >=
 			  s->u._case.end);
 	    } else {
-		tindent--;
-		taddstr(WC_CASE_TYPE(code) == WC_CASE_OR ? " ;;" : ";&");
+		if (tnewlins)
+		    taddnl();
+		taddstr(WC_CASE_TYPE(code) == WC_CASE_OR ? ";;" : ";&");
 		tindent--;
 		if (tnewlins)
 		    taddnl();

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author