all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* C label indentation: emacs and GNU indent disagree
@ 2011-06-06  7:25 Jim Meyering
  0 siblings, 0 replies; only message in thread
From: Jim Meyering @ 2011-06-06  7:25 UTC (permalink / raw)
  To: Emacs development discussions

I've just discovered that GNU indent's default indentation
of C labels differs from the indentation that I get in emacs.
With GNU indent, an unnested label is left justified.  I.e.,
it starts in the first column.  However, emacs puts a space
before it:

$ printf 'f(){l:;}'|indent > k.c; cat k.c
f ()
{
l:;
}

However, if you run "emacs -q k.c", move point to the line with
the label and hit TAB, it inserts a space:

f ()
{
 l:;
}

I did a quick survey of coreutils and see there isn't a clear favorite:

  $ git grep -E '^[a-z_]+:' src/
  src/copy.c:preserve_metadata:
  src/copy.c:close_src_and_dst_desc:
  src/copy.c:close_src_desc:
  src/copy.c:un_backup:
  src/echo.c:just_echo:
  src/find-mount-point.c:done:
  src/head.c:free_lbuffers:
  src/od.c:cleanup:;
  src/split.c:no_filters:
  src/stat.c:print_mount_point:
  src/tail.c:free_lbuffers:
  src/tail.c:free_cbuffers:

  $ git grep -E '^ [a-z_]+:' src/
  src/du.c: argv_iter_done:
  src/kill.c: no_more_options:;
  src/ls.c: done:
  src/paste.c: done:;
  src/sort.c: greater:
  src/sort.c: not_equal:
  src/sort.c: finish:
  src/uniq.c: closefiles:
  src/wc.c: argv_iter_done:

Note that there is a good reason to prefer the indented label.
If I make a change to copy.c just after the un_backup: label,
here's the "diff" output I see:

diff --git a/src/copy.c b/src/copy.c
index 801a474..ff229f0 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -2521,6 +2521,7 @@ un_backup:

   if (dst_backup)
     {
+
       if (rename (dst_backup, dst_name) != 0)
         error (0, errno, _("cannot un-backup %s"), quote (dst_name));
       else

However, if I "correct" the indentation of that label so that it is not
left justified, the diff then refers to the containing function name,
copy_internal, rather than to the label name:

diff --git a/src/copy.c b/src/copy.c
index b685a6b..b7fd433 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -2521,6 +2521,7 @@ copy_internal (char const *src_name, char const *dst_name,

   if (dst_backup)
     {
+
       if (rename (dst_backup, dst_name) != 0)
         error (0, errno, _("cannot un-backup %s"), quote (dst_name));
       else

I prefer emacs' indentation style and will switch to it.  FYI, for
automated formatting, I am inclined to use uncrustify, which currently
acts just like GNU indent in this respect, but will be easy to fix.



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-06-06  7:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-06  7:25 C label indentation: emacs and GNU indent disagree Jim Meyering

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.