From: Mauricio Fernandez Date: 2007-01-04T02:06:29+09:00 Subject: Re: Suggestion: Post indentation style guideline to "Rules for Core Developers" On Mon, Jan 01, 2007 at 11:58:18PM +0900, Rob Muhlestein wrote: > On Sun, 2006-12-31 at 15:02 +0900, Eric Hodel wrote: > > On Dec 30, 2006, at 20:02, Rob Muhlestein wrote: > > > What *is* the preferred indentation style for ruby core C code? > > > > It appears to by four spaces with hard tabs. All the files I've > > encountered have this structure. > > > Really, humm, in which files specifically are you seeing the mostly hard > tabs? I'm seeing mostly soft tabs. In fact I see very few hard tabs in > io.c, error.c, marshal.c, regcomp.c (which also has 2 space instead of > 4) with vi ':set list' turned on (and thanks richard for the vi rc setup > reminders, been using them for years). Here's io.c for example: > > 1883 static VALUE$ > 1884 rb_io_readline(int argc, VALUE *argv, VALUE io)$ > 1885 {$ > 1886 VALUE line = rb_io_gets_m(argc, argv, io);$ > 1887 $ > 1888 if (NIL_P(line)) {$ > 1889 ^Irb_eof_error();$ > 1890 }$ > 1891 return line;$ > 1892 }$ > > Notice the ^I indicating a tab on 1889 where everything > else is using spaces. IIRC a mixture of hard tabs (considered as 8-space ones) and spaces is used, with 4-space indentation for most files (regcomp.c belongs to Oniguruma which seems to use 2-space). For a given indentation level, as many tabs as possible are used, and up to 7 spaces are added to reach the desired indentation. In the above snippet, only line 1889 is indented >= 8 characters, and it's thus the only one where a hard tab was used. This explains it better: $ ruby -e 'ARGF.each_with_index{|x,i| puts "%06d %s" % [i, x.gsub(/\t/,"###TAB##")]}' eval.c ... 001988 void 001989 rb_frozen_class_p(klass) 001990 VALUE klass; 001991 { 001992 char *desc = "something(?!)"; 001993 001994 if (OBJ_FROZEN(klass)) { 001995 ###TAB##if (FL_TEST(klass, FL_SINGLETON)) 001996 ###TAB## desc = "object"; 001997 ###TAB##else { 001998 ###TAB## switch (TYPE(klass)) { 001999 ###TAB## case T_MODULE: 002000 ###TAB## case T_ICLASS: 002001 ###TAB#####TAB##desc = "module"; break; 002002 ###TAB## case T_CLASS: 002003 ###TAB#####TAB##desc = "class"; break; 002004 ###TAB## } 002005 ###TAB##} 002006 ###TAB##rb_error_frozen(desc); 002007 } 002008 } -- Mauricio Fernandez - http://eigenclass.org - singular Ruby