[libvirt] [PATCH][RFC] Add a rule for indenting labels

Martin Kletzander mkletzan at redhat.com
Fri Mar 21 14:04:32 UTC 2014


On Fri, Mar 21, 2014 at 02:11:10PM +0100, Ján Tomko wrote:
> Indent labels by one space.
>

Oooh yes, this is something I wanted, but didn't have the guts to do
it...

> Add the rule to HACKING and enforce it by syntax-check.
> ---
> Adding a space helps git's function context detection, but the fallout
> patch is over 800K.
>

... basically because of this *and* because of many people having some
defaults which would then indent incorrectly.  I'm guessing vim has
indentation of labels set to no indent (or whatever is the
configuration there) by default, doesn't it?  But I see you added a
configuration for that, so at least that's OK.

> My reasoning for also indenting labels in nested code is that
> vim's cinoptions don't have a separate option for these labels
> (or I haven't searched hard enough?).
>

So that's why you went with 4n+1?

> Inspired by this thread:
> https://www.redhat.com/archives/libvir-list/2014-March/msg01310.html
>
>  cfg.mk               |  7 +++++++
>  docs/hacking.html.in | 18 +++++++++++++++++-
>  2 files changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/cfg.mk b/cfg.mk
> index 559f719..1512fb2 100644
> --- a/cfg.mk
> +++ b/cfg.mk
> @@ -898,6 +898,13 @@ sc_prohibit_virConnectOpen_in_virsh:
>  	halt='Use vshConnect() in virsh instead of virConnectOpen*'    \
>  	  $(_sc_search_regexp)
>
> +sc_require_space_before_label:
> +	@prohibit='^(( {2})*|( {3})*)([_a-zA-Z0-9]+):$$'               \

Doesn't this regexp allow only number of spaces not divisible by 2 or
3?  That would report proper label in 2nd nesting level (if we have
such labels).

> +	exclude='( {4})*default:$$'                                    \
> +	in_vc_files='\.[ch]$$'                                         \
> +	halt="Labels should be indented by 4*n + 1 spaces"             \
> +	  $(_sc_search_regexp)
> +
>  sc_curly_braces_style:
>  	@files=$$($(VC_LIST_EXCEPT) | grep '\.[ch]$$');                \
>  	$(GREP) -nHP                                                   \
> diff --git a/docs/hacking.html.in b/docs/hacking.html.in
> index 0febee2..b2b158a 100644
> --- a/docs/hacking.html.in
> +++ b/docs/hacking.html.in
> @@ -303,7 +303,7 @@
>    set tabstop=8
>    set shiftwidth=4
>    set expandtab
> -  set cinoptions=(0,:0,l1,t0
> +  set cinoptions=(0,:0,l1,t0,L3

Could you modify the emacs defaults as well?

>    filetype plugin indent on
>    au FileType make setlocal noexpandtab
>    au BufRead,BufNewFile *.am setlocal noexpandtab
> @@ -1139,6 +1139,22 @@
>        retry: If needing to jump upwards (e.g., retry on EINTR)
>  </pre>
>
> +    <p>
> +    Labels should be indented by one space (putting them on the beginning
> +    of the line confuses function context detection in emacs and git):

It confuses only git, emacs just indents it differently by default.

> +    </p>
> +
> +<pre>
> +int foo()
> +{
> +    if (wizz) {
> +     retry:
> +        goto retry;
> +    }
> + cleanup:
> +}
> +</pre>
> +
>
>
>      <h2><a name="committers">Libvirt committer guidelines</a></h2>
> --

All in all, I'm for it, I just don't think others will like it...

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140321/8d095114/attachment-0001.sig>


More information about the libvir-list mailing list