From: Jim Meyering <jim@meyering.net>
To: Emacs development discussions <emacs-devel@gnu.org>
Subject: C label indentation: emacs and GNU indent disagree
Date: Mon, 06 Jun 2011 09:25:25 +0200 [thread overview]
Message-ID: <871uz7e80q.fsf@rho.meyering.net> (raw)
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.
reply other threads:[~2011-06-06 7:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871uz7e80q.fsf@rho.meyering.net \
--to=jim@meyering.net \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.